.net Visual Studio 2017-无法加载文件或程序集';System.Runtime,版本=4.1.0.0';或者它的一个依赖项

.net Visual Studio 2017-无法加载文件或程序集';System.Runtime,版本=4.1.0.0';或者它的一个依赖项,.net,visual-studio-2017,.net-standard-1.5,.net,Visual Studio 2017,.net Standard 1.5,我正在使用Visual Studio 2017,并尝试创建一个.Net标准1.5库,并在.Net 4.6.2 nUnit测试项目中使用它 我得到以下错误 无法加载文件或程序集的System.Runtime,版本=4.1.0.0, 区域性=中性,PublicKeyToken=b03f5f7f11d50a3a'或其 依赖关系。系统找不到指定的文件 我尝试了以下方法: <PropertyGroup> <AzureFunctionsVersion>v3</AzureFu

我正在使用Visual Studio 2017,并尝试创建一个.Net标准1.5库,并在.Net 4.6.2 nUnit测试项目中使用它

我得到以下错误

无法加载文件或程序集的System.Runtime,版本=4.1.0.0, 区域性=中性,PublicKeyToken=b03f5f7f11d50a3a'或其 依赖关系。系统找不到指定的文件

我尝试了以下方法:

<PropertyGroup>
  <AzureFunctionsVersion>v3</AzureFunctionsVersion>
