4

I'm developing a C# application and I get the following error at debug runtime:

An unhandled exception of type 'System.IO.FileNotFoundException' occurred in Unknown Module. Could not load file or assembly 'System.Runtime, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.

And the application goes to the break mode.

I'm new in C# and .NET world. I'm using the Visual Studio for debugging.

Peter Csala
  • 17,736
  • 16
  • 35
  • 75
Beatriz Paegle
  • 41
  • 1
  • 1
  • 2

5 Answers5

11

I had this exact error message earlier. I do not know if our situations are the same, but hopefully, they are, and this fix works for you as well.

So I am also new to c#, and especially visual studio. So, when I opened my project, I would launch visual studio, click open folder, and open the folder my application was in. But alas, I did not know that in fact to open it, you open up the folder in explorer, and double click on the .sln file. If you do that, when you build and/or debug the application, you will not get that error. Or at least if your circumstances are the same as mine.

May I ask, when you open it up, how do you do so? If it is any other way then searching for the .sln in file explorer and double clicking on it, then that is your problem.

Dallin Ivie
  • 119
  • 5
1

The most important hint in the error message is that it's trying to load the System.Runtime assembly, which is part of .NET. The problem has come up before on Stack Overflow: Visual Studio 2017 - Could not load file or assembly 'System.Runtime, Version=4.1.0.0' or one of its dependencies

Consider those solutions first.

catfood
  • 4,267
  • 5
  • 29
  • 55
1

I am also new in C#, and I had the same msg when I tried to open my app written in VSC in VS2019. I created this app using dotNet. The one possible answer is you can run the app using the Open Developer Command Prompt and you can type dotnet run. The app will run automatically.

Pawel
  • 11
  • 1
  • But then how do you debug and step through the code? I'd guess you could call System.Debugger.Breakpoint() and attach VS to the running process but that's not as good as using VS's built-in debugging. – Rup Sep 06 '21 at 10:47
  • This does not really answer the question. If you have a different question, you can ask it by clicking [Ask Question](https://stackoverflow.com/questions/ask). To get notified when this question gets new answers, you can [follow this question](https://meta.stackexchange.com/q/345661). Once you have enough [reputation](https://stackoverflow.com/help/whats-reputation), you can also [add a bounty](https://stackoverflow.com/help/privileges/set-bounties) to draw more attention to this question. – Rian Schmits Sep 06 '21 at 14:23
  • This answered my question. **dotnet watch** didn't work for me, but **dotnet run** worked. Thanks – samayo Mar 23 '22 at 13:33
0

This happens when you open the file folder. Open the solution file by double click on the .sln file in the file folder.

Chanuka
  • 127
  • 1
  • 4
0

Solution:

  1. Open Project in VS
  2. In Solution Explorer Section, double-click on xyz.sln file (there must be a .sln file)
  3. pop-up open, click on OK
  4. Now the Problem is solved, your project is ready for compile.