Data Row Type detection when using XSD generated DataSets
Asked Answered
P

1

1

I have an XML Schema Definition (XSD) file in Visual Studio 2010. The DataSet Designer should generate a strongly typed dataset in the <name>.designer.vb file

Depending on a number of errant factors, it seems to sporadically provide strong typing for enumerable operations (used in LINQ or for each loops)

For instance, sometimes the generated code base is able to detect the type, and sometimes it's not:

Screenshot Code Examples

The offending code seems to be whether or not the generated file has the function:

Public Overridable Function GetEnumerator() As IEnumerator Implements IEnumerable.GetEnumerator
    Return Me.Rows.GetEnumerator
End Function

If it does, then calling the enumerator for the function will return a boring object.
If it doesn't, then the enumerator will return the appropriate type.

My Question:

How can I get it to consistently generate the appropriate behavior?

Our source code doesn't contain generated code, so each developer needs to generate it for themselves. This results in some machines getting compiler errors with improper typing, while others don't... with the same exact source code.

Some things that appear to having something to do with it:

  • Assembly version targeted to .NET 4.0 VS .NET 4.0 Client
  • Whether or not the XSD, designer, or usage files are open during generation
  • Others?

Possible Workarounds:

  • Include strong typing / casting with all declarations
  • Include properly generated file in source control
Proteiform answered 14/5, 2014 at 17:55 Comment(0)
P
0

The Problem:

In short, the problem occurs when the MSDataSetGenerator tool runs, but the System.Data.DataSetExtensions assembly has not yet been loaded into the current Visual Studio process.

The Solution:

One way to load the assembly is just to open any XSD file and THEN re-generate the designer code.

The following steps should generate the appropriate designer file:

  1. Open any XSD file to the designer view (this loads DataSetExtensions.dll)
  2. Right Click on the XSD and Select Run Custom Tool

Here's a full step by step walkthrough with pictures of the issue and solution

Other Instances:

This problem has been reported to Microsoft in the following bug tickets:

It is also addressed in the SO Question:

Proteiform answered 14/5, 2014 at 20:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.