Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. 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. I'm using Visual Studio 2017.

  • I set the library project target .Net standard 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).
  • I set the generic Windows application to target .Net Framework 4.6.1.

The UWP version compiles and runs fine.

Initially, the .Net Framework 4.6.1 compiles and runs. However, when I make a call to File.Open from System.IO, I get the following error message:

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. The system cannot find the file specified.'

The code block with File.Run is within the library code (.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.


As a workaround, I tried installing the Nuget package for System.IO in the .Net Framework application. System.IO Version 4.0.1.0 is not even an option. There is a version 4.0.10, but it doesn't work when this Nuget package is installed.

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?

like image 534
Brett Woodard Avatar asked May 30 '17 08:05

Brett Woodard


1 Answers

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. When installing all the packages into a .net framework app (e.g. NETStandard.Library or NETStandard.Library.NETFramework(for upcoming .NET Standard 2.0)), this should be done automatically.

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

<PropertyGroup>
  <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
  <GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
</PropertyGroup>
like image 60
Martin Ullrich Avatar answered Oct 21 '22 22:10

Martin Ullrich