2015-06-08 60 views
0

調用XDocument.load(字符串URI)拋出ArgumentNullException

​​3210

,當我得到一個ArgumentNullException以下是異常的詳細信息。它說,「格式」參數是空的 - 但在哪一點我能夠控制這個參數? 或者我的錯誤究竟是什麼?

> System.ArgumentNullException was unhandled by user code 
>  HResult=-2147467261 
>  Message=Value cannot be null. 
>  Parameter name: format 
>  ParamName=format 
>  Source=mscorlib 
>  StackTrace: 
>  at System.String.FormatHelper(IFormatProvider provider, String format, ParamsArray args) 
>  at System.String.Format(String format, Object[] args) 
>  at System.SR.Format(String resourceFormat, Object[] args) 
>  at System.Xml.XmlException.CreateMessage(String res, String[] args, Int32 lineNumber, Int32 linePosition) 
>  at System.Xml.XmlException..ctor(String res, String[] args, Exception innerException, Int32 lineNumber, Int32 linePosition, String 
> sourceUri) 
>  at System.Xml.XmlTextReaderImpl.Throw(String res, String arg) 
>  at System.Xml.XmlTextReaderImpl.ParseAttributeValueSlow(Int32 curPos, Char quoteChar, NodeData attr) 
>  at System.Xml.XmlTextReaderImpl.ParseAttributes() 
>  at System.Xml.XmlTextReaderImpl.ParseElement() 
>  at System.Xml.XmlTextReaderImpl.ParseElementContent() 
>  at System.Xml.XmlTextReaderImpl.Read() 
>  at System.Xml.Linq.XContainer.ReadContentFrom(XmlReader r) 
>  at System.Xml.Linq.XContainer.ReadContentFrom(XmlReader r, LoadOptions o) 
>  at System.Xml.Linq.XDocument.Load(XmlReader reader, LoadOptions options) 
>  at System.Xml.Linq.XDocument.Load(String uri, LoadOptions options) 
>  at System.Xml.Linq.XDocument.Load(String uri) 
+0

看起來像無效的XML。 –

+1

但是,它不應該從該代碼的級別拋出null ref異常... –

+0

同意,看起來像一個嚴重的XML錯誤,足以在解析器能夠做出體面的報告之前將其解析。 –

回答

0

你需要這個

string EnviromentPath = Path.GetDirectoryName(HostingEnvironment.ApplicationPhysicalPath); 

到你的項目目錄 的路徑,然後你應該後

Path.Combine(EnviromentPath,@"AppData\TestAppData.xml"); 
+0

不,錯誤的路徑不會導致NullRef異常。 –

相關問題