PC Review


Reply
Thread Tools Rating: Thread Rating: 1 votes, 1.00 average.

CSharpCodeProvider generated EXE embedded with ResourceWriter generated .resources fails...

 
 
Jon Rista
Guest
Posts: n/a
 
      30th Sep 2005
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
(E-Mail Removed)


 
Reply With Quote
 
 
 
 
Jon Rista
Guest
Posts: n/a
 
      30th Sep 2005
Is there a better group I could ask this question in?

Jon Rista

"Jon Rista" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>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
> (E-Mail Removed)
>



 
Reply With Quote
 
Tom Spink
Guest
Posts: n/a
 
      30th Sep 2005
One day, Jon Rista wrote:

> Is there a better group I could ask this question in?
>
> Jon Rista
>
> "Jon Rista" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>>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
>> (E-Mail Removed)
>>


Hi Jon,

Have you checked that your paths are all correct? This is the only thing I
can think of, off the top of my head. The error, to me, states to "Make
sure "..." was correctly embedded or linked into assembly "...""

Have you made sure your paths are correct, and whatnot?

--
Tom Spink
 
Reply With Quote
 
Jon Rista
Guest
Posts: n/a
 
      30th Sep 2005
Yeah, I'm pretty certain that the path to the .resources file is correct. I
am currently using the /resources option for csc though. Would linking the
resources be any different? I'm not sure whether VS.NET itself embeds or
links the resources when you compile there or not.

I'll mess with it some more and if I still have problems, I'll post.

"Tom Spink" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> One day, Jon Rista wrote:
>
>> Is there a better group I could ask this question in?
>>
>> Jon Rista
>>
>> "Jon Rista" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>>>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
>>> (E-Mail Removed)
>>>

>
> Hi Jon,
>
> Have you checked that your paths are all correct? This is the only thing
> I
> can think of, off the top of my head. The error, to me, states to "Make
> sure "..." was correctly embedded or linked into assembly "...""
>
> Have you made sure your paths are correct, and whatnot?
>
> --
> Tom Spink



 
Reply With Quote
 
Jon Rista
Guest
Posts: n/a
 
      1st Oct 2005
Well, the resources are there. The output .exe is the same size when
compiled with VS.NET or my own program. I'm really stumped as to why this
won't work.

"Jon Rista" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Yeah, I'm pretty certain that the path to the .resources file is correct.
> I am currently using the /resources option for csc though. Would linking
> the resources be any different? I'm not sure whether VS.NET itself embeds
> or links the resources when you compile there or not.
>
> I'll mess with it some more and if I still have problems, I'll post.
>
> "Tom Spink" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> One day, Jon Rista wrote:
>>
>>> Is there a better group I could ask this question in?
>>>
>>> Jon Rista
>>>
>>> "Jon Rista" <(E-Mail Removed)> wrote in message
>>> news:(E-Mail Removed)...
>>>>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
>>>> (E-Mail Removed)
>>>>

>>
>> Hi Jon,
>>
>> Have you checked that your paths are all correct? This is the only thing
>> I
>> can think of, off the top of my head. The error, to me, states to "Make
>> sure "..." was correctly embedded or linked into assembly "...""
>>
>> Have you made sure your paths are correct, and whatnot?
>>
>> --
>> Tom Spink

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
CSharpCodeProvider: referencing other generated "InMemory" assembl =?Utf-8?B?SmFu?= Microsoft C# .NET 11 29th Apr 2006 10:14 AM
vb.net mod fails 'app has generated an exception that could not be =?Utf-8?B?QmlsbA==?= Microsoft ASP .NET 0 10th Apr 2005 10:55 PM
.resources generated by .NET and creating your own Example2.resources.dll Derick Smith Microsoft VB .NET 0 15th Oct 2004 03:54 PM
ResourceWriter and embedded resources Kyle Kaitan Microsoft C# .NET 0 24th Sep 2004 08:48 PM
Fails In M/S Generated JScript Jim Heavey Microsoft ASP .NET 0 19th Nov 2003 09:10 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:01 AM.