安装.net framework srvice pa后出现xsd codegen问题 [英] Problem with xsd codegen after installing .net framework srvice pa

查看:53
本文介绍了安装.net framework srvice pa后出现xsd codegen问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遵循了优秀的MSDN文章.NET Framework中的代码生成

使用XML Schema [1]构建有限xsd.exe的替代品。我的代码

在.NET framework 1.1下工作正常,但是在安装.net框架之后

service pack 1,我的代码断了。


以下是显示问题的简单示例文件:


XSD文件aaa.xsd

------------- ---------

<?xml version =" 1.0" encoding =" UTF-8"?>


< schema targetNamespace =" urn:ietf:params:xml:ns:aaa"

xmlns:aaa =" urn:ietf:params:xml:ns:aaa"

xmlns =" http://www.w3.org/2001/XMLSchema"

elementFormDefault =" qualified">


< complexType name =" aaa">

< / complexType>


< / schema>


XSD FILE bbb.xsd

------------ ----------

<?xml version =" 1.0" encoding =" UTF-8"?>


< schema targetNamespace =" urn:ietf:params:xml:ns:bbb"

xmlns:bbb =" urn:ietf:params:xml:ns:bbb"

xmlns:aaa =" urn:ietf:params:xml:ns:aaa"

xmlns =" http://www.w3.org/2001/XMLSchema"

elementFormDefault =" qualified">


< import namespace =" urn:ietf:params:xml:ns:aaa"

schemaLocation =" aaa.xsd" />


< element name =" test" />


< / schema>

这是我用来处理上述模式文件的代码(从上面提到的MSDN文章[1]中获取了几乎排队的行,但是增加了读取多个xsd文件的功能:

):


xsdCodeGen.cs

----------------------

string [ ] xsdFiles = {" aaa.xsd"," bbb.xsd" };

XmlSchemas架构=新的XmlSchemas();


//加载XmlSchema及其集合

foreach(string filename在xsdFiles中)

{

XmlSchema xsd;

使用(FileStream fs = new FileStream(filename,FileMode.Open,

FileAccess.Read))

{

xsd = XmlSchema.Read(fs,null);

xsd.Compile(null) ;

}

schemas.Add(xsd);

}


//创建这些模式的导入器

XmlSchemaImporter importer = new XmlSchemaImporter(模式);

// XmlCodeExporter的System.CodeDom命名空间将类放入

CodeNamespace ns = new CodeNamespace(" testNamespace");

XmlCodeExporter exporter = new XmlCodeExporter(ns);


//迭代架构top -level元素和导出代码每个

foreach(模式中的XmlSchema xsd)

{

foreach(xsd.Elements.V中的XmlSchemaElement元素) alues)

{

//导入映射,并导出代码

XmlTypeMapping mapping = importer.ImportTypeMapping(element.QualifiedName);

exporter.ExportTypeMapping(mapping);

}

}

以上代码可以正常使用pre-service pack,但是post-service打包行:


XmlTypeMapping mapping = importer.ImportTypeMapping(element.QualifiedName);


将抛出以下异常:


例外:数据类型''urn:ietf:params:xml:ns:bbb:aaa''缺失。

任何想法为什么不同的行为售前和售后服务包以及

如何解决?


非常感谢提前,


Ceri Williams


[1]
http://msdn.microsoft.com/XML/Buildi...xsdcodegen.asp

I followed the excellent MSDN article "Code Generation in the .NET Framework
Using XML Schema" [1] to build a substitute for the limited xsd.exe. My code
works fine under .NET framework 1.1, but after installing .net framework
service pack 1, my code breaks.

Below are trivial example files that demonstrate the problem:

XSD FILE aaa.xsd
----------------------
<?xml version="1.0" encoding="UTF-8"?>

<schema targetNamespace="urn:ietf:params:xml:ns:aaa"
xmlns:aaa="urn:ietf:params:xml:ns:aaa"
xmlns="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">

<complexType name="aaa">
</complexType>

</schema>

XSD FILE bbb.xsd
----------------------
<?xml version="1.0" encoding="UTF-8"?>

<schema targetNamespace="urn:ietf:params:xml:ns:bbb"
xmlns:bbb="urn:ietf:params:xml:ns:bbb"
xmlns:aaa="urn:ietf:params:xml:ns:aaa"
xmlns="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">

<import namespace="urn:ietf:params:xml:ns:aaa"
schemaLocation="aaa.xsd"/>

<element name="test"/>

</schema>
And here is the code which I use to process the above schema files (taken
almost line for line from the MSDN article mentioned above [1], but with the
addition of the ability to read multiple xsd files):

xsdCodeGen.cs
----------------------
string[] xsdFiles = { "aaa.xsd", "bbb.xsd" };
XmlSchemas schemas = new XmlSchemas();

// Load the XmlSchema and its collection
foreach(string filename in xsdFiles)
{
XmlSchema xsd;
using(FileStream fs = new FileStream(filename, FileMode.Open,
FileAccess.Read))
{
xsd = XmlSchema.Read(fs, null);
xsd.Compile(null);
}
schemas.Add(xsd);
}

// Create the importer for these schemas
XmlSchemaImporter importer = new XmlSchemaImporter(schemas);

// System.CodeDom namespace for the XmlCodeExporter to put classes in
CodeNamespace ns = new CodeNamespace("testNamespace");
XmlCodeExporter exporter = new XmlCodeExporter(ns);

// Iterate schema top-level elements and export code for each
foreach(XmlSchema xsd in schemas)
{
foreach (XmlSchemaElement element in xsd.Elements.Values)
{
// Import the mapping, and export the code
XmlTypeMapping mapping = importer.ImportTypeMapping(element.QualifiedName);
exporter.ExportTypeMapping(mapping);
}
}
The above code works fine pre- service pack, but post- service pack the line:

XmlTypeMapping mapping = importer.ImportTypeMapping(element.QualifiedName);

will throw the following exception:

Exception: The datatype ''urn:ietf:params:xml:ns:bbb:aaa'' is missing.
Any ideas why the different behaviour pre- and post- service pack, and how
to fix?

Many thanks in advance,

Ceri Williams

[1]
http://msdn.microsoft.com/XML/Buildi...xsdcodegen.asp

推荐答案

您好Ceri,

首先,我想确认一下我对您的问题的理解。从

您的描述中,我了解到当您安装.net框架时

ImportTypeMapping会抛出一个异常,表示缺少数据类型。如果

有任何误解,请随时告诉我。


感谢您提供我正在使用的代码。我已经在我的

机器上试过了,我已经安装了.net framework 1.1 sp1。

但是,我无法重现它。它在我的计算机上工作正常,没有任何

例外。你可以在另一台电脑上试试这个代码是否有效吗?


Kevin Yu

=======

提供此帖子按原样提供没有保证,也没有赋予

权利。

Hi Ceri,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that when you have .net framework installed
ImportTypeMapping throws an exception which says a datatype is missing. If
there is any misunderstanding, please feel free to let me know.

Thanks for providing me with the code you''re using. I have tried it on my
machine, which I have .net framework 1.1 sp1 installed on it already.
However, I could not reproduce it. It works fine on my computer without any
exceptions. Could you try this code on another computer to see if it works?

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."


嗨凯文,


只是为了确认:


我从头开始构建一台机器,Windows XP Professional,Visual Studio .NET

2003,.NET framework 1.1。编译并运行我之前提供的代码示例

,一切正常。


然后我安装.NET framework 1.1 Service Pack 1 [1]。我重建了

代码,编译得很好,但这次我得到运行时异常:

"数据类型''urn:ietf:params:xml:ns:bbb :aaa''缺失。


我没有做任何有趣的事情,没有安装任何东西

其他,我设置了它纯粹是为了测试我的示例代码。


干杯,

Ceri


[1] http://msdn.microsoft.com/netframewo...s/default.aspx

Kevin Yu [MSFT]"写道:
Hi Kevin,

Just to confirm:

I built a machine from scratch, Windows XP Professional, Visual Studio .NET
2003, .NET framework 1.1. Compiling and running the code sample I gave
earlier, everything works fine.

I then install the .NET framework 1.1 Service Pack 1 [1]. I rebuild the
code, compiles fine, but this time I get the runtime exception:
"The datatype ''urn:ietf:params:xml:ns:bbb:aaa'' is missing."

I''ve done nothing else interesting to that machine, not installed anything
else, I set it up purely to test my example code.

Cheers,
Ceri

[1] http://msdn.microsoft.com/netframewo...s/default.aspx
"Kevin Yu [MSFT]" wrote:
嗨Ceri,

首先,我想确认一下我对你的问题的理解。从您的描述中,我了解到当您安装.net框架时
ImportTypeMapping会抛出一个异常,表示缺少数据类型。如果有任何误解,请随时告诉我。

感谢您提供我正在使用的代码。我已经在我的
机器上试过了,我已经安装了.net framework 1.1 sp1。
但是,我无法重现它。它在我的计算机上工作正常,没有任何例外。您是否可以在另一台计算机上试用此代码以查看它是否有效?

Kevin Yu
=======
此帖子是按原样提供的没有保证,也没有授予
权利。
Hi Ceri,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that when you have .net framework installed
ImportTypeMapping throws an exception which says a datatype is missing. If
there is any misunderstanding, please feel free to let me know.

Thanks for providing me with the code you''re using. I have tried it on my
machine, which I have .net framework 1.1 sp1 installed on it already.
However, I could not reproduce it. It works fine on my computer without any
exceptions. Could you try this code on another computer to see if it works?

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."



Hi Ceri,


感谢您的确认。为了避免粗心大意,我又试了一次。我在新计算机上设置了

并按照您提供的步骤进行操作。然后用你第一篇文章中的代码尝试了

。但是,这次我没有复制它




这里我附上了一个带有编译过的exe文件的zip文件。请尝试

运行它以查看表格是否可以毫无例外地显示。


Kevin Yu

=== ====

此帖子已提供按现状没有保证,也没有赋予

权利。

Hi Ceri,

Thanks for your comfirming. To avoid carelessness, I tried it again. I set
up a new computer and followed the steps you have provided. And then tried
with the code in your first post. However, I didn''t reproduced it either
this time.

Here I have attached a zip file with a compiled exe file inside. Please try
to run it to see if the Form can be displayed without any exception.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."


这篇关于安装.net framework srvice pa后出现xsd codegen问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