473,238 Members | 1,916 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,238 software developers and data experts.

Resource reader broken. What have i done wrong please

I originally created several "copy" resource reader classes which worked
great individually, but after I converted them into an parent class with
children they no longer find the resources. Each project contains its own
reader class and resource .resx file from where a string or image is read.

Can someone tell me what I need to do to get them to work please. I attach
code.

Im not sure if it's because the derived classes are in different name spaces
to the parent, or whether "myStringResourceManager = new
ResourceManager(myStringResourceName, Assembly.GetExecutingAssembly());" is
returning the ancestor's assembly rather than the derived class' or if it's
something else completely.
Module 1. Ancestor class
==================
using System;
using System.Globalization;
using System.Resources;
using System.Reflection;
using System.Threading;
using System.Drawing;
namespace P.BaseResourceHandler
{
public class BaseResourceHandler
{
protected string myStringResourceName = "";
protected string myImageResourceName = "";
private ResourceManager myStringResourceManager;
private ResourceManager myImageResourceManager;

private ResourceManager StringResourceManager
{
get
{
if (myStringResourceManager == null)
myStringResourceManager = new ResourceManager(myStringResourceName,
Assembly.GetExecutingAssembly());
return myStringResourceManager;
}
}
private ResourceManager ImageResourceManager
{
get
{
if (myImageResourceManager == null)
myImageResourceManager = new ResourceManager(myImageResourceName,
Assembly.GetExecutingAssembly());
return myImageResourceManager;
}
}

// Get the culture of the currently executing thread.
// The value of ci will determine the culture of
// the resources that the resource manager retrieves.
private CultureInfo cultureinfo = Thread.CurrentThread.CurrentCulture;

/// <summary>
/// Loads a string from the resources and returns it
/// </summary>
/// <param name="ID">ID of the string</param>
/// <returns>The resource string</returns>
public string LoadString(string ID)
{
try
{
// Retrieve the value of thes string resource named
// ID, localized for the culture specified by ci.
String str = StringResourceManager.GetString(ID, cultureinfo);
if (str == "")
throw new Exception("Resource '" + ID + "' is missing from the resource
file");
return str;
}
catch(Exception e)
{
return ID;
}
}// function
/// <summary>
/// Loads an image from the resources and returns it
/// </summary>
/// <param name="ID">ID of the image</param>
/// <returns>The image</returns>
public Image LoadImage(string ID)
{
string fnName = "LoadImage";
try
{
// Retrieve the value of thes image resource named
// ID, localized for the culture specified by ci.
Image image = (Image)ImageResourceManager.GetObject(ID, cultureinfo);
if (image == null)
throw new Exception("Image resource '" + ID + "' is missing from the
resource file");
return image;
}
catch(Exception e)
{
return new Bitmap(10,10);
}
}// function
}// class
}// namespace

Module 2. example child class
==================

using System;
using System.Globalization;
using System.Resources;
using System.Reflection;
using System.Threading;
using System.Drawing;
using P.BaseResourceHandler;
namespace P.SmartCentre
{
/// <summary>
/// ResourceHandler handles resources kept in the resource files
/// </summary>
public class ResourceHandler : BaseResourceHandler.BaseResourceHandler
{
private static ResourceHandler mResourceHandler;

public ResourceHandler()
{
myStringResourceName = "P.SmartCentre.StringResources";
myImageResourceName = "P.SmartCentre.ImageResources";
}
/// <summary>
/// Returns an instance of a ResourceHandler object if called
/// </summary>
public static ResourceHandler Resources
{
get
{
if (mResourceHandler == null)
mResourceHandler = new ResourceHandler();
return mResourceHandler;
}
}// function
}//class
}// Namespace
Jul 26 '06 #1
1 2087
Yes, the problem was with ResourceManager(myStringResourceName,
Assembly.GetExecutingAssembly()) which was returning the parent class
assembly rather than the derived class. Instead I stored the derived class
Assembly during the constructor and accessed that instead.
Thanks anyway
Jul 26 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Code Guy | last post by:
Hello, I am trying to execute the following code: private void button1_Click(object sender, System.EventArgs e) { PictureBox c = new PictureBox(); c.BorderStyle = BorderStyle.FixedSingle;...
7
by: Christofer Dutz | last post by:
Hi, I am trying to read a XML-File which I marked as embedded resource from within the code of my DLL. Unfortunately it doesn't work. On my search for the error I inserted some code for...
3
by: J.Marsch | last post by:
Hello all: I am trying to build a resource dll that will house icons, and I'm afraid that I'm not having much luck reading it. Can you lend hand (or just point me to a good primer). Here's...
12
by: bj7lewis | last post by:
I am working on a project I want to add a few files as resource to access(copy them to FS and use) at runtime. So far in VS.NET IDE, I Add Files to the project and set its Build Action to...
3
by: al | last post by:
Hi, I use a resource file (.resx) to store user's settings such as language and other strings. The problem i'm facing is that when the user changes one of the strings in the resource file, ...
1
by: coz | last post by:
Someone please help! I cannot for the life of me get a web resource in asp.net 2.0 to return any content. I know I have correctly embedded my resources (because I can manually get the resources...
0
by: Fabrice | last post by:
Hello, (Alain) Tis is a part of my code to retrieve text from hastable in memory cache, by reading (befor) a resources file. Thanks for your help. /1/ The resources file * I have create a...
9
by: Alf P. Steinbach | last post by:
<what to design a C++ solution for> A Windows API /resource/ is data embedded in the executable, accessed via API functions. A resource is completely identified by the quadruple (id, type,...
5
by: =?Utf-8?B?QXhlbCBEYWhtZW4=?= | last post by:
Hi, I've created a class library assembly containing several string resource files, like: - TableColumns.resx - TableColumns.de.resx - General.resx - General.de.resx
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.