Microsoft KB Archive/815251

= You receive a &quot;Unable to generate a serializer&quot; error message when you drag a user control onto a form =

Article ID: 815251

Article Last Modified on 5/12/2007

-

APPLIES TO


 * Microsoft Visual Studio .NET 2002 Academic Edition
 * Microsoft Visual Studio .NET 2002 Enterprise Architect
 * Microsoft Visual Studio .NET 2002 Enterprise Developer
 * 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  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 &quot;Symptoms&quot; 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).



Steps to Reproduce the Behavior
 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. Click to select TestWebService Project. On the File menu, click Add New Item. Click to select DataSet, and then click Open.

By default, Dataset1 is added to the project. On the View menu, click Server Explorer.</li> In Server Explorer, right-click Data Connections, and then click Add Connection.</li> Type the SQL Server name in the Select or enter a server name combo box. Type the   and   in the corresponding text box.</li> Click to select Northwind from the Select the database on the server list, and then click OK.</li> Drag the Customers table of the Northwind database from Server Explorer onto Dataset1.</li> In Solution Explorer, right-click the Service1.asmx file, and then click View Code.</li>  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(&quot;WebMethod1&quot;) End Sub Visual C# .NET Sample Code [WebMethod] public void WebMethod1(DataSet1 ds) {  Console.WriteLine(&quot;WebMethod1&quot;); } </li> Save and build the project.</li> 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.</li> In Solution Explorer, right-click TestUserControl, and then click Add Web Reference.</li> Add a Web Reference to TestWebService.</li>  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; </li> Save and build the project.</li> On the File menu, point to Add Project, and then click New Project.</li> Create a new Windows Application project named TestApplication by using Visual Basic .NET or Visual C# .NET.</li> On the Tools menu, click Customize Toolbox.</li> <li>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.</li> <li>Drag UserControl1 onto Form1.

You recieve the error message mentioned in the &quot;Symptoms&quot; section of this article.</li></ol>

<div class="references_section">