dotnet run fails with System.IO.FileNotFoundException if using local class library
See original GitHub issueSteps to reproduce
- Create a console project
dotnet new console -n MyConsole
- Create a class library project
dotnet new classlib -n MyClass
- 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);
}
}
}
- 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:
- Created 7 years ago
- Reactions:3
- Comments:9 (4 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.
@livarcocc I’m confused. After wiping the
bin
folder (and rebuilding it),dotnet .\bin\Debug\netcoreapp2.0\repro.dll
orcd \bin\Debug\netcoreapp2.0
anddotnet repro.dll
both work just fine. If I look at the official docs, it seemsdotnet 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.