Skip to content

dotnet run fails with System.IO.FileNotFoundException if using local class library #7814

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
alejiro opened this issue Feb 25, 2017 · 9 comments
Milestone

Comments

@alejiro
Copy link

alejiro commented Feb 25, 2017

Steps to reproduce

  1. Create a console project dotnet new console -n MyConsole
  2. Create a class library project dotnet new classlib -n MyClass
  3. Reference class library project in the console project MyConsole.csproj file using:
<ItemGroup>
    <Reference Include="MyClass">
       <HintPath>path_to_library/MyClass.dll</HintPath>
    </Reference>
 </ItemGroup

4.Use MyClass in MyConsole

using System;
using MyClass;

namespace MyConsole
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(MyClass.HelloWorld);
        }
    }
}
  1. Run MyConsole application dotnet run

Expected behavior

Application executes

Actual behavior

Application crashes with:

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

Environment data

dotnet --info output:

.NET Command Line Tools (1.0.0-rc4-004893)

Product Information:
 Version:            1.0.0-rc4-004893
 Commit SHA-1 hash:  ca4d0b8fbb

Runtime Environment:
 OS Name:     Mac OS X
 OS Version:  10.12
 OS Platform: Darwin
 RID:         osx.10.12-x64
 Base Path:   /usr/local/share/dotnet/sdk/1.0.0-rc4-004893
@livarcocc
Copy link
Contributor

Is it possible for you to reference the library you depend on with a ProjectReference instead of a direct reference. That will work with the 1.0 version of the tools.

Also, we have added support for direct references in 2.0. So, if you need that, you can try with the 2.0 version of the tooling, but keep in mind that that is an early version preview.

@Jonathan34
Copy link

Project reference or packagereference which means DotNet pack to create a nuget package until 2.0 is out

@los93sol
Copy link

los93sol commented Aug 25, 2017

I am using the 2.0 version of the tools but this still does not work. I am unable to add a project reference as I don't own the source code for the dll that is being referenced.

dotnet --info
.NET Command Line Tools (2.0.0)

Product Information:
Version: 2.0.0
Commit SHA-1 hash: cdcd192

Runtime Environment:
OS Name: Windows
OS Version: 10.0.15063
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\2.0.0\

Microsoft .NET Core Shared Framework Host

Version : 2.0.0
Build : e8b8861ac7faf042c87a5c2f9f2d04c98b69f28d

@SidShetye
Copy link

@livarcocc , why was this issue closed without resolution? This is an issue even on .NET Command Line Tools (2.1.4) and we're running into it too.

@livarcocc
Copy link
Contributor

Can you provide a small repro repo? Like on github that we can try running ourselves? Makes debugging these things that much easier.

@SidShetye
Copy link

@livarcocc we're not able to repro this anymore after wiping out the \bin folder. Before wiping the bin folder, this is what we observed

  • FAILS: dotnet .\bin\Debug\netcoreapp2.0\repro.dll
  • PASSES: loading the repro.csproj in Visual Studio and hitting F5
  • PASSES: dotnet run .\repro.csproj

For now we're moving on. Not sure what happened when we cleared out the older bin folder :(

@livarcocc
Copy link
Contributor

The failed scenario is not supposed to work. You can execute the contents of your build folder like that. You can do that with the contents of your publish folder.

@SidShetye
Copy link

@livarcocc I'm confused. After wiping the bin folder (and rebuilding it), dotnet .\bin\Debug\netcoreapp2.0\repro.dll or cd \bin\Debug\netcoreapp2.0 and dotnet repro.dll both work just fine. If I look at the official docs, it seems dotnet myapp.dll should indeed work. So why are you saying the failed scenario is not supposed to work? We're new to the new tooling, so genuinely curious.

@livarcocc
Copy link
Contributor

Executing dotnet myapp.dll is the way to execute Framework Dependent Applications. You are right on that. However, running your app from the build folder is not the way to distribute or execute your app in production.

When ready to move your app into production, you should publish your app and xcopy the contents of the publish folder as a way to distribute it. See https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-publish?tabs=netcore2x. Hope this helps.

@msftgits msftgits transferred this issue from dotnet/cli Jan 31, 2020
@msftgits msftgits added this to the 2.0.0 milestone Jan 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants