question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:3
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
livarcocccommented, Feb 19, 2018

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.

0reactions
SidShetyecommented, Feb 18, 2018

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

dotnet run fails with System.IO.FileNotFoundException if ...
Application crashes with: Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly 'MyClass, Version=1.0.0.0, ...
Read more >
c# - FileNotFoundException when referencing DLL in .NET ...
This error occurs at runtime whenever I include a .NET Core class library in an application: System.IO.FileNotFoundException: 'Could not load ...
Read more >
Debugging System.IO.FileNotFoundException - Cause and fix
Right-click the referenced assembly in Visual Studio, click Properties and make sure that Copy Local is set to true : Set Copy Local...
Read more >
Troubleshoot .NET Framework targeting errors
To resolve the error, make sure that your application targets a .NET version that's compatible with the version that's targeted by the projects ......
Read more >
Could not load file or assembly class library " ...
When I run the application, I receive the error: Could not load file or assembly class library "Microsoft.EntityFrameworkCore version = 6.0 ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found