I have an XML Schema Definition (XSD) file in Visual Studio 2010. The DataSet Designer should generate a strongly typed dataset in the <code><i><name></i>.designer.vb</code> 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:

<!-- language: lang-vb -->
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

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: