title: How to return list<dynamic> from webservice
body: <p>I have a function returning dynamic list and I want to return it back. Is this possible?</p>
  
  <p>My function is as</p>
  
  <pre><code>   public List&lt;dynamic&gt; GiveMeProjects(int id)
          {
              Entities.VSTMEntities vstm = new Entities.VSTMEntities();
              var currentUserProject = (from users in vstm.Users
                                        from project in users.Projects
                                        where users.UserID == id
                                        select new
                                        {
                                            Id = project.ProjectID,
                                            Name = project.ProjectName
                                        }).ToList&lt;dynamic&gt;();
  
              return currentUserProject;
          }
  </code></pre>
  
  <p>and calling it as</p>
  
  <pre><code>  [WebMethod()]
    public List&lt;dynamic&gt; GiveMeProjects(string id)
    {
       int pId = Convert.ToInt32(id);
       return projectItems.GiveMeProjects(pId);
     }
  </code></pre>
  
  <p>When I am testing the service, this function is  generating exception </p>
  
  <p><code>There was an error generating the XML document. ---&gt; System.InvalidOperationException: f__AnonymousType102[System.Int32,System.String] cannot be serialized because it does not have a parameterless constructor.
     at System.Xml.Serialization.TypeDesc.CheckSupported()
     at System.Xml.Serialization.TypeScope.GetTypeDesc(Type type, MemberInfo source, Boolean directReference, Boolean throwOnError)
     at System.Xml.Serialization.XmlSerializationWriter.CreateUnknownTypeException(Type type)
     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.Write9_ArrayOfAnyType(Object o)
     at Microsoft.Xml.Serialization.GeneratedAssembly.ListOfObjectSerializer.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.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()</code></p>
  
  <p>How to resolve this issue</p>