Sign in to follow this  
Stefan Fischlschweiger

Strange Exception in the framework

Recommended Posts

So, I've figured out the last problem in my project, only to run straight into the next one.

 

When selecting "New Game" in the main menu I get a FileNotFoundException from mscorlib.dll

 

By stepping through the code with the debugger I found that it happens when this function has finished:

protected override void Update(GameTime gameTime)
        {
                _screenManager.Update(gameTime);
                base.Update(gameTime);        
        }

To be precise, when in debug mode and the current "instruction" is the closing curly bracket I press F11 and the exception happens. I only see that in the output windows though, which says:

 

An exception (first chance) of type "System.IO.FileNotFoundException" was thrown in mscorlib.dll

 

No information on what file it was attempting to access or anything, just this line. The game code isn't supposed to load any file at that point anyway, so my guess is that something is going wrong in the framework itself.

Also, the code runs fine on my other system

Share this post


Link to post
Share on other sites
Washu    7829
You haven't really provided enough information for us to provide you with any meaningful answers.

The chances that this is "something going wrong in the framework itself" are vanishingly slim, thus it must be something on your machine. Something you didn't copy, something you depend upon, etc.

What is the stack trace of the exception? In fact, what is the exact output of the exception... etc. are all things we'll need to assist you in any efforts to debug this.

Share this post


Link to post
Share on other sites
Nypyren    12073
(EDIT) You can safely ignore first-chance exceptions, unless it isn't handled. Since you're not getting a callstack, I believe it's being handled.

"First-chance" means an exception is being thrown somewhere, and the debugger is able to capture it *before* it looks for a catch block for it. There are unfortunately quite a few things in .Net (especially in the Core framework) that will throw-and-then-catch exceptions internally, which result in this kind of noise in the output window.

You can demonstrate the same kind of behavior with the following code, if you want:


try
{
    throw new FileNotFoundException();
}
catch
{
}
Edited by Nypyren

Share this post


Link to post
Share on other sites
Nypyren    12073
There are two things you might try:

First, you can tell the debugger to stop when a first-chance exception occurs. In Debug -> Exceptions, enable the checkbox next to "Common Language Runtime Exceptions". This will suspend the program whenever any of the exception types in that category occur (including FileNotFoundException - you can enable the checkbox for JUST that one if you want to go digging for it). This will give you a callstack when the exception occurs and MIGHT let you see the filename.


Second, you can try enabling .Net framework source stepping. I've had varying levels of success with this, so it may not help us here...

https://msdn.microsoft.com/en-us/library/cc667410.aspx Edited by Nypyren

Share this post


Link to post
Share on other sites
Bearhugger    1276

What is supposed to happen after the function has returned? The only files the CLR should look up for on its own is assemblies and their native DLL.

 

Since it's a "New Game" function, I suspect that the next step makes the first method call to a type located in a different assembly. The CLR does lazy loading with assemblies, so it waits until the code uses an assembly to load it in process memory.

 

I would double-check that you have all required DLL in your program's folder, especially the native DLL dependencies if you have any. MSBuild is usually smart enough to put the custom .NET assemblies in the output folder, but not the native ones.

Share this post


Link to post
Share on other sites

Does this exception cause any problem? It's unclear from your post. Does your game still run?

Yep, sorry, missed that out. When the exception happens the game just quits

After the exception message I get a bunch of "Thread xy has ended with code 1 (0x1)" and some D3D11 Warnings

 

There are two things you might try:

First, you can tell the debugger to stop when a first-chance exception occurs. In Debug -> Exceptions, enable the checkbox next to "Common Language Runtime Exceptions". This will suspend the program whenever any of the exception types in that category occur (including FileNotFoundException - you can enable the checkbox for JUST that one if you want to go digging for it). This will give you a callstack when the exception occurs and MIGHT let you see the filename.


Second, you can try enabling .Net framework source stepping. I've had varying levels of success with this, so it may not help us here...

https://msdn.microsoft.com/en-us/library/cc667410.aspx

Thanks, enabling CLR exceptions did the trick biggrin.png

 

It was looking for a file that I created manually in the output folder on my other system to test some stuff and whích is missing on my laptop

 

I already had a try-catch on the code responsible to create the stream set to catch FileNotFound exceptions and write the name of the file in question into the logfile.

 

Now I feel really stupid ^^ All I actually would have had to do was look at the logfile -.-

Edited by Lordadmiral Drake

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this