none
ArgumentException was unhandled

    Question

  • I am a newbie in Visual Studio so please excuse my probably naive question in advance. I tried my best to get what I could from Google but wasn't enough.

    I inherited a code developed in VS Express 2010 (VB) and now trying to run/modify it in VS2015. I can Build the project and solution but when I try to debug the code it throw the following message

    An unhandled exception of type 'System.ArgumentException' occurred in UserControlTestContainer.exe
    Also says that my project .dll doesn't contain any UserControl types.

    From my research, I guess it has something to do with version compatibility but I am not sure. Any idea is highly appreciated. I am stuck!

    P.S: This code is an add-in for Autodesk Inventor 2015 which creates a .dll and .addin file to extend the functionality of the software. 

    Thursday, April 27, 2017 4:03 PM

Answers

  • Additional information: Assembly 'C:\Users\...\Documents\My Coding Playground\CS discover\InventorAddIn3\InventorAddIn3\obj\Debug\test.dll' doesn't contain any UserControl types.

    That seems like a project configuration error. For instance, if your project is a class library and you are trying to execute it.   In that case you would usually have another project in the solution which is a test for the class library, and that other project must be set as the startup project. If you have a solution that is only a class library then you can't execute it - you can only build it, and test it from another solution.  That seems like a possibility from your description of inheriting this task.    You can add a test project to the existing solution, but make sure it is the startup project. Then build everything and execute the test.  That may not be the exact scenario, but it will be something along those lines.   See:  https://msdn.microsoft.com/en-us/library/a1awth7y.aspx

    • Marked as answer by Pooya.Row Wednesday, May 3, 2017 1:02 PM
    Friday, April 28, 2017 9:35 PM
  • Error BC30451
    'RunCutSheets' is not declared. It may be inaccessible due to its protection level.

    Is RunCutSheets a method in a class that you are creating in the library?

    You need to ensure that the DLL is included as a reference in the new project.  Then you need to ensure that the methods and members of the classes in that DLL are properly named.  The simplest way to do that is to use an Imports statement at the top of the code where you import the namespace.  Alternatively, each usage of a method or member can include the full name - eg 'MyClassLibrary.UserControlTestContainer.RunCutSheets'. 

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

    In your case the full name will be the namespace, the module name and the method name. You can Import the namespace and the module name.


    • Edited by AcamarMVP Thursday, May 4, 2017 9:48 PM sp
    • Marked as answer by Pooya.Row Friday, May 5, 2017 2:38 PM
    Thursday, May 4, 2017 9:19 PM

