3

create a .net standard dll , name it as Paas dll, and change the output path ..\Output\

add a class logger like below-

 public class Logger 
    {
        public void LogMessage()
        {
            Console.Write("test");
        }
    }

Now create another .net core console project in solution and add dll as a refrence ( not project refrence) for pass.dll and make copy local to false.

Also change output directory of console app to ..\Output\

add below code in console app -

 var logger = new Logger();
  logger.LogMessage();
  Console.Read();

Build and run .net core app, but now application goes in break mode with below error

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

But if you perform same steps with .net framework 4.6.1 projects it works, why this different behavior with .net core exists and how to fix it?

github link for project showcasing this issue - https://github.com/ankgupta067/DependencyInjection.git

16
  • Can you provide exact steps to reproduce (how to set up the projects, etc.)? Commented Apr 16, 2018 at 7:43
  • Do you have to add it as a reference like that, rather than as either a package or a project reference? I can't say I've seen any "old-style" references like that (with hint paths) in "new-style" .NET Core projects. Commented Apr 16, 2018 at 7:46
  • Should work fine. I'd say in current state problem is not reproducable (at least for me). Commented Apr 16, 2018 at 7:54
  • @Daisy You have to add a reference to a DLL instead of a project. Commented Apr 16, 2018 at 8:01
  • 1
    I guess if you have to do it that way, you have to. (I'd still encourage you to try to move away from that over time.) Like Evk, I can't reproduce this - I've just tried doing it with Json.NET as a DLL reference, and it was fine. When you build the project, do you get the DLL in the output directory, e.g. in bin/debug/netcoreapp2.0? Commented Apr 16, 2018 at 8:27

1 Answer 1

2

The issue is setting copy local to false. On .NET Core, in order to know which assemblies should get loaded, it uses what is called a .deps.json file that gets generated next to your output .dll. In order to generate this .deps.json file, the .NET Core SDK inspects information about the assemblies you reference. One of the pieces of information it uses is whether the Reference is CopyLocal or not. See the code here. If you inspect your console app's .deps.json file, you'll see there is no entry for Paas.dll in it.

So in order to make this work, the .deps.json file will need to be written correctly. Using the current tools, that means you will have to stop setting copy local to false. If you want to open an issue for this scenario please log it here. That way it can be fixed in a future release.

OLD ANSWER:

A difference between SDK-based (".NET Core style") .csproj projects and traditional .csproj projects is that by default SDK-based projects will append the target framework to the <OutputPath> property.

So when you say

Also change output directory of console app to ..\Output\

What is really happening is that the output of the SDK-based netstandard library is going to ..\Output\netstandard2.0\Paas.dll and the output of the SDK-based console project is going to ..\Output\netcoreapp2.0\. These are 2 different directories, so the runtime can't find the library.

To stop this behavior, edit both .csproj files and add:

<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>

inside a <PropertyGroup> element.

This will cause both projects to output directly to the specified ..\Output\ folder.

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

2 Comments

well i forgot to mention in question , i did that as well complete github link for project is here github.com/ankgupta067/DependencyInjection.git
Got it. I've updated my answer in light of this information.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.