Using assembly redirection in UWP C#

岁酱吖の 提交于 2019-12-24 20:04:35

问题


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'.'

回答1:


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



来源:https://stackoverflow.com/questions/50675788/using-assembly-redirection-in-uwp-c-sharp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!