简体   繁体   中英

Can't read a resource file

Here's my code when retrieving the resource file.

ResourceManager resourceManager = ResourceManager.CreateFileBasedResourceManager("Resource.resx", @"c:\", null);  

resourceValue = resourceManager.GetString("key1");

But I got this exception everytime I run this.

Could not find any resources appropriate for the specified culture (or the neutral culture) on disk. baseName: Resources.resx locationInfo: null fileName: Resources.resx.resources

What's wrong in my code?

Steven is right, it's looking for a .ressources file. You need to compile your resx file with resgen : http://msdn.microsoft.com/en-us/library/ccec7sz1(v=vs.71).aspx

Some more info : the resx file is just a file that describes how to create a resources file. When you compile it (is compile the right word ?) with resgen, it takes all images, texts, etc.. and merge them in the real resource file that you can distribute and work with.

I suggest the following read, it may help : http://edndoc.esri.com/arcobjects/9.1/ArcGISDevHelp/DevelopmentEnvs/DotNet/WorkingWithResources.htm

It is looking for a different file, as mentioned on msdn , and in your exception message.

baseName Type: System.String The root name of the resources. For example, the root name for the resource file named "MyResource.en-US.resources" is "MyResource".

Your file should be named "Resource.resources", when passing "Resource" as baseName to the method. When you want custom resources for different cultures, you should name them like "Resource.en-US.resources" where the "en-US" part is replaced by the desired ISO culture name .

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