</PropertyGroup>
  • 将Std库作为项目参考。错误:给出了以前的错误
  • 为我的Std库创建一个NuGet pkg并引用它。错误:类型为System.String,应为System.String。这是因为System.Runtime最终被项目引用,并且它具有所有标准类型的定义
  • 引用NuGet pkg NetStandard.Library。错误:给我与#相同的错误(“类型为System.String,应为System.String”)。注意:在此之前,我清除了项目中的所有NuGet软件包,然后只添加了nUnit和NetStandard.Library软件包(其中安装了45个其他软件包)

  • 这是虫子吗?附近有工作吗?非常感谢您的帮助。

    当您从.NET 4.x项目引用.NET标准项目时,会出现此问题:没有.NET标准项目的nuget包引用作为依赖项引入

    要解决此问题,您需要确保.NET 4.x csproj文件指向当前构建工具(至少14个):

    。。。
    
    下面的内容应该不再需要了,它是在VS 15.3左右固定的:

    Could not load file or assembly 'System.Runtime, Version=4.1.0.0' or one of its dependencies
    
    在VS2017中,特别是在NuGet 4.0中,出现了一个问题

    要解决此错误,您需要打开.NET 4.x项目的.csproj文件并添加以下代码段:

    <ItemGroup>
      <PackageReference Include="Legacy2CPSWorkaround" Version="1.0.0">
        <PrivateAssets>All</PrivateAssets>
      </PackageReference>
    </ItemGroup>
    
    
    全部的
    

    NuGet 4.x附带了“package reference”——不再提供packages.config——但在VS2017发布时,旧的4.x管道并没有完全更新。上面的代码片段似乎“唤醒”了构建系统,使其正确地包含依赖项中的包引用。

    我在一个针对dotnet framework 4.6.2的NUnit 2.6.4项目中遇到了这个问题。我在尝试使用时遇到了
    System.Runtime FileNotFound
    错误


    我通过安装到单元测试项目中修复了错误。

    我通过引用NUnit项目中的和以下app.config文件解决了该错误

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
    <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
            <dependentAssembly>
                <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
                <bindingRedirect oldVersion="0.0.0.0-4.1.1.0" newVersion="4.1.1.0" />
            </dependentAssembly>
            <dependentAssembly>
                <assemblyIdentity name="System.Reflection" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
                <bindingRedirect oldVersion="0.0.0.0-4.1.1.0" newVersion="4.1.1.0" />
            </dependentAssembly>
            <dependentAssembly>
                <assemblyIdentity name="System.Runtime.InteropServices" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
                <bindingRedirect oldVersion="0.0.0.0-4.1.0.0" newVersion="4.1.1.0" />
            </dependentAssembly>
        </assemblyBinding>
    </runtime>
    

    我的.NET4.6.1网站多次出现这种情况。每次我添加对一个单独的.NET核心项目的引用时,都会产生这个问题。在构建时,VisualStudio正确地提醒我此类跨框架引用无效,我很快删除了项目引用。此后,该项目建设良好,但访问网站时出现System.Runtime错误,拒绝退出


    每次修复都是蹩脚但有效的:我删除了项目目录,并从源代码管理中重新下载了它。虽然前后没有什么区别,,我可以毫无怨言地构建项目并访问页面。

    我在VS 2017 15.45中遇到了类似的问题-我检查时发现,即使项目编译并运行,当我尝试访问TPL数据流对象时,它也出现了system.IO.FileNotFoundException(system.Runtime)异常


    当我检查解决方案中的项目时,其中一个(顶部)缺少底层项目使用的System.Runtime包。一旦我从Nuget安装了它,它就可以正常工作。

    我也遇到了同样的问题,我发现没有可行的建议解决方案。 我对此问题的解决方案是: 检查App.config和packages.config以查看版本是否匹配

    最初我的app.config包含:

    <dependentAssembly>
      <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
      <bindingRedirect oldVersion="0.0.0.0-4.1.1.0" newVersion="4.1.1.0" />
    </dependentAssembly>
    
    <package id="System.Runtime" version="4.3.0" targetFramework="net461" requireReinstallation="true" />
    
    
    
    但是packages.config包含:

    <dependentAssembly>
      <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
      <bindingRedirect oldVersion="0.0.0.0-4.1.1.0" newVersion="4.1.1.0" />
    </dependentAssembly>
    
    <package id="System.Runtime" version="4.3.0" targetFramework="net461" requireReinstallation="true" />
    
    
    
    我修改了app.config条目以匹配新版本的packages.config:

    <dependentAssembly>
      <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
      <bindingRedirect oldVersion="0.0.0.0-4.1.1.0" newVersion="4.3.0" />
    </dependentAssembly>
    
    
    

    更改后,问题得到解决。

    我们发现,
    自动生成BindingRedirects
    可能导致此问题

    观察到:针对
    net45
    netstandard1.5
    的相同项目在一台机器上成功构建,但在另一台机器上构建失败。机器安装了不同版本的框架(4.6.1-成功和4.7.1-失败)。在将第一台机器上的框架升级到4.7.1之后,构建也失败了

    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.
    
    自动绑定重定向
    .net 4.5.1
    的一项功能。每当nuget检测到项目正在传递引用同一程序集的不同版本时,它将自动在输出目录中生成配置文件,将所有版本重定向到所需的最高版本

    在我们的例子中,它将所有版本的
    System.Runtime
    重新绑定到
    Version=4.1.0.0
    .net 4.7.1
    附带运行时的
    4.3.0.0
    版本。所以重定向绑定映射到的版本在当代版本的框架中是不可用的

    该问题已通过禁用4.5目标的自动绑定重定向并将其仅保留给.net core解决

    <PropertyGroup Condition="'$(TargetFramework)' == 'net45'">
      <AutoGenerateBindingRedirects>false</AutoGenerateBindingRedirects>
    </PropertyGroup>
    
    
    假的
    
    我在这里尝试了所有的解决方案,但都没有成功。最终,我通过打开新的csproj文件并手动添加以下部分来解决此问题:

    <Reference Include="System.Runtime, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
    <HintPath>..\packages\System.Runtime.4.3.0\lib\net462\System.Runtime.dll</HintPath>
    </Reference>
    
    
    ..\packages\System.Runtime.4.3.0\lib\net462\System.Runtime.dll
    
    相信我,我不是在开玩笑。
    从app.config中删除所有System.Runtime依赖项,它将开始工作。

    我通过使用删除我的
    app.config
    修复了它

    <assemblyIdentity name="System.Runtime" ....> 
    
    
    
    条目


    app.config
    是在重构过程中自动添加的(但不是必需的)

    我使用的是ASP.Net CORE 2.1,当我从
    <package id="System.Runtime" version="4.3.0" targetFramework="net47" />
    
    <dependentAssembly>
        <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="4.1.1.1" />
    </dependentAssembly>
    
    <dependentAssembly>
        <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
        <bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="4.0.0.0"/>
    </dependentAssembly>
    
    <dependentAssembly>
        <assemblyIdentity name="System.Runtime" publicKeyToken="B03F5F7F11D50A3A" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.1.2.0" newVersion="4.3.0" />
    </dependentAssembly>
    
    <package id="System.Runtime" version="4.3.0" targetFramework="net461" />
    
    Could not load file or assembly 'System.Runtime, Version=4.1.0.0' or one of its dependencies
    
    <PropertyGroup>
      <AzureFunctionsVersion>v3</AzureFunctionsVersion>
    </PropertyGroup>