简体   繁体   中英

Using assembly redirection in UWP C#

Hi!

I'm getting a typeload exception, the assembly being loaded is targeting runtime version v2.0.50727, other assemblies targets v4.0.30319.
I've been reading about Assembly Redirection and I think it could solve this problem but I'm unsure how this would be applied in a UWP app as there is no app.config.
Any advice would be helpful!

System.TypeLoadException: 'Could not load type 'System.Net.Sockets.Socket' from assembly 'System, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e, Retargetable=Yes'.'

In UWP platform, it would be better to create a Universal Windows Class Library then add it as a reference into the UWP project. You can try to create a Universal Windows Class Library and add your code into it as the following image,

在此处输入图片说明

From Windows 10 Fall Creators Update(16299), UWP supports .Net Standard 2.0, you can also create a .NET Standard 2.0 Class Library in VS2017.

Last but not least, I think you should learn more about the relationship among .Net Framework, .Net standard and UWP, you can look into the following blogs to get a better understanding:

https://blogs.msdn.microsoft.com/dotnet/2016/09/26/introducing-net-standard/

https://msdn.microsoft.com/en-us/magazine/mt814993.aspx

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM