Invalid URI: The Uri string is too long(无效的 URI:Uri 字符串太长)
问题描述
我正在尝试获取架构并针对我的 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 阅读器 = XmlReader.Create(xml, settings);
我明白了
无效的URI:Uri字符串太长System.UriFormatException 未处理 Message=Invalid URI: Uri 字符串太长.源 = 系统堆栈跟踪:在 System.Uri.CreateThis(字符串 uri,布尔值 dontEscape,UriKind uriKind)在 System.Uri..ctor(字符串 uriString,UriKind uriKind)在 System.Xml.XmlResolver.ResolveUri(Uri baseUri,字符串 relativeUri)在 System.Xml.XmlUrlResolver.ResolveUri(Uri baseUri,字符串 relativeUri)在 System.Xml.XmlReaderSettings.CreateReader(字符串 inputUri,XmlParserContext inputContext)在 System.Xml.XmlReader.Create(字符串 inputUri,XmlReaderSettings 设置,XmlParserContext inputContext)在 System.Xml.XmlReader.Create(字符串 inputUri,XmlReaderSettings 设置)在 Program.cs:line 42 中的 ConsoleApplication2.Program.Main(String[] args)在 System.AppDomain._nExecuteAssembly(RuntimeAssembly 程序集,字符串 [] 参数)在 System.AppDomain.ExecuteAssembly(字符串 assemblyFile,证据 assemblySecurity,String [] args)在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()在 System.Threading.ThreadHelper.ThreadStart_Context(对象状态)在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext,ContextCallback 回调,对象状态,布尔 ignoreSyncCtx)在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext,ContextCallback 回调,对象状态)在 System.Threading.ThreadHelper.ThreadStart() 内部异常:
不告诉我最大长度是多少或任何东西.以前有人收到过这个吗?
如果参数是字符串,问题是你的 xmlreader.create 函数中的 xml 应该是 uri.
例如.
XmlReader reader = XmlReader.Create("http://ServerName/data/books.xml", settings);
在您的情况下,xml 文件被解释为 url,因此它抱怨限制.
看看这个 msdn 文档 XmlReader.Create 方法一>对于不同的重载方法..
我猜你应该使用 TextReader 之一.p>
I am trying to grab a schema and validate against my 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);
I get
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:
Does not tell me what the max length is or anything. Anyone ever get this before?
the problem is that the xml in your xmlreader.create function should be a uri if the argument is a string.
eg.
XmlReader reader = XmlReader.Create("http://ServerName/data/books.xml", settings);
In your case the xml file is being interpreted as the url and hence it is complaining about the limit.
look at this msdn doc XmlReader.Create Method for different overloaded methods..
I am guessing you should use the TextReader one.
这篇关于无效的 URI:Uri 字符串太长的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:无效的 URI:Uri 字符串太长
基础教程推荐
- MS Visual Studio .NET 的替代品 2022-01-01
- SSE 浮点算术是否可重现? 2022-01-01
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01
- 将 XML 转换为通用列表 2022-01-01
- rabbitmq 的 REST API 2022-01-01
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30
- 如何激活MC67中的红灯 2022-01-01
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01
- c# Math.Sqrt 实现 2022-01-01
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01