简体   繁体   English

无效的 URI:Uri 字符串太长

[英]Invalid URI: The Uri string is too long

I am trying to grab a schema and validate against my xml.我正在尝试获取架构并针对我的 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.问题是,如果参数是字符串,则 xmlreader.create function 中的 xml 应该是 uri。

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.在您的情况下, xml 文件被解释为 url ,因此它抱怨限制。

look at this msdn doc XmlReader.Create Method for different overloaded methods..看看这个msdn doc XmlReader.Create Method以了解不同的重载方法。

I am guessing you should use the TextReader one.我猜你应该使用TextReader之一。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无效的 URI:Uri 字符串太长 HttpGET - Invalid URI: The Uri string is too long HttpGET Uri.EscapeDataString() - 无效的 URI:Uri 字符串太长 - Uri.EscapeDataString() - Invalid URI: The Uri string is too long XDocument System.UriFormatException: '无效的 URI: Uri 字符串太长 - XDocument System.UriFormatException: 'Invalid URI: The Uri string is too long 无效的URI:使用Imgur API的Uri字符串过长 - Invalid URI: The Uri string is too long using Imgur API HttpClient:uri字符串太长 - HttpClient: The uri string is too long URI 无效:尝试将值字典发布到 API 时 Uri 字符串太长 - Invalid URI: The Uri string is too long when trying to post dictionary of values to API Facebook C#SDK Windows Phone无效的URI:Uri字符串太长 - Facebook C# SDK Windows Phone Invalid URI: The Uri string is too long System.UriFormatException:'无效的URI:Uri方案太长。 - System.UriFormatException: 'Invalid URI: The Uri scheme is too long.' 当我在mvc中获取base64的数据时,发现异常{“无效的URI:Uri字符串太长。”} - When i fetch data of base64 in mvc found exception {“Invalid URI: The Uri string is too long.”} 图像提取:uri太长 - Image Extraction : uri is too long
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM