title: Getting Error System.InvalidOperationException When Invoke WebService Method
body: <p>I had Create One WebService..and Create Get Method inside WebService..</p>
  <p>My code is</p>
  <blockquote>
  <p>public class WebService : System.Web.Services.WebService
  {</p>
  <pre><code>    DataClassesDataContext db = new DataClassesDataContext();
  
      public WebService () 
      {
          //Console.log(&quot;Enter&quot;);
          //Uncomment the following line if using designed components 
          //InitializeComponent(); 
      }
  
      [WebMethod]
      public string HelloWorld() {
          return &quot;Hello World&quot;;
      }
  
      [WebMethod]
      [ScriptMethod(ResponseFormat = ResponseFormat.Json, UseHttpGet = true)]
      public object Get()
      {        
          return db.Countries.ToList();
      }
  }
  </code></pre>
  </blockquote>
  <p><strong>But When I am Test Web-service at that I am getting following Error..</strong></p>
  <blockquote>
  <p>System.InvalidOperationException: There was an error generating the
  XML document. ---&gt; System.InvalidOperationException: The type
  System.Collections.Generic.List`1[[Country, App_Code.hlnie2jd,
  Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]] may not be
  used in this context.    at
  System.Xml.Serialization.XmlSerializationWriter.WriteTypedPrimitive(String
  name, String ns, Object o, Boolean xsiType)    at
  Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write1_Object(String
  n, String ns, Object o, Boolean isNullable, Boolean needType)    at
  Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write3_anyType(Object
  o)    at
  Microsoft.Xml.Serialization.GeneratedAssembly.ObjectSerializer.Serialize(Object
  objectToSerialize, XmlSerializationWriter writer)    at
  System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter,
  Object o, XmlSerializerNamespaces namespaces, String encodingStyle,
  String id)    --- End of inner exception stack trace ---    at
  System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter,
  Object o, XmlSerializerNamespaces namespaces, String encodingStyle,
  String id)    at
  System.Xml.Serialization.XmlSerializer.Serialize(TextWriter
  textWriter, Object o, XmlSerializerNamespaces namespaces)    at
  System.Xml.Serialization.XmlSerializer.Serialize(TextWriter
  textWriter, Object o)    at
  System.Web.Services.Protocols.XmlReturnWriter.Write(HttpResponse
  response, Stream outputStream, Object returnValue)    at
  System.Web.Services.Protocols.HttpServerProtocol.WriteReturns(Object[]
  returnValues, Stream outputStream)    at
  System.Web.Services.Protocols.WebServiceHandler.WriteReturns(Object[]
  returnValues)    at
  System.Web.Services.Protocols.WebServiceHandler.Invoke()</p>
  </blockquote>
  <p>any one having solution please help me</p>