You receive a "Unable to generate a serializer" error message when you drag a user control onto a form (815251)



The information in this article applies to:

  • Microsoft Visual Studio .NET (2002), Academic Edition
  • Microsoft Visual Studio .NET (2002), Enterprise Architect Edition
  • Microsoft Visual Studio .NET (2002), Enterprise Developer Edition
  • Microsoft Visual Studio .NET (2002), Professional Edition

SYMPTOMS

In Microsoft Visual Studio .NET, when you drag a user control onto a form, and the user control consumes a Web service with a Web Service method that has a Typed DataSet as a parameter or as a return type, you receive the following error:
Unable to generate a serializer for type UserControlName.WebServerName.DataSetName from assembly <Unknown> because the assembly may be dynamic. Save the assembly and load it from disk to use it with XmlSerialization.
You receive the error only if the user control instantiates the Web service when you drag the user control onto the form.

CAUSE

To use Typed DataSets, the XML Serializer must have additional serialization information about the Typed DataSets schema. When you create a Web service with a Web Service method, and you have a Typed DataSet as a parameter or as a return type, the serialization information is built into the Web service. When you add a Web Reference to this Web service in a user control project, the serialization information is built into the auto-generated Web Service Proxy file. However, when the user control is added to the toolbox in a project, the project has no reference to the Proxy file. Therefore, Visual Studio .NET cannot obtain the serialization information for the Typed DataSet. Without this serialization information, you receive the error mentioned in the "Symptoms" section of this article.

WORKAROUND

To work around this bug, follow these steps:
  1. In the Windows Application project, click to select the UserControlName.dll assembly under References, and then press the F4 key to display the properties.
  2. Click to select the Copy Local property, and then set the value to False.
  3. Drag the user control onto the form.

    You do not receive an error message.

STATUS

Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article. This bug was corrected in Microsoft Visual Studio .NET (2003).

MORE INFORMATION

Steps to Reproduce the Behavior

  1. Open Visual Studio .NET (2002), and then create a new ASP.NET Web Service project named TestWebService by using Microsoft Visual Basic .NET or Microsoft Visual C# .NET.
  2. Click to select TestWebService Project.
  3. On the File menu, click Add New Item.
  4. Click to select DataSet, and then click Open.

    By default, Dataset1 is added to the project.
  5. On the View menu, click Server Explorer.
  6. In Server Explorer, right-click Data Connections, and then click Add Connection.
  7. Type the SQL Server name in the Select or enter a server name combo box. Type the user name and Password in the corresponding text box.
  8. Click to select Northwind from the Select the database on the server list, and then click OK.
  9. Drag the Customers table of the Northwind database from Server Explorer onto Dataset1.
  10. In Solution Explorer, right-click the Service1.asmx file, and then click View Code.
  11. Append the following code at the end of the class definition:

    Visual Basic .NET Sample Code
    <WebMethod()> Public Sub WebMethod1(ByVal ds1 As Dataset1)
       Console.WriteLine("WebMethod1")
    End Sub
    Visual C# .NET Sample Code
    [WebMethod]
    public void WebMethod1(DataSet1 ds)
    {
       Console.WriteLine("WebMethod1");
    }
  12. Save and build the project.
  13. On the File menu, point to Add Project, click New Project, and then create a new Windows Control Library project named TestUserControl by using Visual Basic .NET or Visual C# .NET.

    By default, UserControl1 is created.
  14. In Solution Explorer, right-click TestUserControl, and then click Add Web Reference.
  15. Add a Web Reference to TestWebService.
  16. Append the following code in the UserControl1_Load event handler:

    Visual Basic .NET Sample Code
    Dim TestService As New localhost.Service1()
    Visual C# .NET Sample Code
    localhost.Service1 TestService = new localhost.Service1();
  17. Save and build the project.
  18. On the File menu, point to Add Project, and then click New Project.
  19. Create a new Windows Application project named TestApplication by using Visual Basic .NET or Visual C# .NET.
  20. On the Tools menu, click Customize Toolbox.
  21. Click the .NET Framework Components tab, and then click Browse. Locate TestUserControl.dll, click Open, and then click OK on the Add Reference page.

    Dataset1, Service1 and UserControl1 are added to the toolbox.
  22. Drag UserControl1 onto Form1.

    You recieve the error message mentioned in the "Symptoms" section of this article.

REFERENCES

For additional information, visit the following Microsoft Web sites: For additional information, click the following article numbers to view the articles in the Microsoft Knowledge Base:

313486 INFO: Roadmap for Visual Database Tools and Typed DataSets

315678 HOW TO: Create and Use a Typed DataSet by Using Visual Basic .NET

320714 HOW TO: Create and Use a Typed DataSet by Using Visual C# .NET


Modification Type:MajorLast Reviewed:1/23/2006
Keywords:kbvs2005swept kbvs2005doesnotapply kbide kbDragDrop kbfix kbControl kbWebServices KB815251 kbAudDeveloper