gpt4 book ai didi

c# - 无效的 URI : The Uri string is too long

转载 作者:可可西里 更新时间:2023-11-01 08:10:25 34 4
gpt4 key购买 nike

我正在尝试获取一个模式并根据我的 xml 进行验证。

  XmlReaderSetting settings = new System.Xml.XmlReaderSettings();
settings.Schemas.Add(null, "http://example.com/myschema.xsd");
settings.ValidationEventHandler += new System.Xml.Schema.ValidationEventHandler(settings_ValidationEventHandler);
settings.ValidationType = ValidationType.Schema;
settings.IgnoreWhitespace = false;
XmlReader reader = XmlReader.Create(xml, settings);

我明白了

Invalid URI: The Uri string is too long


System.UriFormatException was unhandled Message=Invalid URI: The Uri string is too long. Source=System StackTrace:
at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind)
at System.Uri..ctor(String uriString, UriKind uriKind)
at System.Xml.XmlResolver.ResolveUri(Uri baseUri, String relativeUri)
at System.Xml.XmlUrlResolver.ResolveUri(Uri baseUri, String relativeUri)
at System.Xml.XmlReaderSettings.CreateReader(String inputUri, XmlParserContext inputContext)
at System.Xml.XmlReader.Create(String inputUri, XmlReaderSettings settings, XmlParserContext inputContext)
at System.Xml.XmlReader.Create(String inputUri, XmlReaderSettings settings)
at ConsoleApplication2.Program.Main(String[] args) in Program.cs:line 42
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart() InnerException:

没有告诉我最大长度是多少或任何东西。有人以前得到过这个吗?

最佳答案

问题是如果参数是字符串,则 xmlreader.create 函数中的 xml 应该是一个 uri。

例如。

XmlReader reader = XmlReader.Create("http://ServerName/data/books.xml", settings);

在您的情况下,xml 文件被解释为 url,因此它提示限制。

看看这个 msdn 文档 XmlReader.Create Method对于不同的重载方法..

我猜你应该使用 TextReader一个。

关于c# - 无效的 URI : The Uri string is too long,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7043566/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com