Windows Forms application working in Release but not in Debug

desmo

Member
Joined
Jan 3, 2018
Messages
14
Programming Experience
Beginner
Visual Studio Enterprise 2015.
Simple Windows Forms C# application, which a few TextBoxes. The information in the text boxes are stored in an application.settings file, so that the entries are saved and reloaded on quit/startup.

Up until now, I've been building and running the app in VS in the Build configuration. Now, suddenly when I try building/running it, I get a NullReferenceException that wasn't there before. No changes in the code whatsoever after the last successful run. The strange thing is that the exception occurs in the application.Designer.cs file, which I've not edited manually at all. My code contains all the try-catches necessary. Here's the code in application.Designer.cs about which VS suddenly started complaining (in red):

C#:
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
public int rowcount {
    get {
        [COLOR=#ff0000]return ((int)(this["rowcount"]));[/COLOR]
     }
     set {
        this["rowcount"] = value;
     }
}

The complete error from the VS debugger:

C#:
[B]NullreferenceException was unhandled[/B]

An unhandled exception of type 'System.NullreferenceException' occured in ...

Additional information: Object reference not set to an instance of an object.

It's not possible to do any try-catch checking in that file, as far as I can see? In any case, this error suddenly appeared after I switched to the Release configuration, did a few builds/runs, and then switched back to Debug.

When I switch configuration to Release and do a build/run, then it works like before. No errors.

I've cleaned the solution and rebuilt, but other than that I don't know what else to try.

I also tried creating a new configuration, copying the settings from the (working) Release configuration. When I try building/running that, I get the same Exception error as in the Debug configuration.

Any ideas? I'd like to be able to build and run the solution in both the Debug and Release configurations. In any case, I'd like this seemingly random error gone. I hate errors like this, that seemingly makes no sense.
 
Last edited:
Just so you know, I did read the rest of your post after posting that but I don't really have a solution to offer. That said, it doesn't sound normal and something is likely corrupt. If it's not too onerous a task, I'd be inclined to create a new project and start importing the existing types into it.
 
I did. I created a new solution and replicated the original solution manually. In this solution, the error occurs in both the Release and Debug configurations.

So, this is the new state:

Original Solution:
- Debug configuration: Suddenly started throwing NullReferenceException exceptions everywhere the code is accessing the application.settings file.
- Release configuration: Still throws NullReferenceException only in the places where it acutally makes sense.
- New Configuration: Throwing NullReferenceException exceptions everywhere the code is accessing the application.settings file.

New Solution, copied manually from the Original:

- Debug Configuration: Throwing NullReferenceException exceptions everywhere the code is accessing the application.settings file.
- Release Configuration: Throwing NullReferenceException exceptions everywhere the code is accessing the application.settings file.

Visual Studio is making itself VERY hard to love.

I can get the new solution to work if I add try-catch blocks everywhere it's accessing the application.settings file - or use a global try-catch. But why do I have to, when I didn't have to a few hours ago?

UPDATE:
As a last test, I cloned the solution manually. Copied it to another name and changed all the name references. It runs fine, but with the exact same problems as were not present in the original.
 
Last edited:

Latest posts

Back
Top Bottom