Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ResourceReader Cannot Read Resource File #10306

Closed
zeus82 opened this issue May 10, 2018 · 3 comments
Closed

ResourceReader Cannot Read Resource File #10306

zeus82 opened this issue May 10, 2018 · 3 comments
Labels
question Answer questions and provide assistance, not an issue with source code or documentation.

Comments

@zeus82
Copy link

zeus82 commented May 10, 2018

We are in the process of migrating an application from the .NET Framework to .NET Core 2, but it looks like the ResourceReader cannot process a valid resx file.

When I create the ResourceReader I get

System.ArgumentException: Stream is not a valid resource file.
   at System.Resources.ResourceReader._ReadResources()
   at System.Resources.ResourceReader.ReadResources()
   at System.Resources.ResourceReader..ctor(String fileName)

Here is a gist to the contents of the resx file.

@danmoseley
Copy link
Member

That should certainly work. Could you share a code snippet?

@zeus82
Copy link
Author

zeus82 commented May 10, 2018

Here's how I'm using it:

        public IEnumerable<Tuple<string, string>> Parse(string fileName)
        {
            var results = new List<Tuple<string, string>>();

            fileName = Path.GetFullPath(fileName);

            if (!string.IsNullOrWhiteSpace(Path.GetDirectoryName(fileName)))
                Directory.SetCurrentDirectory(Path.GetDirectoryName(fileName));
            using (var reader = new ResourceReader(fileName)) // This blows up
            {
                foreach (DictionaryEntry pair in reader)
                {
                    results.Add(new Tuple<string, string>(pair.Key as string, pair.Value as string));
                }
            }
            return results;
        }

@jkotas
Copy link
Member

jkotas commented May 10, 2018

ResourceReader is for reading .resources files. .resources files are binary compiled files.

ResourceReader is not for reading .resx files. .resx files are xml source files. You need to use GenerateResource build task to compile .resx file into .resources files. Typically, you do not need to call this build task explicitly - it gets called implicitly by just having the .resx file in your solution.

This is same between .NET Core and .NET Framework.

@jkotas jkotas closed this as completed May 10, 2018
@msftgits msftgits transferred this issue from dotnet/coreclr Jan 31, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 17, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
question Answer questions and provide assistance, not an issue with source code or documentation.
Projects
None yet
Development

No branches or pull requests

3 participants