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

前端 未结 3 1613
北海茫月
北海茫月 2021-01-04 08:00

First of all I need to emphasize that this is slightly different question than the one in this thread. Additionally, installing KB2468871 doesn\'t help.

I tried to s

相关标签:
3条回答
  • 2021-01-04 08:29

    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.

    0 讨论(0)
  • 2021-01-04 08:38

    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().

    0 讨论(0)
  • 2021-01-04 08:49

    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? :)

    0 讨论(0)
提交回复
热议问题