23
votes

I've ran into a weird problem.

I basically have my own web-stack for .NET-core which I've built into a few .dlls, and I want to reference these from another ASP CORE-solution.

VS seems to find the assemblies, where I can navigate types etc. I can also build the project without any issues, but when IIS then runs the server I get an internal server error stating:

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

The referenced DLLs are in the debug-folder, and the really weird thing is that if I create a new ASP Core project in the same solution as the web-stack, I can reference and use it without any problems.

Why is this happening only when running on a project outside the web-stack's solution, and what can I do to make it runnable everywhere?

2
Have you set up your reference to be copied to the output folder? (see properties of the reference)Tseng
@Tseng Yes I tried this. Did not make a difference sadlyTokfrans
And you're sure you didn't tried to reference a net4xx library in an netcoreapp1.x project?Tseng
@Tseng Affirmative. Both the library and the web-project is targeting .NETCoreApp 1.1Tokfrans
Libraries shouldn't usually have to target netcoreapp1.x, with the very rare exception of requiring .NET Core only API which is unavailable in netstandard1.x. You should always try to target netstandardTseng

2 Answers

34
votes

The .NET Core Tooling in VS 2017 (< 15.3 preview) / .NET CLI < 2.0 doesn't fully support referencing assemblies on disk. You need to package the library up as a NuGet package or use a project reference ("same solution"). The technical reason is that all the required assemblies and versions are resolved during compilation and written to the .deps.json file. When loading arbitrary assemblies, this might fail because either the assembly or its dependencies cannot be found (or a conflict with each other).

0
votes

for load the external dll in core project, needed to:

  1. vs 2017 with version 15.3 or upper.
  2. Microsoft.Extensions.DependencyModel NuGet package installed in your project.