locked
First Chance Exception while Declaring Class RRS feed

  • Question

  • Hello,

    I am getting a first chance exception of type 'system.formatexception' occurred in mscorlib.dll when declaring my classlike shown below

    namespace Gartech_Sales_Demo
    {
        public partial class Form1 : Form
        {
            public ModbusTCP.Master MBmaster;
            Connection cs_Connection = new Connection(); // Class
            DeclarationsMethod cs_DeclarationsMethod = new DeclarationsMethod();
            ReadModbusTag cs_ReadModbusTag = new ReadModbusTag();
            WriteModbusTag cs_WriteModbusTag = new WriteModbusTag();
            public Form1()
            {
                InitializeComponent();
            }
    }
    }

    When I comment

         Connection cs_Connection = new Connection(); // Class
            DeclarationsMethod cs_DeclarationsMethod = new DeclarationsMethod();
            ReadModbusTag cs_ReadModbusTag = new ReadModbusTag();
            WriteModbusTag cs_WriteModbusTag = new WriteModbusTag();

    My form Appears and it works

    Whats the problem ...It was working in the morning and now it stopped


    Thursday, April 28, 2016 11:32 AM

Answers

  • Hi,

    the code you provided is not enough. Could you please give us the exact exception details including the stacktrace?

    Then it is important to show us the exact code where the exception occured.

    One possibility that you could try to localize the problem is to debug your application. Please make sure that the debugger stops when the exception is thrown:
    Press Ctrl + Alt + E to open the Exception settings
    Mark Common Language Runtime Exceptions completly or mark at least the System.FormatException. That way you can directly see the code, where the exception is thrown inside the debugger.

    With kind regards,

    Konrad

    • Proposed as answer by Kristin Xie Wednesday, May 4, 2016 8:07 AM
    • Marked as answer by Kristin Xie Friday, May 6, 2016 1:23 AM
    Thursday, April 28, 2016 11:44 AM
  • One of the methods mentioned in your commented out code is throwing the exception. You'll need to step through your code and wait for the exception to occur. When it does you'll have the callstack and exception information to identify the issue. Sounds like you are probably getting data from your modbus call that you didn't expect (bad date, number, etc). You'll have to code for that particular problem.

    Michael Taylor
    http://www.michaeltaylorp3.net

    • Proposed as answer by Kristin Xie Wednesday, May 4, 2016 8:07 AM
    • Marked as answer by Kristin Xie Friday, May 6, 2016 1:23 AM
    Thursday, April 28, 2016 6:48 PM
  • I will share with you some things I have done to solve problems such as this. This will sound like a lot of work but this is more than just words, I have done what I suggest myself.

    Reduce your program down to the most minimal program possible that recreates the problem. Try to make it as small as possible. When the problem goes away, undo what you did and try to remove other parts until you get to the smallest as possible. Then if the problem has not been identified, analyze what you have as much as you can. Then if you can't figure it out then hopefully the sample will be small enough that you can post the entire source here that recreates the problem.

    I once spent a few hours doing that and then someone else was able to see very quickly that I had done something stupid. Don't feel bad if you finally realize that the problem is very obvious once it becomes obvious.

    Consistent with that, problems are often so simple that we can't see them because we are expecting something difficult.



    Sam Hobbs
    SimpleSamples.Info

    • Proposed as answer by Kristin Xie Wednesday, May 4, 2016 8:07 AM
    • Marked as answer by Kristin Xie Friday, May 6, 2016 1:23 AM
    Friday, April 29, 2016 9:12 AM

All replies

  • Hi,

    the code you provided is not enough. Could you please give us the exact exception details including the stacktrace?

    Then it is important to show us the exact code where the exception occured.

    One possibility that you could try to localize the problem is to debug your application. Please make sure that the debugger stops when the exception is thrown:
    Press Ctrl + Alt + E to open the Exception settings
    Mark Common Language Runtime Exceptions completly or mark at least the System.FormatException. That way you can directly see the code, where the exception is thrown inside the debugger.

    With kind regards,

    Konrad

    • Proposed as answer by Kristin Xie Wednesday, May 4, 2016 8:07 AM
    • Marked as answer by Kristin Xie Friday, May 6, 2016 1:23 AM
    Thursday, April 28, 2016 11:44 AM
  • One of the methods mentioned in your commented out code is throwing the exception. You'll need to step through your code and wait for the exception to occur. When it does you'll have the callstack and exception information to identify the issue. Sounds like you are probably getting data from your modbus call that you didn't expect (bad date, number, etc). You'll have to code for that particular problem.

    Michael Taylor
    http://www.michaeltaylorp3.net

    • Proposed as answer by Kristin Xie Wednesday, May 4, 2016 8:07 AM
    • Marked as answer by Kristin Xie Friday, May 6, 2016 1:23 AM
    Thursday, April 28, 2016 6:48 PM
  • I will share with you some things I have done to solve problems such as this. This will sound like a lot of work but this is more than just words, I have done what I suggest myself.

    Reduce your program down to the most minimal program possible that recreates the problem. Try to make it as small as possible. When the problem goes away, undo what you did and try to remove other parts until you get to the smallest as possible. Then if the problem has not been identified, analyze what you have as much as you can. Then if you can't figure it out then hopefully the sample will be small enough that you can post the entire source here that recreates the problem.

    I once spent a few hours doing that and then someone else was able to see very quickly that I had done something stupid. Don't feel bad if you finally realize that the problem is very obvious once it becomes obvious.

    Consistent with that, problems are often so simple that we can't see them because we are expecting something difficult.



    Sam Hobbs
    SimpleSamples.Info

    • Proposed as answer by Kristin Xie Wednesday, May 4, 2016 8:07 AM
    • Marked as answer by Kristin Xie Friday, May 6, 2016 1:23 AM
    Friday, April 29, 2016 9:12 AM