Last post Sep 20, 2011 11:01 PM by Saavik
Sep 18, 2011 10:52 PM|Saavik|LINK
I know this seems really obvious, but I am having an issue here.
I have to reference string resources in an external dll (which I cannot change).
Here is my code that results in an error:
Dim rm As ResourceManager
rm = New ResourceManager("Resources", Assembly.Load("MyDll"))
' Get a string
rm.GetString results in this error:
"Could not find any resources appropriate for the specified culture or the neutral culture. Make sure "Resources.resources" was correctly embedded or linked into assembly "MyDll" at compile time, or that all the satellite assemblies required are loadable
and fully signed."
Why is it looking for Resources.resources when I specified only "Resources" in New ResourceManager statement?
Help most appreciated.
Sep 19, 2011 02:30 AM|Aminjun|LINK
I think your assembly is not loaded properly.Try using Assembly.LoadFile(). And about your question I think every single Resource Content is ended with .resource property.
Sep 19, 2011 10:03 AM|Saavik|LINK
Thank you for your quick reply.
I tried your suggestion, and still encountering the same error. I think the issue is not loading the dll, but rather, finding the resources therein.
Is my code right? (see above).
Sep 19, 2011 03:08 PM|Aminjun|LINK
A MissingManifestResourceException is thrown when the
attempt to retrieve a resource fails because the resource set for the neutral
culture could not be loaded from a particular assembly. Note that even though
the exception is thrown when you attempt to retrieve a particular resource, it
is caused by the failure to load the resource set rather than the failure to
find the resource. The main causes of the exception include the following:
The resource set is not identified by its fully qualified name. For example,
if the baseName parameter in the call to the
ResourceManager.ResourceManager(String, Assembly) method includes
the root name of the resource set without a namespace, but the resource set is
assigned a namespace when it is stored in its assembly, the call to the ResourceManager.GetString
method throws this exception. You can
determine the namespace of the resource set by examining its assembly with a
reflection tool such as Ildasm.exe (MSIL
Originally from MSDN :
I have tested and get your exception but after I changed my baseName Parameter and run it again , the program worked
ResourceManager rm = new ResourceManager("ClassLibrary1.Properties.Resources",
try ILDasm.exe and open your assembly, and look for your resource address base (actually the Namespace hierarchy ) and type it in baseName parameter.
hope it works for you too.
Sep 19, 2011 09:53 PM|Saavik|LINK
Thank you very much for the detail in your response.
Unfortunately - still not working.
I have used the disassembler to display the dll. Here is (part) what I saw:
D:\Data...\Mydll.dll (the full path to the dll)
M A N I F E S T
.class public auto ansi sealed
.custom instance void
get_MyString1 : string()
get_MyString2 : string()
I assumed my code should use look like this:
rm = New ResourceManager("Mydll.My.Resources", Assembly.LoadFile(full Path To Mydll.dll))
String s = rm.GetString("MyString1")
Help MOST appreciated!
Sep 20, 2011 03:24 AM|Aminjun|LINK
If the output of ILDasm is what you have posted , you should use
rm = New ResourceManager("Mydll.My.Resources.Resources", Assembly.LoadFile(full Path To Mydll.dll))
String s = rm.GetString("MyString1")
Sep 20, 2011 03:41 PM|Saavik|LINK
Thanks again for your help.
I have tried every possible combination I could think of, but to no avail.
In debug, I looked at “rm”, and saw that there are 0 ResourceSets. So, if I am reading this correctly, ResourceManager did not find or load any resources.
I am stumped! This is a real road block!
Help would be most appreciated.
Sep 20, 2011 08:09 PM|rstrahl|LINK
Another thing you can do that might be much easier:
.NET automatically creates resource wrapper classes for resource files - they're usually in your Properties folder. By default these auto-generated classes are internal and so not visible cross assembly. But you can use the designer to set a flag to make
them public (in the Resource designer click on the Access Modifier dialog and choose: Public).
Once you've done that you can set a reference to your assembly in the project or load the assembly via code and then reference the class. It should return the appropriate resources for you as well in the current ui-culture.
Hope this helps,
+++ Rick ---
Sep 20, 2011 11:01 PM|Saavik|LINK
Thank you for your help.
I did not quite understand your solution, so I pursued another path, and Tada! A solution was found.
Examining the error message carefully, I noticed that the system (whatever it may be) was looking for an extra “.resources”. So, on a whim, I opened Resources.Designer.vb and added “.resources” to the namespace (without quotes).
Obviously – a bug! But now it works.
I appreciate all your time and help.