Share via


Troubleshooting Exceptions: System.InvalidOperationException

An InvalidOperationException exception is thrown when the failure to invoke a method is caused by a reason other than an invalid argument. This might be thrown by .NET Framework methods when the underlying Win32 method cannot be invoked.

Associated Tips

  • If you are using the Graphics object after the GetHdc method, call the ReleaseHdc method.
    This will release the context handle obtained by a previous call to the GetHdc method of the Graphics object.

  • TableAdapters require valid UPDATE, INSERT, and DELETE commands to perform a successful save operation.
    TableAdapters generate INSERT, UPDATE, and DELETE statements based on the original SELECT statement entered into the wizard. In some situations, the SELECT statement does not provide enough information for the adapter to generate the commands that are required to create the INSERT, UPDATE, and DELETE commands required for a successful save. This often occurs when the database table does not have a primary key column, or the SELECT command uses JOINS. For more information, see How to: Edit TableAdapters.

  • Pass a valid endpoint name to the service client constructor.
    When a Windows Communication Foundation (WCF) client has only one endpoint, there is no ambiguity and you do not have to list the endpoint as an argument. However, when two or more endpoints exist for the same contract type, you must specify which one the client uses. For example, defining a client as an instance of ServiceReference.ServiceSoapClient(), without an argument, raises this exception. You can resolve the problem by specifying a particular endpoint:

    Dim client As New ServiceReference.ServiceSoapClient("ServiceSoap")

    Similarly, this exception is raised if you provide an endpoint name that cannot be found. In this case, you must identify and provide a valid endpoint name.

Remarks

When you run your code in the Visual Studio debugger, an InvalidOperationException is thrown if you access a UI element from any thread other than the one on which it was created. The debugger does this to warn you about a dangerous programming practice. UI elements are not thread-safe and should be accessed only on the thread that created them. For more information, see Multithreading in Visual Basic.

If the method invocation failure is caused by an invalid argument or arguments, ArgumentException or one of its derived classes, ArgumentNullException or ArgumentOutOfRangeException, should be thrown instead.

For 64 bit development with Visual Studio and SQL Server Compact 3.5, the Target CPU option in the Advanced Compiler Settings must be explicitly set to x86. When the Target CPU is set to the default value of Any CPU, you might receive an "Unable to load sqlceme35.dll" message. Set the Target CPU option in the Advanced Compiler Settings in project properties.

See Also

Tasks

How to: Use the Exception Assistant

Troubleshooting Service References

Reference

InvalidOperationException

GetHdc

ReleaseHdc