为什么Blazor应用程序中的XML验证在本地主机和Azure静态Web应用程序中提供不同的消息? [英] Why is XML validation in a Blazor application giving different messages on localhost and as an Azure Static Web App?
问题描述
编辑 我在 https://github.com/GilShalit/XMLValidation
我正在Blazor WebAssembly(TargetFramework = net5.0)中构建XML编辑器.该功能的一部分涉及验证XML的完整性,并根据具有三个包含项的复杂xsd模式进行验证.
I am building an XML editor in Blazor WebAssembly (TargetFramework=net5.0). Part of the functionality involves validating the XML for completeness and according to a complex xsd schema with three includes.
这些是我要执行的步骤:
These are the steps I follow:
- 通过为每个xsd调用以下方法来构建XmlSchemaSet并向其中添加4个架构:
private async Task loadSchema(string path, string nameSpace)
{
byte[] byteArrayS = await _client.GetByteArrayAsync(path);
Console.WriteLine($"{path}: {byteArrayS.Length}");
MemoryStream streamS = new MemoryStream(byteArrayS);
XmlReader xmlSchemaReader = XmlReader.Create(streamS);
schemaSet.Add(nameSpace, xmlSchemaReader);
}
- 使用以下方法初始化事件处理程序:
ValidationEventHandler eventHandler = new ValidationEventHandler(ValidationEventHandler);
- 将XML加载到XmlDocument中:
byte[] byteArrayX = Encoding.ASCII.GetBytes(await _editorTarget.GetValue());
MemoryStream streamX = new MemoryStream(byteArrayX);
XmlReader reader = XmlReader.Create(streamX);
XmlDocument document = new XmlDocument();
document.Load(reader);
- 根据schemaSet进行验证:
document.Schemas = schemaSet;
document.Validate(eventHandler);
第3步和第4步在Try ... Catch块中运行,并且当XML格式不正确(例如缺少结束标记)时在本地运行, document.Load(reader);
行会产生错误,并显示以下消息:
ssteps 3 and 4 are run inside a Try...Catch block and running locally when the XML is not well formed (missing closing tag for example), the document.Load(reader);
line produces an error with a message like the following:
The 'publicationStmt1' start tag on line 9 position 11 does not match the end tag of 'publicationStmt'. Line 11, position 12.
太好了.但是,在部署到Azure的应用程序中验证类似情况会产生以下错误消息: Xml_MessageWithErrorPosition,Xml_TagMismatchEx,11、12
.
which is great. But validating a similar situation in the application deployed to Azure produces the following error message:Xml_MessageWithErrorPosition, Xml_TagMismatchEx, 11, 12
.
Schema验证错误,并且典型的消息是:
Schema validation errors are caught in the event handler when the line document.Validate(eventHandler);
is run and a typical message is:
The element 'fileDesc' in namespace 'http://www.tei-c.org/ns/1.0' has invalid child element 'publicationStmt1' in namespace 'http://www.tei-c.org/ns/1.0'. List of possible elements expected: 'editionStmt, extent, publicationStmt' in namespace 'http://www.tei-c.org/ns/1.0'.
但是在Azure上运行时,消息为 Sch_InvalidElementContentExpecting
.
But when run on Azure the message is Sch_InvalidElementContentExpecting
.
在本地运行和在Azure中运行时,验证结果出现这种差异的原因是什么?
我尝试通过添加以下内容来禁用链接:
I tried to disable linking by adding:
<ItemGroup>
<BlazorLinkerDescriptor Include="LinkerConfig.xml" />
</ItemGroup>
但这对已部署的应用程序没有影响,并且使用Release而不是Debug在本地运行也没有任何改变.
But that did not make a difference in the deployed application, and running locally with Release instead of Debug did not change anything either.
我还确保从Azure运行时确实加载了4个xsd文件.
I also made sure the 4 xsd files are actually loaded when running from Azure.
推荐答案
所以这不是错误,而是功能...
So this was a feature not a bug...
问题我在dot社区/运行时团队中提取了在Dev社区上打开的内容,并将其添加到GitHub问题跟踪器此处.
An issue I opened on Dev community was picked up by the dotnet/runtime team and added to the GitHub issue tracker here.
事实证明,删除了异常消息以节省大小.
It turns out exception messages are removed to save on size.
使用< UseSystemResourceKeys> false</UseSystemResourceKeys>
启用异常消息,我必须说我没有看到大小增加.
Using <UseSystemResourceKeys>false</UseSystemResourceKeys>
enables exception messages and I must say I am not seeing an increase in size.
这篇关于为什么Blazor应用程序中的XML验证在本地主机和Azure静态Web应用程序中提供不同的消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!