Daniel Santos
Daniel Santos

Reputation: 15908

FileNotFoundException when after adding a Class Library assembly

I do have an ASP.NET MVC Core app and would like to add a Class library in my project. I added it in my project via "Add Reference" > "Browse" > select DLL and done.

enter image description here

I added it on code like

using PagarMe; // works good on code 

And I was able to compile and run the app. however when the user goes to a page where the lib is referenced then I got the fallowing error.:

FileNotFoundException: Could not load file or assembly 'PagarMe.Pcl, Version=2.0.6372.16631, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.

What I already done.

What can I do in order to use Class Library or PCL library into my Core App?

Upvotes: 2

Views: 251

Answers (1)

rickvdbosch
rickvdbosch

Reputation: 15611

In .NET Core you no longer use Portable Class Libraries, but you target the correct version of the .NET Standard Library. Some PCL or Shared Classes may use some unsupported references.

To solve this please try one of this:

1. Rebuild your Class Library to target .NET Standard. .NET Standard 1.6, for instance, is supported by both .NET Core 1.0 and .NET Framework 4.6.1.

.NET Standard can be thought of as the next generation of Portable Class Libraries (PCL). The .NET Standard improves on the experience of creating portable libraries by curating a standard BCL and establishing greater uniformity across .NET runtimes as a result. A library that targets .NET Standard is a PCL or a ".NET Standard-based PCL". Existing PCLs are "profile-based PCLs". (Taken from the documentation)

2. Target your app to .NET Framework. You could build an ASP.NET Core application to target the full .NET Framework in stead of .NET Core only. This gives you the advantages of ASP.NET Core, without the limits of .NET Core.

ASP.NET Core != .NET Core

Upvotes: 2

Related Questions