26

Been searching for ages, can't find anything helpful. Here is the exception I'm getting:

Could not load file or assembly 'System, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e, Retargetable=Yes' or one of its dependencies. The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047) 

Exception Details: System.IO.FileLoadException: Could not load file or assembly 'System, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e, Retargetable=Yes' or one of its dependencies. The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047)

Stack Trace: 

[FileLoadException: Could not load file or assembly 'System, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e, Retargetable=Yes' or one of its dependencies. The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047)]
StructureMap.Graph.PluginGraph..ctor() in c:\BuildAgent\work\996e173a8ceccdca\src\StructureMap\Graph\PluginGraph.cs:41
StructureMap.PluginGraphBuilder..ctor() in c:\BuildAgent\work\996e173a8ceccdca\src\StructureMap\PluginGraphBuilder.cs:22
StructureMap.InitializationExpression..ctor() in c:\BuildAgent\work\996e173a8ceccdca\src\StructureMap\InitializationExpression.cs:22
StructureMap.ObjectFactory.Initialize(Action`1 action) in c:\BuildAgent\work\996e173a8ceccdca\src\StructureMap\ObjectFactory.cs:47
...

This applications works fine on the test server but is throwing this exception on the production server. As you can see, the StructureMap code is what is causing the exception.

I had to convert this app to .NET 4 from 4.5 because 4.5 wasn't installed on the production server. After the conversion, the app still works fine on my local machine and the test server.

I have already set the Copy Local to True for the System assembly, but since the referenced version is 4.0.0.0 and not 2.0.5.0, I this made no difference.

Let me know if any more info is needed. Any help you may be able to provide is appreciated.

2
  • 1
    Have you checked the web.config file if there are assembly redirects pointing to the wrong version?
    – 3dd
    May 28, 2014 at 5:49
  • Yes, there are no redirects. I actually tried to add a redirect from 2.0.5.0 to 4.0.0.0 but that seemed to have no effect.
    – tarnold86
    May 28, 2014 at 5:56

6 Answers 6

43

Make sure your .NET framework is patched. Microsoft released patches to .NET to allow Portable Class Libraries to properly find the appropriate runtime (KB2468871). If you are seeing the above exception (or something like it), it means you're missing the latest .NET framework patches.

4
  • 1
    I think this is exactly the issue. Unfortunately this is a production server and I do not have permission to install updates. I ended up just refactoring the application to not use StructureMap.
    – tarnold86
    Jul 3, 2014 at 1:46
  • Nice. That linked KB article solved an issue I had where a 4.0 framework assembly which references a PCL assembly failed to load.
    – slugster
    Jul 29, 2014 at 0:05
  • Thank you very much. This fixed issues that we were having after someone accidentally uninstalled the 4.0 framework and even after our team reinstalled it we were still getting errors. The weird thing is that after reinstalling 4.0, we ran Windows Update and it said no updates were available. It took manually downloading and installing this one to fix it.
    – GR7
    Nov 26, 2014 at 19:17
  • I am experiencing this problems with some customer PCs running Windows 7 SP1 with .net 4.0 installed (did not check if they are patched). As my click once deployment prerequisites requires .net 4.0 with KB2468871 I assume they are. In call cases I fixed installing .net 4.5. What else could be causing this? Apr 10, 2017 at 21:39
1

Edit the web.config file to remove the reference, which is not required for normal operation:

1 - Open the web.config file in the root of your site

2 - Find the following line and comment it out():xxxxx-is your assembly name.

<add assembly="xxxxx", Version=2.0.5.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>

3 - Save and close the web.config file and try again

2
  • That line is not in the web.config, there is only 1 assembly: <assemblies> <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /> </assemblies>
    – tarnold86
    May 28, 2014 at 6:06
  • Are you adding any class library projects to you app? if yes ,then check it's reference also.
    – Jay
    May 28, 2014 at 6:25
1

I found that it was the "await" and "async" that where giving me trouble.

I had Windows XP SP3 with only .NET 4.0, but had to update it to .NET 4.0.3 using KB2600211 - this wasn't updated automatically through Windows Update when .NET 4.0.3 came out because the computer is off-grid.

This is the link to the update:

https://www.microsoft.com/en-us/download/details.aspx?id=29053

1
  • You are awesome, saved me hours !! Thanks Jun 13, 2018 at 10:48
0

I just want to share another solution from here that solved the problem on my development machine: installing Silverlight 5 SDK (only 11.2MB at the time of writing this post) was enough to make everything working.

0

Install Microsoft® Silverlight® 5 SDK from the following link. It resolves and works fine for me.

SDK download

1
  • Not sure taking a dependency on SilverLight when he probably doesn't need it is a great solution. Jun 19, 2017 at 15:46
0

Starting from a machine configuration that only had VS2017 and Silverlight 5 SDK on it, I installed VS2015 on top of that. This is when I started getting the System.Core and System.Windows problems.

When I uninstalled VS2015 and re-installed Silverlight 5 SDK, these problems went away.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.