Here's my code when retrieving the res开发者_如何学Goource 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.
精彩评论