C# .NET Core How to debug System.IO.FileNotFoundException in System.Private.CoreLib.dll?
Asked Answered
L

3

24

When I run .NET Core Web API Application on VS 2017,
In Output's Debug panel, keep showing me Exception throw:

'System.IO.FileNotFoundException' in System.Private.CoreLib.dll

However, application runs well without stoping or malfunctioning.
I know Exception always means somthing needs to be cared.

So, how can I search what File is Not Found when run CoreCLR?

------------- more -------------------

'dotnet.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files (x86)\dotnet\shared\Microsoft.NETCore.App\2.0.0\System.Private.Xml.Linq.dll'. Symbols loaded.
'dotnet.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files (x86)\dotnet\shared\Microsoft.NETCore.App\2.0.0\System.Private.Xml.dll'. Symbols loaded.
'dotnet.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files (x86)\dotnet\shared\Microsoft.NETCore.App\2.0.0\System.Resources.ResourceManager.dll'. Symbols loaded.
Exception thrown: 'System.IO.FileNotFoundException' in System.Private.CoreLib.dll
Exception thrown: 'System.IO.FileNotFoundException' in System.Private.CoreLib.dll
Ladder answered 13/10, 2017 at 2:20 Comment(4)
Please provide some code.Sardinia
It just plain .NET Core Web API Application Template. I just followed tutorialLadder
Did you read through the comments on the tutorial to see if anyone else had the same issue?Felspar
I read comments after you mentioned. There is no one asking about this issue becuase tutorial works great even output gives Exception. (also, my code also runs well.) I just look into why program still run correctly even Exception throwed. It could be a .NET Core envrioment settings issue. I just do not know where to start in order to chase this issue.Ladder
P
64

Go to Debug/Windows/Exception Settings and check FileNotFoundException under Common Language Runtime Exceptions. The debugger will stop when the exception is thrown and you will be able to see what is going on.

Note that it is not unusual for exceptions to be expected and handled in some cases. You may find that the exception is expected and handled, and nothing needs to be done to fix it.

Phyfe answered 13/10, 2017 at 3:3 Comment(1)
Finally a use case for this tool were i can learn when to use itLanner
S
1

The above answer helped me pin point my issue in my Test project.

My case: I was using a .netcore csproj targeting net45 and was missing the MSTest adapter reference.

Once I added these all was good.

 <ItemGroup>
    <PackageReference Include="MSTest.TestAdapter" Version="2.2.7" />
    <PackageReference Include="MSTest.TestFramework" Version="2.2.7" />
  </ItemGroup>
Spencer answered 23/9, 2021 at 16:5 Comment(0)
N
-3

This issue come when you click on debug through VS code and you already opened application using command prompt using dotnet run.

Make sure to close the command prompt where you have opened the application by command CTRL+C

Nur answered 24/2, 2023 at 18:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.