All replies

  • Under the debug menu in Visual studio select "exception settings" and place a check on Common Language Runtime Exceptions. Build/run in debug mode. Hopefully the debugger will throw an exception and point to the code that is causing the problem.


    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

    Thursday, April 27, 2017 4:55 PM
    Moderator
  • Wild guesses.

    Is the project or dll in 2015 using a newer version of .net like 4.5 and the old project is .net 2.0 or some other?

    What platform are you set to complile for ie 64 bit or any or x86? Perhaps you are 64 bit and the .dll is 32 bit. Try setting your project to x86 etc.

    Thursday, April 27, 2017 5:00 PM
  • Thanks for the ideas. I tried 32 bit platform and I got the following error:

    An unhandled exception of type 'System.BadImageFormatException' occurred in mscorlib.dll

    and then it says that it cannot load the dll or one of its dependent file or assembly of my project. An attempt was made to load a program with an incorrect format.

    To my knowledge the legacy project was using .net 4.0 (VS2012 Express). I tried both .NET 4.0 and 4.5 for compiling with no success.

    Thursday, April 27, 2017 5:46 PM
  • Thanks Karen for your comment. I still face the same problem after activating all the "Common language runtime exceptions". No extra information is thrown. 
    Thursday, April 27, 2017 5:50 PM
  • Also says that my project .dll doesn't contain any UserControl types.

    What is this exact message?

    "Unhandled exception" simply means that your project has no code to deal with the error - this is the default.  It doesn't tell you what the error is.   But that other comment implies that your project needs a supporting component that hasn't been built, has an error, or is not correctly referenced.  The exact details might help to track it down.

    Thursday, April 27, 2017 10:22 PM
  • Thanks Acamar. Here is the exact message I get:

    An unhandled exception of type 'System.ArgumentException' occurred in UserControlTestContainer.exe

    Additional information: Assembly 'C:\Users\...\Documents\My Coding Playground\CS discover\InventorAddIn3\InventorAddIn3\obj\Debug\test.dll' doesn't contain any UserControl types.

    Nothing is written in the output window but in the Immediate Window the following message pops up.

    Exception thrown: 'System.ArgumentException' in UserControlTestContainer.exe
    Friday, April 28, 2017 3:43 PM
  • A simple search on Internet about that message gives a lot of answers. 

    But those are often related to the kind of project or code which is used. 

    Therefore it is probably easier if you investigate them yourself. 

    If you then don't find them show a piece of code to us where it can happen.

    https://www.google.com/search?q=Exception+thrown%3A+%27System.ArgumentException%27+in+UserControlTestContainer.exe&oq=Exception+thrown%3A+%27System.ArgumentException%27+in+UserControlTestContainer.exe&sourceid=chrome&ie=UTF-8


    Success
    Cor

    Friday, April 28, 2017 3:52 PM
  • Additional information: Assembly 'C:\Users\...\Documents\My Coding Playground\CS discover\InventorAddIn3\InventorAddIn3\obj\Debug\test.dll' doesn't contain any UserControl types.

    That seems like a project configuration error. For instance, if your project is a class library and you are trying to execute it.   In that case you would usually have another project in the solution which is a test for the class library, and that other project must be set as the startup project. If you have a solution that is only a class library then you can't execute it - you can only build it, and test it from another solution.  That seems like a possibility from your description of inheriting this task.    You can add a test project to the existing solution, but make sure it is the startup project. Then build everything and execute the test.  That may not be the exact scenario, but it will be something along those lines.   See:  https://msdn.microsoft.com/en-us/library/a1awth7y.aspx

    • Marked as answer by Pooya.Row Wednesday, May 3, 2017 1:02 PM
    Friday, April 28, 2017 9:35 PM
  • Your hints led me to the right path Acamar. Thanks!

    I simply added a form that calls the class library upon being loaded and compiled it as a Windows Forms Application with the form being the startup object. After debugging, I'll remove the forma and compile the project as a Class Library for release.

    I guess it's not the smartest way but works for me :)

    Wednesday, May 3, 2017 1:02 PM
  • I simply added a form that calls the class library upon being loaded and compiled it as a Windows Forms Application with the form being the startup object.

    The alternative is to add a project, add a reference to the DLL your are building in the class library, then add your form and test code into that project.  Then set that new project as the startup project for the solution, and make sure the class library is recognised as a dependency.  Then you can compile and test, and no changes needed for production.

    Thursday, May 4, 2017 2:06 AM
  • Thanks Acamar! I did all the above as you mentioned. But now, in the new form, when I want to call a Public Sub I used to call through the form in the original project, it cannot be recognized and throws this error: 

    Error BC30451 'RunCutSheets' is not declared. It may be inaccessible due to its protection level.

    I double checked my references but they seem ok. My Public Sub is defined in a Module under the original project. 

    Sorry for asking basic questions! I am learning on the go :0)

    Thursday, May 4, 2017 2:02 PM
  • Error BC30451
    'RunCutSheets' is not declared. It may be inaccessible due to its protection level.

    Is RunCutSheets a method in a class that you are creating in the library?

    You need to ensure that the DLL is included as a reference in the new project.  Then you need to ensure that the methods and members of the classes in that DLL are properly named.  The simplest way to do that is to use an Imports statement at the top of the code where you import the namespace.  Alternatively, each usage of a method or member can include the full name - eg 'MyClassLibrary.UserControlTestContainer.RunCutSheets'. 

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

    In your case the full name will be the namespace, the module name and the method name. You can Import the namespace and the module name.


    • Edited by AcamarMVP Thursday, May 4, 2017 9:48 PM sp
    • Marked as answer by Pooya.Row Friday, May 5, 2017 2:38 PM
    Thursday, May 4, 2017 9:19 PM
  • Thanks so much for clear and helpful answers Acamar!

    Your suggestions solved the problem. The only thing I needed to add was to turn the Module that RunCutSheet method was defined in into a public one to be accessible using the Imports command. 

    Thank you once again.

    Friday, May 5, 2017 2:42 PM