使用 XSD.exe 生成 XSD
我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
解决方案是指示 XSD.exe 跳过有问题的成员(在您的情况下为“System.ComponentModel.Component.Site”)的序列化。
为此,请在导致问题的类成员之前添加以下属性:
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:
在阅读这个问题时,我想知道一些事情:
然后,出现问题的原因是该库包含具有公共字段/属性的类型具有接口类型(本例中为 ISite)。
XmlSerializer 无法序列化接口,它需要具体类型。因此你会遇到失败。
目标很明确,但恐怕您将无法使用 XSD.exe 工具。由于您所需的对象(Cube)之一具有 ISite 类型的公共属性,因此这总是会破坏 XMLSerializer。
我猜你最好的选择是 AnalysisServices SDK(也许他们为你提供了这个对象模型)或者...(哎哟)自己使用反射来生成你想要的类型,其中属性字段的子集省略了任何接口类型。
希望这有帮助,
There are a few things i wondered about when reading this question:
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,