I have a portable class library project that is for .NET 4.6 and Universal Windows Platform. This class library contains only one class with the following line of code in its constructor:
Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()));
Now I am creating a new project for the .NET 4.6 console application in the same solution and adding the project link to the portable class library. Calling a method that contains the above line of code causes the following exception at runtime:
Could not load file or assembly 'System.IO.FileSystem, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
What am I doing wrong here? Errors or warnings during compilation do not exist.
What I tried: add the missing (?) NuGet package manually
It seems that System.IO.FileSystem is a library provided through NuGet as part of the Microsoft.NETCore mega-package. Well, maybe I need to explicitly add this package to any project that uses my portable class library. I am trying to do this.
Could not install package 'Microsoft.NETCore.Platforms 1.0.0'. You are trying to install this package into a project that targets '.NETFramework,Version=v4.6', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.
No luck with this approach.
Things I tried: create a project.json file
While there is no clear information on the Internet, I read a few tidbits about the new NuGet harness or assembly system based on project.json. To experiment, I created the following project.json file in a console application project:
{ "dependencies": { }, "frameworks": { "net46": { } }, "runtimes": { "win-anycpu": { } } }
It works! Runtime error disappears! However, I soon discovered that this was either a wrong decision or not a complete solution. I started writing some code to read the values โโof the configuration section, which included using the IConfigurationSectionHandler interface and received the following compile time error:
error CS0246: The type or namespace name 'IConfigurationSectionHandler' could not be found (are you missing a using directive or an assembly reference?)
This interface is part of the system build. I see a link to this assembly, but it has a yellow exclamation mark icon, and a warning appears in the warning window:
The referenced component 'System' could not be found.
Here I ran out of ideas. Am I missing something completely obvious?