Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
Previous Versions
.NET Framework 3.0
Class Library
System

  Switch on low bandwidth view
InvalidOperationException Class
The exception that is thrown when a method call is invalid for the object's current state.

Namespace: System
Assembly: mscorlib (in mscorlib.dll)

Visual Basic (Declaration)
<SerializableAttribute> _
<ComVisibleAttribute(True)> _
Public Class InvalidOperationException
    Inherits SystemException
Visual Basic (Usage)
Dim instance As InvalidOperationException
C#
[SerializableAttribute] 
[ComVisibleAttribute(true)] 
public class InvalidOperationException : SystemException
C++
[SerializableAttribute] 
[ComVisibleAttribute(true)] 
public ref class InvalidOperationException : public SystemException
J#
/** @attribute SerializableAttribute() */ 
/** @attribute ComVisibleAttribute(true) */ 
public class InvalidOperationException extends SystemException
JScript
SerializableAttribute 
ComVisibleAttribute(true) 
public class InvalidOperationException extends SystemException
XAML
Not applicable.

InvalidOperationException is used in cases when the failure to invoke a method is caused by reasons other than invalid arguments. For example, InvalidOperationException is thrown by:

  • MoveNext if objects of a collection are modified after the enumerator is created.

  • GetString if the resource set is closed before the method call is made.

If the method invocation failure is due to invalid arguments, then ArgumentException or one of its derived classes, ArgumentNullException or ArgumentOutOfRangeException, should be thrown instead.

  • The Ldflda Microsoft intermediate language (MSIL) instruction throws InvalidOperationException.

InvalidOperationException uses the HRESULT COR_E_INVALIDOPERATION, which has the value 0x80131509.

For a list of initial property values for an instance of InvalidOperationException, see the InvalidOperationException constructors.

System.Object
   System.Exception
     System.SystemException
      System.InvalidOperationException
         Derived Classes
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

XNA Framework

Supported in: 1.0
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
System.Net.WebWxception and System.InvalidOperation Exception      siddharth__04   |   Edit   |   Show History
Hi

I am new to the c#, I am trying to develop an application which queries the website

http://patft.uspto.gov/netahtml/PTO/search-bool.html

and then the application fills the term1 field (which is given by user) and the field1 as the assignee name

I have written the following code but I am getting the exception: System.Net.WebException

the code is:

public Form2(TextBox t)
{
InitializeComponent();

label1.Text = t.Text;

StringBuilder sb = new StringBuilder();
byte[] buf = new byte[100000000];



try
{
string webpage_data = "Sect1=PTO2&Sect2=HITOFF&p=1&u=/netahtml/PTO/search-bool.html&r=0&f=S&l=50&TERM1=" + t.Text + "&FIELD1=ASNM&co1=AND&TERM2=&FIELD2=&d=PTXT";
// string webpage_data = "TERM1=" + t.Text + "&FIELD1=ASNM";
// string webpage = "http://patft.uspto.gov/netacgi/nph-Parser";
string webpage = "http://patft.uspto.gov/netahtml/PTO/search-bool.html";

ASCIIEncoding encoding = new ASCIIEncoding();
byte[] data = encoding.GetBytes(webpage_data);
webpage = webpage + "?" + webpage_data;
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(webpage);

myRequest.Credentials = CredentialCache.DefaultCredentials;
HttpWebResponse response = (HttpWebResponse)myRequest.GetResponse();

myRequest.ContentLength = data.Length;
myRequest.Method = "GET";
myRequest.ContentType = "application/x-www-form-urlencoded";
myRequest.ContentLength = data.Length;

Stream newStream = myRequest.GetRequestStream();

newStream.Write(data, 0, data.Length);

Stream receive_stream = response.GetResponseStream();

StreamReader read_stream = new StreamReader(receive_stream, Encoding.UTF8);

string str = read_stream.ReadToEnd();

newStream.Close();


// response.GetResponseStream(read_stream.ReadToEnd());

response.Close();
read_stream.Close();

richTextBox1.Text = str;

}
catch (Exception)
{

throw;
}

and the stack trace is as follows:


'WindowsFormsApplication1.vshost.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_32\mscorlib\2.0.0.0__b77a5c561934e089\mscorlib.dll'
'WindowsFormsApplication1.vshost.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.HostingProcess.Utilities\9.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.HostingProcess.Utilities.dll'
'WindowsFormsApplication1.vshost.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_MSIL\System.Windows.Forms\2.0.0.0__b77a5c561934e089\System.Windows.Forms.dll'
'WindowsFormsApplication1.vshost.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_MSIL\System\2.0.0.0__b77a5c561934e089\System.dll'
'WindowsFormsApplication1.vshost.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_MSIL\System.Drawing\2.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll'
'WindowsFormsApplication1.vshost.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.HostingProcess.Utilities.Sync\9.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.HostingProcess.Utilities.Sync.dll'
'WindowsFormsApplication1.vshost.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.Debugger.Runtime\9.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.Debugger.Runtime.dll'
'WindowsFormsApplication1.vshost.exe' (Managed): Loaded 'C:\Users\Siddharth\Documents\Visual Studio 2008\Projects\WindowsFormsApplication1\WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.vshost.exe'
'WindowsFormsApplication1.vshost.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_MSIL\System.Core\3.5.0.0__b77a5c561934e089\System.Core.dll'
'WindowsFormsApplication1.vshost.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_MSIL\System.Xml.Linq\3.5.0.0__b77a5c561934e089\System.Xml.Linq.dll'
'WindowsFormsApplication1.vshost.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_MSIL\System.Data.DataSetExtensions\3.5.0.0__b77a5c561934e089\System.Data.DataSetExtensions.dll'
'WindowsFormsApplication1.vshost.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_32\System.Data\2.0.0.0__b77a5c561934e089\System.Data.dll'
'WindowsFormsApplication1.vshost.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_MSIL\System.Deployment\2.0.0.0__b03f5f7f11d50a3a\System.Deployment.dll'
'WindowsFormsApplication1.vshost.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_MSIL\System.Xml\2.0.0.0__b77a5c561934e089\System.Xml.dll'
The thread 0x15dc has exited with code 0 (0x0).
The thread 0x1154 has exited with code 0 (0x0).
The thread 0x1148 has exited with code 0 (0x0).
'WindowsFormsApplication1.vshost.exe' (Managed): Loaded 'C:\Users\Siddharth\Documents\Visual Studio 2008\Projects\WindowsFormsApplication1\WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.exe', Symbols loaded.
'WindowsFormsApplication1.vshost.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_MSIL\System.Configuration\2.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll'
A first chance exception of type 'System.InvalidOperationException' occurred in System.dll
A first chance exception of type 'System.InvalidOperationException' occurred in WindowsFormsApplication1.exe
An unhandled exception of type 'System.InvalidOperationException' occurred in WindowsFormsApplication1.exe

Additional information: This property cannot be set after writing has started.

The thread 'vshost.RunParkingWindow' (0x1710) has exited with code 0 (0x0).
The program '[4280] WindowsFormsApplication1.vshost.exe: Managed' has exited with code -532459699 (0xe0434f4d).


Any help would be highly appreciated.

Thanks


Tags What's this?: Add a tag
Flag as ContentBug
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker