[英]DTD validation in a 3.5 assembly fails when linked in an application targeting 4.6
I have an assembly written in c# that does DTD validation on an input string. 我有一个用c#编写的程序集,它对输入字符串进行DTD验证。 It uses XMLReaderSettings.ValidationTpe = ValidationType.DTD and XMLReaderSettings.ProhibitDtd = false.
它使用XMLReaderSettings.ValidationTpe = ValidationType.DTD和XMLReaderSettings.ProhibitDtd = false。 XML validation works fine when linking this assembly in applications that target 2.0, 3.5, 4.0, 4.5 but when the application targets 4.6 it no longer works (DTD processing becomes prohibited).
在目标为2.0、3.5、4.0、4.5的应用程序中链接此程序集时,XML验证可以正常工作,但是在目标为4.6的应用程序中,XML验证不再起作用(禁止进行DDT处理)。 I know that ProhibitDtd is deprecated in 4.0 in favor of DtdProcessing = DtdProcessing.Parse.
我知道ProhibitDtd在4.0中已弃用,而推荐使用DtdProcessing = DtdProcessing.Parse。
I can't use DtdProcessing.Parse unless I target 4.0 for my assembly. 除非我将程序集目标为4.0,否则不能使用DtdProcessing.Parse。 My questions are: 1. How can I continue to target 3.5 and get it to work in applications targeting 4.6 and higher?
我的问题是:1.如何继续以3.5为目标并使其在以4.6及更高版本为目标的应用程序中工作? 2. If I have to target 4.0 to make it work, how will that affect an application that targets 2.0 using my 4.0 assembly?
2.如果必须以4.0为目标,那么它将如何影响使用4.0程序集针对2.0的应用程序?
I have solved this problem. 我已经解决了这个问题。 I am now able to continue to target 3.5 with my assembly and when it is linked into an application targeting 4.6 and above it still is able to validate XML with DTDs.
现在,我可以继续以我的程序集为目标3.5,并将其链接到目标为4.6及更高版本的应用程序时,它仍然能够使用DTD验证XML。
I had to explicitly set the XmlReaderSettings.XmlResolver to a new XmlUrlResolver() to get it to work. 我必须将XmlReaderSettings.XmlResolver显式设置为新的XmlUrlResolver()才能使其正常工作。 I guess without setting this to a new XmlUrlResolver() the 4.6 framework sets it at runtime with a resolver that will not allow DTD validation.
我想如果不将其设置为新的XmlUrlResolver(),4.6框架会在运行时使用不允许DTD验证的解析器对其进行设置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.