none
System.DLL excption help RRS feed

  • Question

  • I have a VB program that when I run in Debug the following message appears in the Immediate Wingow:

    Exception thrown: 'System.InvalidOperationException' in System.Windows.Forms.dll
    Exception thrown: 'System.ArgumentNullException' in System.dll

    The program does not "crash" and everything runs normally.  After building and installing the program it runs fine with no error messages.  I'm curious at to what those messages are and how to prevent them.

    Thanks in advance.

     

    Philip

    Monday, November 13, 2017 10:54 AM

Answers

  • Phillip,

    In reference to the last screenshot above, test first that ds.Tables(0) IsNot Nothing.

    Why it's null is another problem but for this, test that first.


    "A problem well stated is a problem half solved.” - Charles F. Kettering

    • Marked as answer by Philip Potts Friday, December 1, 2017 12:02 PM
    Saturday, November 25, 2017 11:42 PM

All replies

  • Given the information provided (which means there may be details missing that you don't realize) this may happen because a component used is not fully qualified to handle some situations by not checking a property DesignMode or perhaps from a Exception setting e.g.

    Have you attempted to set a break point in code and step through until the exception is hit?


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Monday, November 13, 2017 11:23 AM
    Moderator
  • Hi Karen,

    Thanks for your reply.  Yes, I have set a break point and stepped through the program.  At no time does the program throw an exception.  At least not that I have been able to find.  This program was originally written using Visual Studio 2015.  I upgraded to Visual Studio 2017 and copied the older program folder into the newer version.  I then uninstalled Visual Studio 2015.  Could that be the reason for the message?


    Philip

    Tuesday, November 14, 2017 12:39 PM
  • Hi,

    The issue persist when you downgrade the Visual Studio to 2015 ?

    I suggest you try to catch the global exception in Main method by handle AppDomain.CurrentDomain.UnhandledException and Application.ThreadException Event .

    Sincerely,

    Stanly


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    • Edited by Stanly Fan Tuesday, November 21, 2017 9:37 AM
    Tuesday, November 21, 2017 9:36 AM
  • Thanks for your reply Stanly.

    I incorporated your suggestions into my code but no exception was thrown by my program.  The exceptions mentioned above appear in the immediate screen as soon as I start the debug process.  However, I feel pretty confident that it is being caused by my program because I do not get the exception with any of my other programs.  I just can't figure it out.  I wrote this program about six years ago and never had this problem.  I believe I had Visual Studio 2010 when I wrote the program.  Ported it to Visual Studio 2015 without issue.  This problem occurred after I copied it to the 2017 folder.  I removed the 2015 edition and deleted the associated files.  I'm wondering if I deleted a system file that this program was pointing to?  Many things happen at the system level that I don't understand.  I've thought about rewriting the program from scratch (using copy and paste) to see how that works.  But really that would involve quite a bit of work.  


    Philip

    Thursday, November 23, 2017 11:49 PM
  • Hi Philp,

    In regards too

    I removed the 2015 edition and deleted the associated files. 

    I see no issues coming from this.

    But this

    I'm wondering if I deleted a system file that this program was pointing to

    More likely there is a newer version of some DLL that may be causing an issue yet no a high likelihood but is possible.



    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Friday, November 24, 2017 12:06 AM
    Moderator
  • Hi Karen,

    Thanks for your reply.  Yes, I have set a break point and stepped through the program.  At no time does the program throw an exception.  At least not that I have been able to find.  This program was originally written using Visual Studio 2015.  I upgraded to Visual Studio 2017 and copied the older program folder into the newer version.  I then uninstalled Visual Studio 2015.  Could that be the reason for the message?


    Philip

     Are you saying that the exception does not show up in the Immediate window if you put a break point in the code and step through it?

     If you are using the Form Load event,  the Form Shown event,  or the Constructor (Public Sub New) in your code to do anything,  then place a Break point at the very beginning of those subs (example image below).  Run the app and when it stops at the Break Point,  see if the exception is listed in the Immediate window yet.

     

     If it is not listed yet,  then keep stepping through the code one line at a time by using the F8 key until the exception appears in the Immediate window.  When you see it,  you will know it was the last line of code that you just stepped off from that caused it.  That will give you a good starting point of what to look at or where to look for the culprit.

     


    If you say it can`t be done then i`ll try it

    • Edited by IronRazerz Friday, November 24, 2017 12:37 AM
    Friday, November 24, 2017 12:36 AM
  • Hi Karen,

    As you suggested I put a break point in at the load screen sub.

    

    This is the result when I step through the program.

    The NullException occurs at the ValueMember = "Name" statement and the InvalidOperationException occurs at the DisplayMember = "Name" statement.  These statements are part of a routine to load names found in an Access database into a combo box.

    Edit:  Both exceptions are coming form the line "DataSource = ds.Tables(0)" not the lines I stated above.

    Any suggestions?

    Again, thank you for your help.


    Philip


    • Edited by Philip Potts Saturday, November 25, 2017 11:49 PM I made a mistake
    Saturday, November 25, 2017 11:32 PM
  • Phillip,

    In reference to the last screenshot above, test first that ds.Tables(0) IsNot Nothing.

    Why it's null is another problem but for this, test that first.


    "A problem well stated is a problem half solved.” - Charles F. Kettering

    • Marked as answer by Philip Potts Friday, December 1, 2017 12:02 PM
    Saturday, November 25, 2017 11:42 PM
  • These statements are part of a routine to load names found in an Access database into a combo box.

    Any suggestions?

    Move that code form the form load event to the form shown event.  It is likely that the form controls are not fully initialised when the Load event executes, and that makes populating the controls subject to this sort of error.

    Saturday, November 25, 2017 11:49 PM
  • Thank you Frank,

    I edited my earlier post to reflect the mistake I made.  Both errors are, in fact, being generated at the statement you reference.  I will do more testing on this.

    You are, as always, most helpful.


    Philip

    Saturday, November 25, 2017 11:52 PM
  • Thank you Frank,

    I edited my earlier post to reflect the mistake I made.  Both errors are, in fact, being generated at the statement you reference.  I will do more testing on this.

    You are, as always, most helpful.


    Philip

    Debugging can be a real pain.

    Hopefully it'll lead up to where the real issue is though. :)


    "A problem well stated is a problem half solved.” - Charles F. Kettering

    Saturday, November 25, 2017 11:55 PM
  • OK, I have traced one of the error down and I see where it's coming from.  I'm not sure why the error message is showing up in the Immediate Window.

    The NullException is thrown at the line "mySerialport = My.Computer.Ports.OpenSerialPort..."

    The program then steps to the Catch line.  I confused as to why the exception is being shown in the Immediate Window when the Catch is in place and working.  I'm going to change my IF statement and see what happens.


    Philip

    Sunday, November 26, 2017 1:28 AM
  • Philip,

    I think you're a bit confused:

    First, test that it's NotNothing; chances are, that's where the NullException originated.

    Secondly, a Try/Catch is only that; take it out (or comment it out) for testing. Later, for production, put it back in and log the failures, but the Try/Catch only catches the exception; it doesn't prevent them.

    As you work through this, work out what's actually throwing the exception and in the meantime, don't use one.


    "A problem well stated is a problem half solved.” - Charles F. Kettering

    Sunday, November 26, 2017 1:37 AM
  •  I can not see what the rest of that line says after the '....OpenSerialPort(lbPort' part of the image.  What does the rest of that line look like?   Is that a Label's Text or maybe a ListBox's Item Text?

     My guess would be that the Text in that control is not set yet and is passing an empty string or invalid port name to the Open method.


    If you say it can`t be done then i`ll try it

    Sunday, November 26, 2017 1:48 AM
  • Hi Phil, in regards to ValueMember = "Name", and the SQL

    SELECT Name FROM Members

    Try 

    SELECT [Name] FROM Members 

    Reason why, in MS-Access Name is a reserve word.

    See what happens when I attempt to create a field using name.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Sunday, November 26, 2017 2:32 AM
    Moderator
  •  I can not see what the rest of that line says after the '....OpenSerialPort(lbPort' part of the image.  What does the rest of that line look like?   Is that a Label's Text or maybe a ListBox's Item Text?

     My guess would be that the Text in that control is not set yet and is passing an empty string or invalid port name to the Open method.


    If you say it can`t be done then i`ll try it

    The full line is:

     mySerialport = My.Computer.Ports.OpenSerialPort(lbPort, 115200, Parity.None, 8, StopBits.One)

    Thank you for taking the time to help.


    Philip

    Sunday, November 26, 2017 2:47 AM
  • Hi Karen,

    I changed the program as you instructed but it didn't make a difference.  

    One of the things that confuses me (and there are many) is that the combo box populates with the names as expected.  The exception makes no difference to the program that I can tell.  Everything works normally.  But it is bugging me that it is there and I can't figure it out.


    Philip

    Sunday, November 26, 2017 2:52 AM
  • Frank, to say I'm a bit confused is an understatement!  At 62 years of age it seems to be a normal state of awareness. :)

    I did change that section of the program to test for NotNothing.  And it worked.  That solved one of the mysteries and half of my current issues.  Now I am working on the second.

    I don't want to sound too fawning, but I really can't thank you enough for your help.


    Philip

    Sunday, November 26, 2017 2:57 AM
  •  My guess would be that the Text in that control is not set yet and is passing an empty string or invalid port name to the Open method.

    You are absolutely correct.  I changed the program to bypass the Open statement if the port name string was empty.  One problem solved, one to go.

    Thank you for your help.


    Philip

    Sunday, November 26, 2017 11:56 AM
  •  My guess would be that the Text in that control is not set yet and is passing an empty string or invalid port name to the Open method.

    You are absolutely correct.  I changed the program to bypass the Open statement if the port name string was empty.  One problem solved, one to go.

    Thank you for your help.


    Philip

     Glad it helped,  it seemed to be the only obvious culprit after you said it jumped to the Catch when it executed that line.

     So,  what is the one left to go?  Are you still getting the 'System.InvalidOperationException' ?  If so,  have you tracked down where in the code or what sub it comes from?

     I also noticed that the name used in that open method is 'lbPort',  is that a Label or other control that has it's Text property set to the serial port name.  If it is,  it should probably be 'lbPort.Text' instead of just 'lbPort'.


    If you say it can`t be done then i`ll try it

    • Edited by IronRazerz Sunday, November 26, 2017 3:24 PM
    Sunday, November 26, 2017 3:19 PM
  • Hi Philip,

    It seems you have solved your problem now, if so, hope you can close this thread by marking the helpful reply as answer as this will help others looking for the same or similar issues down the road.

    Regards,

    Stanly


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, November 27, 2017 1:26 AM
  • Thanks for the reply and the help Iron.

    lbPort is just a text string to hole the serial port number: com1, com5, etc.

    I have traced the message that still remains to another form withing this program.  It is coming from a query to a database.  As yet, I have not nailed it down but I'm getting close.

    I'm going to mark this thread as solved and open another for my current issue.

    Again, thanks for all your help.  And everyone else also.


    Philip

    Friday, December 1, 2017 12:01 PM