简体   繁体   中英

ResxResourceReader throwing ArgumentNullException

I have used ResxResourceReader for reading resource file. It work well for some files. Its getting error for parsing below line

<data name="GlbResource"  type="System.Resources.ResXFileRef,  
System.Windows.Forms">
<value>glbresource.resx;System.String, mscorlib, Version=4.0.0.0,  
Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>
</data>

Could you tell me please why ResxResourceReader is failing for parsing above line?

Version=4.0.0.0

That's the problem. You are not running on .NET 4.0 (or later). So your program cannot load types from a version 4 assembly.

Assuming that you cannot target .NET 4, the only fix is to re-generate the .resx file. Open the form with the bad .resx file in the designer and make a trivial change to one of the properties. And just change it back. This recreates the .resx file, it will now use version 2.0.0.0 references. Double-check that the change was effective by looking at the .resx file with a text editor.

And you probably want to use Edit + Find and Replace + Find in Files to search all .resx files for "4.0.0.0" to make sure you have them all.

I had the same problem... Please use below code and try it out. Its worked for me..

XDocument xDoc = XDocument.Load("File Path");
IEnumerable<XElement> xmlData = xDoc.Descendants("node name");
foreach(XElement element in xmlData)
{
   if(element == null)
   {
       continue;
   }

   // retrieve key using element.Attribute("name").Value
   // retrieve value using element.Element("value").Value
 }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM