Bug with namespaces in XSD.EXE /dataset (C#)

M

Marc Durdin

I have come across an issue with XSD.exe code generation (in /dataset mode,
version 2.0.50727.1432), relating to namespaces. Specifically, certain types
are not always consistently prefixed with global::, so if you have a
namespace with the name System, the generated code will fail to compile.

The issue can occur specifically in two lines of the generated code, first
in the Add*Row function:

public SomeTableRow AddSomeTableRow(System.DateTime SomeDateTimeField) {

Which should be:

public SomeTableRow AddSomeTableRow(global::System.DateTime
SomeDateTimeField) {

And in the property get/set for any datetime field:

public System.DateTime SomeDateTimeField {

Which should be:

public global::System.DateTime SomeDateTimeField {

WORKAROUND

Don't use a namespace called System. We came across this because we are
generating database class libraries for a legacy system which included a
"system" 'namespace' in the data objects...

ISSUE REPRODUCTION

To reproduce this issue, take the following sample XSD:

<?xml version="1.0" standalone="yes"?>
<xs:schema id="DateTimeBug" xmlns=""
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="DateTimeBugDataSet" msdata:IsDataSet="true"
msdata:UseCurrentLocale="true" msdata:EnforceConstraints="False">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="DateTimeBug">
<xs:complexType>
<xs:sequence>
<xs:element name="DateTimeField" type="xs:dateTime"
minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>

Generate a C# file with XSD:
xsd /dataset /n:MyCompany.Data.DateTimeBuggy datetimebug.xsd

Include the following namespace in second C# file:

namespace MyCompany.Data.System { };

Compile a project with these two C# files. It will fail with the error "The
type or namespace name 'DateTime' does not exist in the namespace
'MyCompany.Data.System' (are you missing an assembly reference?)"

(originally misposted to microsoft.public.data.ado ... oops)
 
W

WenYuan Wang [MSFT]

Hello Marc,
Thanks for your posting.

I reproduced this issue on my side. VS IDE throw the error message
"'DataTime' doesn't exist in 'MyCompany.DataSystem' namespace" when
compiling. I agree with you. It seems XSD.exe forget to add prefix global::
for System.DataTime. We need perform further research. I will update here
as soon as possible. If you have any more concern, please also feel free to
post here.

Thanks again for your understanding.
Best regards,

Wen Yuan
Microsoft Online Community Support
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
W

WenYuan Wang [MSFT]

Hello Marc,
Thanks for your waiting.

I have logged this issue in our DB for Visual Studio product team to
investigate.
The issue is that XSD.exe doesn't generate prefix "global::" for
System.DataTime. Thereby, project will failed to be compiled, due to
namespace conflict. The workaround is not use a namespace called System in
your project. Another way is to specify the prefix "global::" for
System.DataTime type manually. Thanks again for your post. This will
benefit our product quality improvement very much.

But I'm afraid this issue may not be fixed very soon.
For urgent issues, we can contact Microsoft CSS directly.
If the problem is confirmed to be a product bug, the case charge will be
free.
You can check http://support.microsoft.com for regional support phone
numbers.

You can also post the issue to our Connect feedback portal. Our developer
will evaluate them seriously and communicate with you directly on the issue
there.
http://connect.microsoft.com/VisualStudio/

Improving the quality of our products and services is a never ending
process for Microsoft.
Please also feel free to let me know if you have any more concern on this
issue. It's my pleasure to assist you.

Have a great day,
Best regards,

Wen Yuan
Microsoft Online Community Support
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
M

Marc Durdin

Thank you. We have gone ahead and worked around the issue by special-casing
our MyCompany.Data.System namespace!

Glad to be of assistance in improving product quality - and equally glad to
see Microsoft's responsiveness here.

Regards,

Marc
 
W

WenYuan Wang [MSFT]

The pleasure is all mine.
Thanks for your understanding, Marc. :)

Have a great day,
Best regards,

Wen Yuan
Microsoft Online Community Support
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top