Accessing string resources from embedded .resx in dll?
I'm completely new to resource files, but I need to deploy my application as a single tap and this seems to ignore all my external files (images, .ini files, etc.) - Instead of wasting time trying to figure it out, I thought I'd learn how to use resource files correctly.
After searching through SO I found a lot of code and I created my resource file. So far, it only contains lines that I thought would be easier !? Alas...
So, I have my DLL (ValhallaLib.dll) and these two functions for working with resources (these functions are stored in a static helper class where all my random but useful functions live):
public static Bitmap getImageByName(string imgName)
{
System.Reflection.Assembly asm = System.Reflection.Assembly.GetExecutingAssembly();
string resName = asm.GetName().Name + ".Properties.Resources";
var rm = new System.Resources.ResourceManager(resName, asm);
return (Bitmap)rm.GetObject(imgName);
}
public static string getStringByName(string var)
{
System.Reflection.Assembly asm = System.Reflection.Assembly.GetExecutingAssembly();
string resName = asm.GetName().Name + ".Properties.Resources";
var rm = new ResourceManager(resName, asm);
return rm.GetString(var);
}
And I'm trying to call them simple:
CHelpers.getStringByName("db_host_address");
Now, other than getting a MissingManifestException ... My problem is that I have no idea (and cannot find a direct answer!) What should be resName
. My resource file is called: StringResource.resx
- However, this is not the case when you say Assembly.ValhallaLib.StringResource.
Can anyone suggest some guidance please?
Update
I've tried global::ValhallaLib.StringResource
- but that's not exactly what I'm after either.
Update 2 Solved. I managed to get it to work with:
public static string getStringByName(string var)
{
System.Reflection.Assembly asm = System.Reflection.Assembly.GetExecutingAssembly();
string resName = asm.GetName().Name + ".Properties.Resources";
var rm = new ResourceManager("ValhallaLib.StringResource", asm);
return rm.GetString(var);
}
I don't know why I found this too complicated. Perhaps because I had about 2 hours of sleep.
Cheers to those who tried: :)
source to share
facepalm I figured it out. I can access the resource file using
public static string getStringByName(string var)
{
System.Reflection.Assembly asm = System.Reflection.Assembly.GetExecutingAssembly();
string resName = asm.GetName().Name + ".Properties.Resources";
var rm = new ResourceManager("ValhallaLib.StringResource", asm);
return rm.GetString(var);
}
Ignore me :)
source to share