Click here to Skip to main content
15,670,482 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hey !
i have an issue with adding a resource file to my generated exe file in runtime!
i used 'Microsoft.CSharp.CSharpCodeProvider' and 'System.CodeDom.Compiler.CompilerParameters' to generate a exe file in runtime... my problem is adding a resource file (.resx) ! i use EmbeddedResources or LinkedResources to add a resx file to my generated exe file! but this error will show! :
Unhandled Exeption :System.Resources.MissingManifestResourceException :Could not find any resource apprpriate for the specified culture or the nutural culture . Make sure "ChildProgram.Form1.Resources" was correctly embedded or linked into assembly "ChildProgram" at compile time ,or that all the satellite assemblies required are loadable and fully signed.
at System.Resources.ManifestBasedResourceGroveler.HandledResourceStreamMissing<string filename>

i dont know what should i do! i searched manytimes but resolutions not effective on my problem!
can you explain me how should add a resource in runtime?maybe i missed something!

this is that line causes error
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
this.rdp.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("rdp.OcxState")));

very thanks!
Updated 24-Apr-13 5:54am

1 solution

If you are embedding the .resx file directly into the assembly then that is probably incorrect. Although the compiler will let you embed any file, the default format expected and understood by the managed environment is the binary '.resources' format.

Resx can be thought of as the source code for a binary resource and Visual Studio uses resgen.exe to convert between the two as shown by this (heavily edited) output from the compilation of a simple program.

Target CoreResGen:
    "C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\bin\Resgen.exe" 
    /compile Form1.resx,obj\Debug\ResourceTest.Form1.resources    
    Processing resource file "Form1.resx" into "obj\Debug\ResourceTest.Form1.resources".
Target CoreCompile:
  Task "Csc"
   /target:winexe Form1.cs Form1.Designer.cs Program.cs

I don't think the .NET framework class library has anything that implements the functionality of the resgen.exe tool and your only recourse will be to run it with the correct arguments via Process.Start.

Use CompilerParameters.EmbeddedResources and ensure that the resources associated with forms are given the correct name.

For the following form the resource must be named ResourceTest.Form1.resources
namespace ResourceTest {
  public class Form1 : Form {}

The MissingManifestResourceException will occur if the ComponentResourceManager cannot find the correctly named resource. e.g. If I change the name of the binary resource file from ResourceTest.Form1.resources to ResourceTest.Form2.resources then the program raises the exception.

Share this answer
ali_heidari_ 24-Apr-13 11:30am    
very thanks ... i used resgen to convert my .resx to .resources but with wich one of this classes in the System.CodeDom.Compiler.CompilerParameters i should add it? ReferencedAssemblies,EmbeddedResources,LinkedResources,Win32Resources
i try all of them but always same error shown! can you tell me i should use wich one? (how use) very thanks for spending time for me!
Richard C Bishop 24-Apr-13 11:41am    
The proper use of the combining of the words "very" and "thanks" is "Thank you very much". Just a friendly comment for your clarification.
ali_heidari_ 24-Apr-13 11:42am    
thank you very much for your clarification!
Richard C Bishop 24-Apr-13 11:45am    
You are welcome and nice use of the phrase.
ali_heidari_ 24-Apr-13 11:48am    
english is not my first language, i have these problems ! but really important things here is solving my problem, it wastes my time for more than 24 hours!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900