HELP strange error

Posted on 2006-04-27
Last Modified: 2008-03-10
I am making my first vb application.
I was trying to use a folder browser and was getting errors when using that path to open a file for writing.

I got rid of the code, and for some reason I can't run my application any more.

So now I have a form with a few buttons on it and almost no code after that.
I have one button event that definitely works.

I am getting this error

System.InvalidOperationException was unhandled
  Message="An error occurred creating the form. See Exception.InnerException for details.  The error is: Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed."
       at WindowsApplication1.My.MyProject.MyForms.Create__Instance__[T](T Instance)
       at WindowsApplication1.My.MyProject.MyForms.get_Form1()
       at WindowsApplication1.My.MyApplication.OnCreateMainForm()
       at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
       at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
       at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
       at WindowsApplication1.My.MyApplication.Main(String[] Args)
       at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.runTryCode(Object userData)
       at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
Question by:jackjohnson44
    LVL 1

    Assisted Solution

    Put the code that is failing in a TRY CATCH block.  Then put a break after the exception is caught...

    Catch ex As Exception
    End Try

    Put the break at the Msgbox line.  Then investigate the ex in your locals windows and find the inner exception and read that exception's message.

    Author Comment

    I don't have any code, I even got rid of everything except

    Public Class Form1
    end class

    I am not sure what is going on with the other files .net uses, but I didn't touch any of them.
    I tried opening a dialog, adding "\test.txt", writing to it.
    I was getting errors, so I got rid of everything and now I can't do anything.

    Is there a way to figure out what lines are causing the problems?

    I tried adding imports on my form in various places, but got rid of it.
    LVL 3

    Assisted Solution


    sounds like you might have items defined in your designer.vb file that do not exist on design mode.  

    Imports          needs to be at the very top of your initial form.  You can not add "in various places".

    Can you describe what your form does?


    Author Comment

    I tried putting it on my form above the class and below, but I took it out.
    Like I said before, it is a blank form class with some buttons on it.

    Basically I added a bunch of code to my form, then got rid of all of it.
    I was trying to get rid of the problem by deleting all that I had added.

    Again, the only file I touched was the form.

    If something was added to designer.vb, I did not do it.

    When I run the project, I get the error
    "InvalidOperationException was unhandled"
    I pasted the rest above.
    LVL 5

    Assisted Solution

    I think Jack is right, you have something defined in your designer.vb file that does not exist on design mode.  If all you have is a form with no code, I would delete the form and then create a new one. You can even copy the buttons and paste them on the new form if you want to keep them.

    Good Luck
    LVL 3

    Accepted Solution

    Generally, designer.vb is automatically updated when moving elements into your form.  For instance, moving things in and then deleting them afterwards can sometimes hang up in the designer.vb code, causing it to not to be removed.  Especially when removing more than one elements at a time.  Like a mass deletion.  Maralans has a good idea.  It seems as though not much is invested in this form with no code, just start in over.  

    Note:  all namespace references (Imports System.IO and similar) will always reside at the very top of the form.  Even above the class declaration.

    LVL 3

    Expert Comment

    Just thinking...  but do you have any properties that are required to be initalized (buttons, labels, grids), say on a form load operation.  This might be a clue?  If you double click the form background you can find your form_load event.

    Can you describe what your form does?

    LVL 5

    Expert Comment

    To expand on what Kudzullc is saying you can also open up the designer.vb file and see if there is a block of code or a line referencing something that is no longer on your form.
    LVL 2

    Assisted Solution

    For now, since you have no code, make a completely new project. Fixing what you have is harder...
    Add buttons to GUI then add your own code in the button click event.
    For the future, try not to modify "Windows Form Designer Generated Code"

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Join & Write a Comment

    Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
    Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    This video discusses moving either the default database or any database to a new volume.

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now