0

I am trying to open a resx file that is a resource in my C# project. I need to create a ResXResourceSet object. However at runtime an "Illegal characters in path" exception is thrown. This is the code I am trying to use.

var resX = new ResXResourceSet(Project.Properties.Resources.ResXFile);

The ResXResourceSet class has only two constructors (from stream and from file name). How can I create an object of the ResXResourceSet class in this situation?

Peter17
  • 3,052
  • 9
  • 47
  • 77
  • You are getting the *content* of the .resx file embedded as a string in your resources. This is just not what you want, a .resx file should be compiled by resgen.exe. Add the file to your project instead. – Hans Passant Feb 07 '11 at 13:44

1 Answers1

2

Use Project.Properties.Resources.ResourceManager.GetStream("ResXFile");

If I understand correctly, the value in ResXFile is a string with the complete contents of the ResX, and not a file path, which is what ResXResourceSet expects when you pass it a string. You'll need to wrap a stream around it.

See this question for getting a stream from a string: how to generate a stream from a string?

Also, if you make the resource file into a project item, like the main resources, you can access its ResourceSet through its ResourceManager: ResXFile.ResourceManager.GetResourceSet()

You can add a ResX to your project by rightclicking on the project > Add > New Item > Resources File.

Community
  • 1
  • 1
Alex J
  • 9,905
  • 6
  • 36
  • 46
  • Thank you for respond. But, unfortunately, it is not working. The type of the Project.Properties.Resources.ResXFile is a string. And I can't get stream from that or invoke GetResourceSet() method. – Peter17 Feb 07 '11 at 12:18
  • Thank you! This time it worked out with generating stream from the string. But I am wondering, how can I make the resource file into project file in order to use ResXFile.ResourceManager.GetResourceSet() method? – Peter17 Feb 07 '11 at 14:31
  • Just add a new resource file to the project. I updated the answer. – Alex J Feb 07 '11 at 18:08