简体   繁体   English

在库中使用.Net Standard 1.4并在应用程序中使用.Net Framework 4.6.1时,无法加载文件System.IO.FileSystem,版本= 4.0.1.0

[英]When using .Net Standard 1.4 in a library and .Net framework 4.6.1 in and application, unable to load file System.IO.FileSystem, Version=4.0.1.0

I have a solution that contains a library and 2 applications. 我有一个包含一个库和2个应用程序的解决方案。 The applications represent the same program, with one built to target the Windows App Store through UAP10 and the other built to target a Microsoft Windows PC using .Net Framework 4.6.1. 这些应用程序代表相同的程序,其中一个程序通过UAP10定位于Windows App Store,另一个程序则针对使用.Net Framework 4.6.1的Microsoft Windows PC。 I'm using Visual Studio 2017. 我正在使用Visual Studio 2017。

  • I set the library project target .Net standard 1.4. 我将库项目目标设置为.Net标准1.4。
  • I set the UWP application to target Windows 10 Aniversary Edition (10.0; Build 14393), Min version Windows 10 (10.0; Build 10586). 我将UWP应用程序设置为以Windows 10 Aniversary Edition(10.0; Build 14393),最小版本Windows 10(10.0; Build 10586)为目标。
  • I set the generic Windows application to target .Net Framework 4.6.1. 我将通用Windows应用程序设置为目标.Net Framework 4.6.1。

The UWP version compiles and runs fine. UWP版本可以编译并正常运行。

Initially, the .Net Framework 4.6.1 compiles and runs. 最初,.Net Framework 4.6.1编译并运行。 However, when I make a call to File.Open from System.IO, I get the following error message: 但是,当我从System.IO调用File.Open时,出现以下错误消息:

System.IO.FileNotFoundException: 'Could not load file or assembly 'System.IO.FileSystem, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. System.IO.FileNotFoundException:'无法加载文件或程序集'System.IO.FileSystem,版本= 4.0.1.0,区域性=中性,PublicKeyToken = b03f5f7f11d50a3a'或其依赖项之一。 The system cannot find the file specified.' 该系统找不到指定的文件。'

The code block with File.Run is within the library code (.Net Standard 1.4). File.Run的代码块在库代码(.Net Standard 1.4)中。 I'm not sure what is causing the problem. 我不确定是什么引起了问题。 I thought that I could use .Net Standard 1.4 libraries within an application that references .Net Framework 4.6.1. 我以为可以在引用.Net Framework 4.6.1的应用程序中使用.Net Standard 1.4库。


As a workaround, I tried installing the Nuget package for System.IO in the .Net Framework application. 解决方法是,我尝试在.Net Framework应用程序中为System.IO安装Nuget程序包。 System.IO Version 4.0.1.0 is not even an option. System.IO版本4.0.1.0甚至都不是一个选项。 There is a version 4.0.10, but it doesn't work when this Nuget package is installed. 有一个版本4.0.10,但在安装此Nuget软件包时不起作用。

So, how do I properly reference System.IO operations within a .Net Framework 4.6.1 application that references the System.IO code within a .Net Standard 1.4 library? 因此,如何在引用.Net Standard 1.4库中的System.IO代码的.Net Framework 4.6.1应用程序中正确引用System.IO操作?

This usually happens with "classic" csproj projects when referenced projects require overwritten override system defined types but no binding redirects are present that set this up correctly. 当引用的项目需要覆盖覆盖的系统定义的类型,但是没有绑定重定向可以正确设置此设置时,“经典” csproj项目通常会发生这种情况。 When installing all the packages into a .net framework app (eg NETStandard.Library or NETStandard.Library.NETFramework (for upcoming .NET Standard 2.0)), this should be done automatically. 将所有软件包安装到.net框架应用程序(例如NETStandard.LibraryNETStandard.Library.NETFramework (对于即将推出的.NET Standard 2.0))时,应自动完成此操作。

To force generation of binding redirects, add this to the csproj file of the .NET Framework project (if it is an executable project, the second property should be irrelevant but it doesn't hurt): 要强制生成绑定重定向,请将其添加到.NET Framework项目的csproj文件中(如果它是一个可执行项目,则第二个属性应该无关紧要,但不会受到损害):

<PropertyGroup>
  <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
  <GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
</PropertyGroup>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在带有.NET Core(.NET Standard 1.4和.NET Framework 4.6.1)的System.Net.Http中使用await / async时出现错误? - Bug when using await/async for System.Net.Http with .NET Core (.NET Standard 1.4 and .NET Framework 4.6.1)? .NET Framework 4.6.1应用程序具有引用.NET Standard 1.4类库的错误 - .NET Framework 4.6.1 application has errors referencing .NET Standard 1.4 class library Visual Studio 2017类库项目:无法加载文件或程序集System.IO.FileSystem - Visual Studio 2017 Class Library Project: Could not load file or assembly System.IO.FileSystem 无法在引用 .Net 标准库的已发布 .Net 4.6.1 项目中加载文件或程序集“System.ComponentModel.Annotations” - Could not load file or assembly 'System.ComponentModel.Annotations' in published .Net 4.6.1 project referencing .Net Standard library 使用Mono进行编译:System.IO.FileSystem,版本= 4.0.2.0-&gt;系统找不到指定的文件 - Compiling with Mono: System.IO.FileSystem, Version=4.0.2.0 -> The system cannot find the file specified 无法加载与“ System.Diagnostics.DiagnosticsSource”文件一起使用4.6.1的Net Framework App中的错误 - Error in Net Framework App Using 4.6.1 with “System.Diagnostics.DiagnosticsSource” File Not Load 无法加载文件或程序集&#39;System.Net.Http,Version = 4.1.0.0 .net framework 4.6 .net standard 1.3 - Could not load file or assembly 'System.Net.Http, Version=4.1.0.0 .net framework 4.6 .net standard 1.3 如何修复.net标准2.0项目中的“无法加载文件或程序集System.IO.Packaging,版本= 4.0.3.0” - How to fix 'Could not load file or assembly System.IO.Packaging, Version=4.0.3.0' in a .net standard 2.0 project 假货和 .net Framework 4.6.1 和系统 - Fakes and .net Framework 4.6.1 and System 在 .NET Framework 中使用 .NET Standard 库时获取正确的依赖项版本 - Getting the right dependency version when using a .NET Standard library in .NET Framework
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM