XmlSchemaSet中的架构验证错误/线程安全? [英] Schema validation error / Thread safety of XmlSchemaSet?

查看:145
本文介绍了XmlSchemaSet中的架构验证错误/线程安全?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下午好



这是XML架构验证片段正在开发/ Q&安培以下的罚款;一个环境,但在高产生产一些奇怪的验证结果。通常的嫌疑人将是该代码是不安全的线程,并且该生产情景的附加负载冲洗掉的错误



的确切的情况如下。认为XML被验证为:

 < MSSQL:spExecute类型=的ResultSet的xmlns:MSSQL =瓮:命名空间> 
< MSSQL:演员>&IPASS LT; / MSSQL:演员>
< MSSQL:连接>的ConnectionString< / MSSQL:连接>
< MSSQL:StoredProcedure的> dbo.RedFox< / MSSQL:StoredProcedure的>
< / MSSQL:spExecute>

在一整天的过程中,各地(的> 2M)300执行将产生以下异常

 
System.Xml.Schema.XmlSchemaValidationException
中的'http://www.w3.org/2000/xmlns/ :MSSQL'属性未声明。



模式验证,似乎抱怨命名空间声明。



的代码结构如下:




  • 有一个静态实例XmlSchemaSet中;

  • XmlSchemaSet中实例的初始化是在一个线程安全的方式正在做;

  • 每个工作线程使用了相同的XmlSchemaSet;

  • 验证的XmlSerializer.Deserialize()调用期间发生,使用一个XmlReader与ValidationType.Schema初始化XmlReaderSettings。



这是什么可能会导致与空间声明呛验证有什么想法?


解决方案

  1. 是你描述一个对照实验的结果,或者
    从生产环境的观察?
    。如果是后者,试图复制其在可控的设置,以确保其他一些
    bug是不是真正的原因。


  2. < A HREF =http://msdn.microsoft.com/en-us/library/system.xml.schema.xmlschemaset.aspx相对=nofollow>有关文档的XmlSchemaSet 说:




    所有实例成员不能保证是线程安全的




    这包括财产读取和只读的方法。
    所以,我们不能假定只读使用的XmlSchemaSet 将被线程安全的。
    ,直到微软提供了实现,明确允许线程之间相同的已编译
    模式代表共享,唯一安全的事情是不共享。


  3. OTOH它似乎是合乎逻辑共享单一的编译一成不变的XmlSchemaSet 来验证
    多个的XmlDocument (或的XmlReader )的实例。
    这是一个非常明智的情景,所以我不明白为什么它没有被明确
    允许和记录



    (更新:显然,这在 Java的标准XML库是明确保障
    为什么不是所以在.NET?)



Good afternoon,

An XML schema validation snippet is working fine on development/q&a environments, but is yielding some odd validation results in Production. The usual suspect would be that the code is unsafe for threading, and that the additional load of the Production scenario is flushing out the error.

The exact scenario is as follows. Consider that the XML being validated is:

<mssql:spExecute type="ResultSet" xmlns:mssql="urn:namespace">
    <mssql:actor>IPASS</mssql:actor>
    <mssql:connection>ConnectionString</mssql:connection>
    <mssql:storedProcedure>dbo.RedFox</mssql:storedProcedure>
</mssql:spExecute>

In the course of a full day, around 300 executions (of >2M) will yield the following exception:

System.Xml.Schema.XmlSchemaValidationException
The 'http://www.w3.org/2000/xmlns/:mssql' attribute is not declared.

The schema validator seems to complain about the namespace declaration.

The code structure is as follows:

  • There is a static instance of XmlSchemaSet;
  • Initialization of the XmlSchemaSet instance is being done in a thread-safe manner;
  • Each worker thread makes use of the same XmlSchemaSet;
  • The validation occurs during an XmlSerializer.Deserialize() call, using an XmlReader with XmlReaderSettings initialized with ValidationType.Schema.

Any thoughts on what might be causing the validation to choke with the namespace declaration?

解决方案

  1. Is what you describe a result of a controlled experiment or an observation from production environment? If the latter, try reproducing it in a controlled setup to make sure some other bug is not a real cause.

  2. The documentation for XmlSchemaSet says:

    "Any instance members are not guaranteed to be thread safe."

    This includes property reads and "read-only" methods. So we cannot assume that read-only use of XmlSchemaSet would be thread safe. Until Microsoft provides implementation that explicitly allows sharing of the same compiled schema representation between threads, the only safe thing to do is not to share.

  3. OTOH it seems logical to share single compiled immutable XmlSchemaSet to validate multiple XmlDocument (or XmlReader) instances. It is a very sensible scenario, so I don't understand why it is not explicitly permitted and documented.

    (Update: Apparently this is explicitly guaranteed in Java's standard XML library. Why isn't it so in .NET?)

这篇关于XmlSchemaSet中的架构验证错误/线程安全?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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