How do I reference a UWP+NET46 portable library from a .NET 4.6 console application?

Sander

I have a portable class library project that targets .NET 4.6 and Universal Windows Platform. This class library contains just one class with the following line of code in its constructor:

Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()));

Now I create a new .NET 4.6 console application project in the same solution and add a project reference to the portable class library. Calling the method that houses the above line of code results in 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? There are no compile-time errors or warnings.

Things I have tried: add missing(?) NuGet package manually

It seems that System.IO.FileSystem is a library delivered via NuGet, as part of the Microsoft.NETCore mega-package. Okay, perhaps I need to explicitly add this package to any project that uses my portable class library. I attempt to do so.

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 have tried: create a project.json file

While there is no clear info on the web, I read a few tidbits about a new project.json based NuGet harness or build system. Just to experiment, I created the following project.json file in my console application project:

{
  "dependencies": {
   },
  "frameworks": {
    "net46": { }
  },
  "runtimes": {
    "win-anycpu": { }
  }
}

It works! The runtime error goes away! However, I soon found that this was either not the right solution or not a complete solution. I started writing some code to read configuration section values, which involved making use of the IConfigurationSectionHandler interface, and got 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 assembly. I see a reference to this assembly, but it has a yellow exclamation mark icon, and a warning appears in the warnings window:

The referenced component 'System' could not be found.

This is where I ran out of ideas. Am I missing something totally obvious?

Sander

I have found the solution. My initial attempt was to install the Microsoft.NETCore package into the console application, resulting in the error shown in my original post.

However, if I install only the narrowly-scoped packages, e.g. System.IO.FileSystem, then I achieve success and the application works correctly. Apparently there is something special about the Microsoft.NETCore "master package" that prevents it from correctly installing into dependent projects.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How do I add a reference to F# Portable Library from C# Portable Class Library (PCL)

From Dev

How do I add a reference to F# Portable Library from C# Portable Class Library (PCL)

From Dev

How do I reference Entity Framework 6 from a .NET core class library in RC2?

From Dev

How do I reference Entity Framework 6 from a .NET core class library in RC2?

From Dev

How do I reference a "Portable" .NET assembly from an Azure Cloud Function?

From Dev

Cannot reference .NET Core library from UWP

From Dev

How do I make an OpenGL SuperBible 6 application portable?

From Dev

.NET C# Console Application How do I get more detailed exception information from a production environment

From Java

How do I specify the exit code of a console application in .NET?

From Dev

how do i get a bearer token in a .Net console application?

From Dev

Reference a class library from UWP and ASP.NET 5

From Dev

Is possible to avoid this Exception in System.dll in a Portable library from .net to uwp?

From Dev

Why can't I reference System.Net.Sockets in a Portable Class Library using Xamarin?

From Dev

How do I reference a multi-target .NET Core class library from a 4.6.1 project within the same solution?

From Dev

Portable library in .net core

From Dev

How to create a .NET Core library I can reference from a .NET Core App (Web API)

From Dev

How to generate a standalone console application from .NET

From Dev

How can I reference a .NET Standard 2.0 class libary from a UWP app?

From Dev

How to make a c#.net application portable

From Dev

How to make a c#.net application portable

From Dev

How do I reference a Visual Studio Shared Project in a .NET Core Class Library

From Dev

How do I reference a local class library project in .NET Core 1.1?

From Dev

Use ICommand in Portable Class Library that targets .net 4

From Java

How can I get the application's path in a .NET console application?

From Dev

How to get Log4Net to write to EventLog in Console Application?

From Dev

How do I hide the console after starting a Windows application from it?

From Dev

How do I make SetThreadDesktop API work from a console application?

From Dev

How to reference Windows.winmd from a .NET Core library?

From Dev

How do I reference jQuery from my HTML/JavaScript application?

Related Related

  1. 1

    How do I add a reference to F# Portable Library from C# Portable Class Library (PCL)

  2. 2

    How do I add a reference to F# Portable Library from C# Portable Class Library (PCL)

  3. 3

    How do I reference Entity Framework 6 from a .NET core class library in RC2?

  4. 4

    How do I reference Entity Framework 6 from a .NET core class library in RC2?

  5. 5

    How do I reference a "Portable" .NET assembly from an Azure Cloud Function?

  6. 6

    Cannot reference .NET Core library from UWP

  7. 7

    How do I make an OpenGL SuperBible 6 application portable?

  8. 8

    .NET C# Console Application How do I get more detailed exception information from a production environment

  9. 9

    How do I specify the exit code of a console application in .NET?

  10. 10

    how do i get a bearer token in a .Net console application?

  11. 11

    Reference a class library from UWP and ASP.NET 5

  12. 12

    Is possible to avoid this Exception in System.dll in a Portable library from .net to uwp?

  13. 13

    Why can't I reference System.Net.Sockets in a Portable Class Library using Xamarin?

  14. 14

    How do I reference a multi-target .NET Core class library from a 4.6.1 project within the same solution?

  15. 15

    Portable library in .net core

  16. 16

    How to create a .NET Core library I can reference from a .NET Core App (Web API)

  17. 17

    How to generate a standalone console application from .NET

  18. 18

    How can I reference a .NET Standard 2.0 class libary from a UWP app?

  19. 19

    How to make a c#.net application portable

  20. 20

    How to make a c#.net application portable

  21. 21

    How do I reference a Visual Studio Shared Project in a .NET Core Class Library

  22. 22

    How do I reference a local class library project in .NET Core 1.1?

  23. 23

    Use ICommand in Portable Class Library that targets .net 4

  24. 24

    How can I get the application's path in a .NET console application?

  25. 25

    How to get Log4Net to write to EventLog in Console Application?

  26. 26

    How do I hide the console after starting a Windows application from it?

  27. 27

    How do I make SetThreadDesktop API work from a console application?

  28. 28

    How to reference Windows.winmd from a .NET Core library?

  29. 29

    How do I reference jQuery from my HTML/JavaScript application?

HotTag

Archive