Results 1 to 5 of 5

Thread: Windows Forms application working in Release but not in Debug

  1. #1
    .NET Framework
    .NET 4.0
    Join Date
    Jan 2018
    Posts
    14
    Rep Power
    7

    Windows Forms application working in Release but not in Debug

    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):

    Code:
    [global::System.Configuration.UserScopedSettingAttribute()]
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
    public int rowcount {
        get {
            return ((int)(this["rowcount"]));
         }
         set {
            this["rowcount"] = value;
         }
    }
    The complete error from the VS debugger:

    Code:
    NullreferenceException was unhandled
    
    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 by desmo; 01-05-2018 at 7:29 AM.

  2. #2
    .NET Framework
    .NET 4.0
    Join Date
    Apr 2011
    Posts
    1,787
    Rep Power
    137
    Quote Originally Posted by desmo View Post
    Visual Studio Enterprise 2016.
    There is no such thing. VS 2015 was followed by VS 2017.

  3. #3
    .NET Framework
    .NET 4.0
    Join Date
    Jan 2018
    Posts
    14
    Rep Power
    7
    Typo. Thanks for pointing that out.

  4. #4
    .NET Framework
    .NET 4.0
    Join Date
    Apr 2011
    Posts
    1,787
    Rep Power
    137
    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.

  5. #5
    .NET Framework
    .NET 4.0
    Join Date
    Jan 2018
    Posts
    14
    Rep Power
    7
    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 by desmo; 01-05-2018 at 10:59 AM.

Similar Threads

  1. Question .NET 3.5, Build on Windows 10, Debug on Windows XP
    By MrPresident in forum Deployment
    Replies: 1
    Last Post: 09-30-2017, 11:32 PM
  2. Windows Forms application with a shared database
    By marcusdyson in forum Windows Forms
    Replies: 1
    Last Post: 06-29-2017, 9:15 PM
  3. Replies: 1
    Last Post: 10-21-2014, 2:13 PM
  4. Windows Forms Application and WPF Application
    By jdy0803 in forum C# General Discussion
    Replies: 2
    Last Post: 05-24-2013, 5:51 PM
  5. debug windows
    By jassie in forum IDE
    Replies: 0
    Last Post: 02-07-2013, 3:14 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •