Click here to Skip to main content
15,906,567 members
Home / Discussions / C#
   

C#

 
QuestionWhen to use Int32.Parse(... vs. Convert.ToInt32(... Pin
...---...30-Sep-05 9:20
...---...30-Sep-05 9:20 
AnswerRe: When to use Int32.Parse(... vs. Convert.ToInt32(... Pin
Robert Rohde30-Sep-05 9:48
Robert Rohde30-Sep-05 9:48 
AnswerRe: When to use Int32.Parse(... vs. Convert.ToInt32(... Pin
mpw_30-Sep-05 10:19
mpw_30-Sep-05 10:19 
QuestionConnection between two C# program Pin
Yanshof30-Sep-05 9:13
Yanshof30-Sep-05 9:13 
AnswerRe: Connection between two C# program Pin
DavidNohejl30-Sep-05 9:30
DavidNohejl30-Sep-05 9:30 
QuestionHow to calculate the nearest color? Pin
bouli30-Sep-05 9:07
bouli30-Sep-05 9:07 
AnswerRe: How to calculate the nearest color? Pin
DavidNohejl30-Sep-05 9:27
DavidNohejl30-Sep-05 9:27 
QuestionCSharpCodeProvider generated EXE embedded with ResourceWriter generated .resources fails... Pin
Jon Rista30-Sep-05 6:43
Jon Rista30-Sep-05 6:43 
I have a project where I need to create a windows .exe by compiling code and linking in some resources. This program thats being generated is somewhat unconventional, and I'll explain how. I'm generating a very simple installer app that embeds referenced .dll files inside it, which are extracted and referenced when the installer app is executed. This works great when the installer app is built with Visual Studio .NET, but it does not work when I compile it myself using a CSharpCodeProvider. The resources are written to a .resource file using a ResourceWriter just prior to compilation of the .exe. I add a custom compiler option to embed the resources. Code follows:

PopupProgress.Display("Compiling Installer...", null, "Compiling", "Creating
compiler...", 3, 1);
// Create code compiler
CSharpCodeProvider provider = new CSharpCodeProvider();
ICodeCompiler compiler = provider.CreateCompiler();

// Create compiler parameters
PopupProgress.Display("Compiling Installer...", null, "Compiling",
"Configuring compiler...", 3, 2);
CompilerParameters cparams = new CompilerParameters();
cparams.Evidence = new
System.Security.Policy.Evidence(AppDomain.CurrentDomain.Evidence);
cparams.GenerateExecutable = true;
cparams.GenerateInMemory = false;
cparams.IncludeDebugInformation = false;
//cparams.MainClass = "S2CIPInstaller.Main";
//cparams.OutputAssembly = step4.CompileTarget;
cparams.TempFiles = new TempFileCollection(m_basePath + @"temp\", true);
cparams.ReferencedAssemblies.Add("System.dll");
cparams.ReferencedAssemblies.Add("System.Drawing.dll");
cparams.ReferencedAssemblies.Add("System.Windows.Forms.dll");
// cparams.ReferencedAssemblies.Add("System.XML.dll");
cparams.ReferencedAssemblies.Add(m_basePath +
@"temp\SynapticEffect.Collections.dll");
cparams.ReferencedAssemblies.Add(m_basePath + @"temp\DatGen.DBPF.dll");
cparams.CompilerOptions = "/resource:\"" + m_basePath +
"temp\\S2CIPInstaller.resources\"";
//cparams.Win32Resource = m_basePath + @"temp\S2CIPInstaller.resources";

// Compile
PopupProgress.Display("Compiling Installer...", null, "Compiling", "Please wait...", 3, 3);
CompilerResults results = compiler.CompileAssemblyFromSource(cparams, code);
PopupProgress.Remove();

int errCount = 0;
for (int i=0; i<results.errors.count; i++)
{
="" if="" (!results.errors[i].iswarning)
="" errcount++;
}

if="" (errcount=""> 0)
{
MessageBox.Show(this, "There were errors during compilation. Installer not created.");
}
else
{
MessageBox.Show(this, "Installer successfully created!");
}


When I use the code provider from my own program, I get the following error (only visible after attaching with a debugger. I apologize for the coded .exe name --> yodjgmq_.exe):


An unhandled exception of type 'System.Resources.MissingManifestResourceException' occurred in mscorlib.dll

Additional information: Could not find any resources appropriate for the
specified culture (or the neutral culture) in the given assembly. Make sure "S2CIPInstaller.resources" was correctly embedded or linked into assembly "yodjgmq_". baseName: S2CIPInstaller locationInfo: DatGen.S2CIPInstaller resource file name: S2CIPInstaller.resources assembly: yodjgmq_, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null


Does anyone know why the installer app works when compiled with VS.NET, but not with the CSharpCodeProvider and ResourceWriter classes from the .NET Framework from my own code? Any insight is greatly appreciated.

Jon Rista
jrista@hotmail.com
AnswerRe: CSharpCodeProvider generated EXE embedded with ResourceWriter generated .resources fails... Pin
Jon Rista1-Oct-05 8:11
Jon Rista1-Oct-05 8:11 
QuestionConvert colour image to Black and White Pin
Colin Waite30-Sep-05 5:57
Colin Waite30-Sep-05 5:57 
AnswerRe: Convert colour image to Black and White Pin
Jon Rista30-Sep-05 7:11
Jon Rista30-Sep-05 7:11 
QuestionConvert a video from 32bit -&gt;16bit in DirectShow -- possible? Pin
Nyst30-Sep-05 5:12
Nyst30-Sep-05 5:12 
QuestionRetrieve resource from resources.resx? Pin
Carl Mercier30-Sep-05 4:04
Carl Mercier30-Sep-05 4:04 
AnswerRe: Retrieve resource from resources.resx? Pin
Jon Rista30-Sep-05 7:23
Jon Rista30-Sep-05 7:23 
AnswerRe: Retrieve resource from resources.resx? Pin
Heinz_30-Sep-05 8:33
Heinz_30-Sep-05 8:33 
GeneralRe: Retrieve resource from resources.resx? Pin
Carl Mercier30-Sep-05 10:56
Carl Mercier30-Sep-05 10:56 
GeneralRe: Retrieve resource from resources.resx? Pin
Heinz_30-Sep-05 17:35
Heinz_30-Sep-05 17:35 
QuestionPage_Unload question Pin
Sled Dog30-Sep-05 3:50
Sled Dog30-Sep-05 3:50 
AnswerRe: Page_Unload question Pin
Tom Larsen30-Sep-05 4:35
Tom Larsen30-Sep-05 4:35 
GeneralRe: Page_Unload question Pin
Sled Dog30-Sep-05 4:56
Sled Dog30-Sep-05 4:56 
QuestionCrystalReport RAS Request Pin
User 209307330-Sep-05 2:26
User 209307330-Sep-05 2:26 
Questionfetching data from dataset using sql query Pin
arusmemon30-Sep-05 1:40
arusmemon30-Sep-05 1:40 
AnswerRe: fetching data from dataset using sql query Pin
Gavin Jeffrey30-Sep-05 2:07
Gavin Jeffrey30-Sep-05 2:07 
AnswerRe: fetching data from dataset using sql query Pin
Jon Rista30-Sep-05 7:36
Jon Rista30-Sep-05 7:36 
QuestionRotating images Pin
PHDENG8130-Sep-05 1:25
PHDENG8130-Sep-05 1:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.