5

I'm trying to use a custom DLL (4.5 framework) in a aspnet core 1.1 app.

I'm using Microsoft.NETCore.Portable.Compatibility

When I run the project and try to make a call at some class of the library project, vs2017 throw the following exception.

Could not load file or assembly 'ApiHelperSock, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'. O sistema não pode encontrar o arquivo especificado. 

If I check the bin\Debug\netcoreapp1.1 I can see my dll here.

This is my project.json file

{ "compilerOptions": { "noImplicitAny": false, "noEmitOnError": true, "removeComments": false, "sourceMap": true, "target": "es5" }, "exclude": [ "node_modules", "wwwroot" ] } 

Any ideas ?

--- EDIT ---

Tried to setup a nuget package with my dll, getting the following error when trying to import:

The package ApHelperSock 1.0.0 isn't compatible with netcoreapp1.1 (.NETCoreApp,Version=v1.1). The package ApiHelperSock 1.0.0 supports: net (.NETFramework,Version=v0.0) 

Tried to create a .NETFramework library project, import here and then call the library from my aspnetcore app, without success.

3
  • 1
    As per my knowledge, there is no project.json in VS2017 ASP.NET core project template. Commented Jun 27, 2017 at 3:48
  • @Sanket: Well you can still open old projects old project.json projects in VS2017 when you open it as folder and not via .sln/.xproj, VS won't suggest that you migrate Commented Jun 27, 2017 at 5:51
  • 1
    And btw. the posted json file is not a project.json, it's a tsconfig.json which contains typescript options Commented Jun 27, 2017 at 5:59

2 Answers 2

7

You can't auto-magically use .NET 4.5 libraries in .NET Core applications! Your library has to target netstandard1.0 or higher.

Convert your library to a netstandard1.0 (4.5.2) or netstandard1.2 (.NET 4.5.2) project. If you use .NET 4.5 only Api, you also need to add net45/net452 target and use #ifdef NET45 preprocessor directives to make your code inside it only compile for net452, but not for other platforms.

In .NET Core 2.0 you'll get the ability to reference normal .NET 4.5 libraries, but the same limitations apply and you must be extremely carefully when using it: It will only then work on .NET Core, when the referenced library only uses API which is available on .NET Standard 2.0!!! Using any other API will blow up your program at runtime! This option is only there for people who need to reference a library which is .NET 4.5 but not yet ported for .NET Standard 2.0 (i.e. orphaned nuget packages).

Sign up to request clarification or add additional context in comments.

Comments

0

With thanks to Panagiotis Kanavos ( commenting on my recent duplicate question )

First, switch to .NET 6. .NET 5 reaches End Of Line on May 2022, 3 months away. .NET 6 is the Long Term Support version, with the new fully functional Windows Forms designer. Second, you can't use .NET Old code with .NET (Core) 5 or 6. You can't share any UI-related code, because .NET Old only supports up to .NET Standard 2.0, which doesn't support Windows Forms

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.