Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
942 views
in Technique[技术] by (71.8m points)

c# - .NET Core - Could not load file or assembly

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 binDebug etcoreapp1.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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...