使用 XSD.exe 生成 XSD

发布于 2024-08-20 04:01:55 字数 979 浏览 5 评论 0原文

我正在使用 C# 中的 AMO 构建 SSAS 多维数据集。为此,我想要获取服务器、多维数据集、维度等类的公共属性列表。这将是我的超集,用户必须从中提供强制属性,并且可以提供可选属性。

我正在尝试生成 XSD 架构。我运行了以下命令

XSD C:\windows\ assembly\GAC_MSIL\Microsoft.AnalysisServices\10.0.0.0__89845dcd8080cc91\Microsoft.AnalysisServices.DLL /dataset /element:Cube /out:c:\temp\gac

并收到此错误

Error: There was an error processing 'C:\windows\assembly\GAC_MSIL\Microsoft.AnalysisServices\10.0.0.0__89845dcd8080cc91\Microsoft.AnalysisServices.DLL'.
  - There was an error reflecting type 'Microsoft.AnalysisServices.ModelComponent'.
  - Cannot serialize member 'System.ComponentModel.Component.Site' of type 'System.ComponentModel.ISite', see inner exception for more details.
  - Cannot serialize member System.ComponentModel.Component.Site of type System.ComponentModel.ISite because it is an interface.

我该怎么做才能正确生成架构?

I am building SSAS cubes using AMO in c#. For this, I want to get a list of the public properties for the classes for Server, Cube, Dimension, etc. This will be my superset from which the user must provide mandatory properties and may provide the optional ones.

I am trying to generate an XSD schema. I ran the following command

XSD C:\windows\assembly\GAC_MSIL\Microsoft.AnalysisServices\10.0.0.0__89845dcd8080cc91\Microsoft.AnalysisServices.DLL /dataset /element:Cube /out:c:\temp\gac

and got this error

Error: There was an error processing 'C:\windows\assembly\GAC_MSIL\Microsoft.AnalysisServices\10.0.0.0__89845dcd8080cc91\Microsoft.AnalysisServices.DLL'.
  - There was an error reflecting type 'Microsoft.AnalysisServices.ModelComponent'.
  - Cannot serialize member 'System.ComponentModel.Component.Site' of type 'System.ComponentModel.ISite', see inner exception for more details.
  - Cannot serialize member System.ComponentModel.Component.Site of type System.ComponentModel.ISite because it is an interface.

What do I do so that the schema is properly generated?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

注定孤独终老 2024-08-27 04:01:55

解决方案是指示 XSD.exe 跳过有问题的成员(在您的情况下为“System.ComponentModel.Component.Site”)的序列化。
为此,请在导致问题的类成员之前添加以下属性:

[System.Xml.Serialization.XmlIgnore]

The solution is to instruct XSD.exe to skip serialization of your problematic member ('System.ComponentModel.Component.Site' in your case).
To do this add the following attribute before the class member that makes the problem:

[System.Xml.Serialization.XmlIgnore]
月依秋水 2024-08-27 04:01:55

在阅读这个问题时,我想知道一些事情:

  • 为什么有 /dataset 选项。这仅在将 XSD 转换为代码时有用。您似乎正在将(编译的)代码放入 XSD 中。 (数据集与 DTOc 类生成)
  • 为什么有 /element 选项。这仅在将 XSD 转换为代码时有用(子选择要为其生成代码的元素,而不是源模式中的所有元素)

然后,出现问题的原因是该库包含具有公共字段/属性的类型具有接口类型(本例中为 ISite)。

XmlSerializer 无法序列化接口,它需要具体类型。因此你会遇到失败。

目标很明确,但恐怕您将无法使用 XSD.exe 工具。由于您所需的对象(Cube)之一具有 ISite 类型的公共属性,因此这总是会破坏 XMLSerializer。

我猜你最好的选择是 AnalysisServices SDK(也许他们为你提供了这个对象模型)或者...(哎哟)自己使用反射来生成你想要的类型,其中属性字段的子集省略了任何接口类型。

希望这有帮助,

There are a few things i wondered about when reading this question:

  • Why have a /dataset option. This is only usefull when transforming an XSD into Code. You seem to be doing the (compiled)code into XSD. (dataset versus DTOc class generation)
  • Why have a /element option. This is only usefull when transforming an XSD into Code (Sub select the element(s) to generate code for, not all elements in the source schema)

Then, why the problem occurs is that this library contains types, which have public fields/properties with an interface type (ISite in this case).

The XmlSerializer cannot serialize interfaces, it needs concrete types. Hence the failure you are getting.

Goal is clear, but i´m afraid you will not be able to use the XSD.exe tool. Since one of your required objects (Cube) has a public property of the type ISite, this will always break the XMLSerializer.

I´m guessing your best bet is the AnalysisServices SDK (maybe they provide you this object model) or... (ouch) using reflection yourself on the types you want generated with a subset of the properties-fields leaving out any interface type.

Hope this helps,

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文