<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Ali Pasha's WebLog... : types</title><link>http://blogs.msdn.com/a_pasha/archive/tags/types/default.aspx</link><description>Tags: types</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Visual Basic Issue with Types that are generated using svcutil.exe (WCF)</title><link>http://blogs.msdn.com/a_pasha/archive/2006/12/21/types-are-unitialized-if-using-visual-basic-wcf.aspx</link><pubDate>Thu, 21 Dec 2006 22:30:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1341933</guid><dc:creator>a_pasha</dc:creator><slash:comments>2</slash:comments><comments>http://blogs.msdn.com/a_pasha/comments/1341933.aspx</comments><wfw:commentRss>http://blogs.msdn.com/a_pasha/commentrss.aspx?PostID=1341933</wfw:commentRss><description>&lt;P&gt;&lt;SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman','serif'; mso-ansi-language: EN-US; mso-fareast-font-family: Calibri; mso-bidi-language: AR-SA; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin"&gt;If you generate a WCF VB proxy that contains a DataContract type using &lt;A class="" href="http://msdn2.microsoft.com/en-us/library/ms717328.aspx" mce_href="http://msdn2.microsoft.com/en-us/library/ms717328.aspx"&gt;svcutil.exe&lt;/A&gt;, calling a method that returns the type will always incorrectly return an uninitialized type. This works correctly for C#.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman','serif'; mso-ansi-language: EN-US; mso-fareast-font-family: Calibri; mso-bidi-language: AR-SA; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman','serif'; mso-ansi-language: EN-US; mso-fareast-font-family: Calibri; mso-bidi-language: AR-SA; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin"&gt;John Stallo, a peer of mine,&amp;nbsp;spent some time investigating this issue. Here's the resolution:&lt;/SPAN&gt;&lt;/P&gt;&lt;SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman','serif'; mso-ansi-language: EN-US; mso-fareast-font-family: Calibri; mso-bidi-language: AR-SA; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin"&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 11pt; COLOR: #1f497d; FONT-FAMILY: 'Calibri','sans-serif'"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;The problem is a &lt;/SPAN&gt;namespace mismatch issue that involves the /Rootnamespace compiler switch (on by default in VB projects).&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 11pt; COLOR: #1f497d; FONT-FAMILY: 'Calibri','sans-serif'"&gt;&lt;SPAN style="FONT-SIZE: 11pt; COLOR: #1f497d; FONT-FAMILY: 'Calibri','sans-serif'"&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 11pt; COLOR: #1f497d; FONT-FAMILY: 'Calibri','sans-serif'"&gt;&lt;SPAN style="FONT-SIZE: 11pt; COLOR: #1f497d; FONT-FAMILY: 'Calibri','sans-serif'"&gt;The important line of code that svcutil generates with this switch is an explicit namespace argument for DataContractAttribute. (This information is usually pulled from the service’s WSDL – the namespace below is the default one that’s generated if a namespace isn’t explicitly specified on the data contract on the server side):&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 11pt; COLOR: #1f497d; FONT-FAMILY: 'Calibri','sans-serif'"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&lt;FONT color=#000000&gt;System.Runtime.Serialization.DataContractAttribute(&lt;/FONT&gt;&lt;SPAN style="BACKGROUND: yellow; mso-highlight: yellow"&gt;&lt;FONT color=#000000&gt;[Namespace]:=&lt;/FONT&gt;&lt;SPAN style="COLOR: #a31515"&gt;"&lt;A href="http://schemas.datacontract.org/2004/07/" mce_href="http://schemas.datacontract.org/2004/07/"&gt;&lt;FONT color=#0000ff&gt;http://schemas.datacontract.org/2004/07/&lt;/FONT&gt;&lt;/A&gt;"&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;FONT color=#000000&gt;)&amp;gt;&amp;nbsp; _&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&lt;FONT color=#000000&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&lt;SPAN style="COLOR: blue"&gt;Partial&lt;/SPAN&gt;&lt;FONT color=#000000&gt; &lt;/FONT&gt;&lt;SPAN style="COLOR: blue"&gt;Public&lt;/SPAN&gt;&lt;FONT color=#000000&gt; &lt;/FONT&gt;&lt;SPAN style="COLOR: blue"&gt;Class&lt;/SPAN&gt;&lt;FONT color=#000000&gt; DataContract1&lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 11pt; COLOR: #1f497d; FONT-FAMILY: 'Calibri','sans-serif'"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 11pt; COLOR: #1f497d; FONT-FAMILY: 'Calibri','sans-serif'"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 11pt; COLOR: #1f497d; FONT-FAMILY: 'Calibri','sans-serif'"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 11pt; COLOR: #1f497d; FONT-FAMILY: 'Calibri','sans-serif'"&gt;Apparently svcutil.exe doesn’t generate the explicit namespace argument by default.&amp;nbsp; So when the generated proxy is added to a VB project, the Data Contract type now falls under the VB project’s root namespace (e.g. &lt;B&gt;ConsoleApplication1.&lt;/B&gt;DataContract1).&amp;nbsp; Without the explicit namespace argument, WCF has trouble finding the Data Contract type at runtime because the project’s root namespace throws a spanner in the works, which is why you then end up with uninitialized fields.&amp;nbsp; This doesn’t repro with C# because C# projects don’t have an implied root namespace.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt; 
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;/o:p&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;B&gt;&lt;SPAN style="FONT-SIZE: 11pt; COLOR: #1f497d; FONT-FAMILY: 'Calibri','sans-serif'"&gt;Workaround&lt;/SPAN&gt;&lt;/B&gt;&lt;SPAN style="FONT-SIZE: 11pt; COLOR: #1f497d; FONT-FAMILY: 'Calibri','sans-serif'"&gt;: &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 11pt; COLOR: #1f497d; FONT-FAMILY: 'Calibri','sans-serif'"&gt;Run svcutil with the following switch: &lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 11pt; COLOR: #00b050; FONT-FAMILY: 'Courier New'"&gt;/namespace:*,MyNamespace&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 11pt; COLOR: #00b050; FONT-FAMILY: 'Calibri','sans-serif'"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 11pt; COLOR: #1f497d; FONT-FAMILY: 'Calibri','sans-serif'"&gt;…where “MyNamespace” is the namespace of your choosing that you want the proxy to be generated in.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/SPAN&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman','serif'; mso-ansi-language: EN-US; mso-fareast-font-family: Calibri; mso-bidi-language: AR-SA; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin"&gt;Note that this will not be an issue with the Service Reference feature that will be available in the Feburary CTP of Visual Studio Orcas.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman','serif'; mso-ansi-language: EN-US; mso-fareast-font-family: Calibri; mso-bidi-language: AR-SA; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin"&gt;Cheers,&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman','serif'; mso-ansi-language: EN-US; mso-fareast-font-family: Calibri; mso-bidi-language: AR-SA; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin"&gt;Ali&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman','serif'; mso-ansi-language: EN-US; mso-fareast-font-family: Calibri; mso-bidi-language: AR-SA; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin"&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=1341933" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/a_pasha/archive/tags/default/default.aspx">default</category><category domain="http://blogs.msdn.com/a_pasha/archive/tags/initialize/default.aspx">initialize</category><category domain="http://blogs.msdn.com/a_pasha/archive/tags/types/default.aspx">types</category><category domain="http://blogs.msdn.com/a_pasha/archive/tags/WCF/default.aspx">WCF</category></item></channel></rss>