开发者

Problem with creating ResXResourceSet object from the embedded resource file

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 stre开发者_运维百科am and from file name). How can I create an object of the ResXResourceSet class in this situation?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