Stream is not a valid resource file RRS feed

  • Question

  • I am working with ASP.NET MVC4 and I have my own class where I am using System.resources.ResourceReader class to access my resource file. Whatever I do, I will get some exception. But this exception is the most irritating. Here is the code:

    using (ResourceReader resReader = new ResourceReader(@"C:\Users\Administrator\Desktop\InternacionalizacijaPokusaj4\InternacionalizacijaPokusaj4\App_GlobalResources\en-UK.resources.resx"))
          IDictionaryEnumerator dictionaryEnumerator = resReader.GetEnumerator();
          while (dictionaryEnumerator.MoveNext())
               if ((string)dictionaryEnumerator.Key == property)
                      value = (string)dictionaryEnumerator.Value;

    Since my resource file by default have .resx exstension, I don't get it why am I getting this exception. And is there a way to make path string shorter?

    Microsoft Student Parnter Microsoft Technology Associate

    • Moved by Jason Dot Wang Wednesday, October 23, 2013 5:49 AM This thread is about ASP.NET
    Thursday, October 17, 2013 11:42 AM

All replies

  • ResourceReader is intended for .resources files, binary versions of .resx. There's the ResXResourceReader class if you want to read .resx files. Or you could use a XmlReader since the format is quite trivial.

    But ultimately I'm not sure why are you trying to read a .resx file like that. Normally .resx files are compiled to .resources files and embedded in the dll. Accessing such resources is usually done by using the ResourceManager class.

    Thursday, October 17, 2013 11:55 AM
  • can you post Error Details

    if you have any file access error , change the folder path from desktop to regular directory

    Happy Coding, RDRaja

    Thursday, October 17, 2013 11:56 AM
  • The main problem is that I want to determin within the method which resource file will be open, based on users language. Since that is a string, I need to parse that string to a string parameter so constructor will now the path to that resource file.

    And I can't access ResXResourceReader class in MVC4.

    Microsoft Student Parnter Microsoft Technology Associate

    Thursday, October 17, 2013 12:38 PM
  • You're doing this wrong, you're really not supposed to read .resx files like that. Normally this is done by using the ResourceManager class and passing the appropriate culture to the GetString overload that takes a culture argument. Or pass null to it and it will use the current thread's culture.

    I'm not familiar with MVC so I don't know if there are specific ways used to localize MVC apps but a quick search of the Internet lead to me to this: It makes more sense that what you're trying to do now.

    I suggest you to the ASP.NET MVC forums and ask there about the proper way to localize MVC apps:

    Thursday, October 17, 2013 12:50 PM