Data Row Type detection when using XSD generated DataSets

こ雲淡風輕ζ 提交于 2019-12-08 07:37:13

问题


I have an XML Schema Definition (XSD) file in Visual Studio 2010. The DataSet Designer generates 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:

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

回答1:


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:

  • #668724 - MSDataSetGenerator generates incorrect output sometimes
  • #733077 - MSDataSetGenerator does not generate TypedTableBase derived classes

It is also addressed in the SO Question:

  • Typed Dataset not using TypedTableBase in .NET 4


来源:https://stackoverflow.com/questions/23661756/data-row-type-detection-when-using-xsd-generated-datasets

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!