Visual Studio 2017 - Could not load file or assembly 'System.Runtime, Version=4.1.0.0' or one of its dependencies

前端 未结 25 2588
轻奢々
轻奢々 2020-11-28 22:52

I am using Visual Studio 2017 and am trying to create a .Net Standard 1.5 library and use it in a .Net 4.6.2 nUnit test project.

I am getting the following error...

25条回答
  •  清酒与你
    2020-11-28 23:40

    We have found that AutoGenerateBindingRedirects might be causing this issue.

    Observed: the same project targeting net45 and netstandard1.5 was successfully built on one machine and failed to build on the other. Machines had different versions of the framework installed (4.6.1 - success and 4.7.1 - failure). After upgrading framework on the first machine to 4.7.1 the build also failed.

    Error Message:
     System.IO.FileNotFoundException : Could not load file or assembly 'System.Runtime, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
      ----> System.IO.FileNotFoundException : Could not load file or assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
    

    Auto binding redirects is a feature of .net 4.5.1. Whenever nuget detects that the project is transitively referencing different versions of the same assembly it will automatically generate the config file in the output directory redirecting all the versions to the highest required version.

    In our case it was rebinding all versions of System.Runtime to Version=4.1.0.0. .net 4.7.1 ships with a 4.3.0.0 version of runtime. So redirect binding was mapping to a version that was not available in a contemporary version of framework.

    The problem was fixed with disabling auto binding redirects for 4.5 target and leaving it for .net core only.

    
      false
    
    

提交回复
热议问题