“Could not load file or assembly 'System.Core, Version=2.0.5.0,…” exception when loading Portable Class Library dynamically

会有一股神秘感。 提交于 2019-12-01 02:55:57
Gabriel Horvath

You can return the System.Core assembly of your platform (e.g. version 4.0.0.0 for .NET Framework 4.0) from the AssemblyResolve event, when asked for the 2.0.5.0 version.

I am loading all my referenced assemblies stored as resources via Load(byte[]), which also fails to resolve the 2.0.5.0 assembly, and I retrieve both System and System.Core from AppDomain.CurrentDomain.GetAssemblies().

I think you are getting these issues because:

You're getting an exception because you haven't got the latest .NET updates.

http://www.paraesthesia.com/archive/2013/01/21/using-portable-class-libraries-update-net-framework.aspx

Take note of the WSUS part - you may think you have the latest updates, but you don't cause your WSUS server is out of date.

This patch may help, but you're better just to get all the .net updates:

http://support.microsoft.com/kb/2468871

(from a comment above)

Try LoadFrom(...) rather than LoadFile(...) / Load(byte[]) and see if that fixes your issue? :)

I had the same problem and ended up with the following solution: invoke the following code before dynamically loading the PCL assembly.

Assembly.Load("System, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e, Retargetable=Yes");
Assembly.Load("System.Core, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e, Retargetable=Yes");

If any other dependency is missing when you load your PCL assembly, you just need to add a line to code above. For some strange and ununderstandable reason, it works.

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