Solved

MissingManifestResourceException when running Windows Service /  C# (VS 2003)

Posted on 2007-04-10
3
485 Views
Last Modified: 2013-12-17
I have a simple Windows Service written in C# and I would like to maintain error messages in a Resource File.

I added the resource file by Right-Clicking on the project name in the Solution Explorer and selecting Add New Item -> Assemly Resource File, and I gave it the name "MainResource".  The extension .resx was then added to the file name.

I then wrote a class called "ResourceHelper".

The entire code for ResourceHelper is as follows:
/************************************************************************************************/
using System;
using System.Resources;
using System.Reflection;

namespace crodia2batchprocess_ws.Resources
{
      /// <summary>
      /// Summary description for ResourceHelper.
      /// </summary>
      public class ResourceHelper
      {
            public ResourceHelper()
            {
                  //
                  // TODO: Add constructor logic here
                  //
            }

            public static string GetMessage(int MessageNumber)
            {
         
                  String message;
                  String strNumber;
                  String resourceCode;

                  strNumber = Convert.ToString(MessageNumber);
                  
                  //messages are defined in the resource file as "msgNNNN"
                  //msgNumber = "msg" + MessageNumber.ToString.
                  //48 = ASCII 0
                  //Example: message number 123 would be filed using resource code "msg0123"
                  resourceCode = "msg" + strNumber.PadLeft(4, (char)48);
                                                                                                        
                  Assembly asm = Assembly.GetExecutingAssembly();
   
                  //ResourceManager rm = new ResourceManager("MainResource.resx", asm);
                  ResourceManager rm = new ResourceManager("MainResource", asm);
           
                  message = (string) rm.GetObject(resourceCode);

                  return message;

            }

      }
}
/************************************************************************************************/

The project compiles without any errors.

An example of where I make a call to the above method from my Windows Service code is as follows:


public Crodia2BatchProcess()
      {
            // This call is required by the Windows.Forms Component Designer.
            InitializeComponent();

            // TODO: Add any initialization after the InitComponent call
            // Just check if the settings file exists. If so, the service will go to
            // OnStart and load the settings file.
            if (!File.Exists(GlobalValues.AppSettingsFileName))
            {      
      
                  EventLog.WriteEntry(ResourceHelper.GetMessage(1), EventLogEntryType.Information);

                  this.OnStop();                                    

            }      // !File.Exists
            // Else the service will go straight to OnStart
      }


I installed the service successful using InstallUtil <servicename.exe>

When I attempt to start the service, I deliberately make sure that my file defined under AppSettingsFileName does not exist in order to throw the exception trapped above which I would then like to access the message in the Resource file using the GetMessage method.

When I start the service, I get a Window telling me that a MissingManifestResourceException has occurred...


Any ides of where I'm going wrong?  

Many thanks.

0
Comment
Question by:ersldublin
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 18883600
What is the 'Build Action' for the .resx file?

Bob
0
 

Author Comment

by:ersldublin
ID: 18888069
Embedded Resource
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 250 total points
ID: 18888328
Actually, the file names for the .resources files should be fully qualified with the LCID for the language you are working with:

ResourceManager class:
http://msdn2.microsoft.com/en-us/library/system.resources.resourcemanager.aspx

Examples:
MyResources.ja-JP.resources
MyResources.zh-CHS.resources
MyResources.fr-BE.resources

Bob
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have done a reformat of your hard drive and proceeded to do a successful Windows XP installation, you may notice that a choice between two operating systems when you start up the machine. Here is how to get rid of this: Click Start Clic…
Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

635 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question