473,396 Members | 1,998 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,396 software developers and data experts.

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

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.CurrentD omain.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.d ll");
cparams.ReferencedAssemblies.Add("System.Windows.F orms.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
jr****@hotmail.com
Nov 17 '05 #1
4 5859
Is there a better group I could ask this question in?

Jon Rista

"Jon Rista" <jr****@hotmail.com> wrote in message
news:eq*************@TK2MSFTNGP10.phx.gbl...
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.CurrentD omain.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.d ll");
cparams.ReferencedAssemblies.Add("System.Windows.F orms.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
jr****@hotmail.com

Nov 17 '05 #2
One day, Jon Rista wrote:
Is there a better group I could ask this question in?

Jon Rista

"Jon Rista" <jr****@hotmail.com> wrote in message
news:eq*************@TK2MSFTNGP10.phx.gbl...
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.CurrentD omain.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.d ll");
cparams.ReferencedAssemblies.Add("System.Windows.F orms.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
jr****@hotmail.com


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
Nov 17 '05 #3
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" <to*@nowhere.com> wrote in message
news:uT**************@TK2MSFTNGP14.phx.gbl...
One day, Jon Rista wrote:
Is there a better group I could ask this question in?

Jon Rista

"Jon Rista" <jr****@hotmail.com> wrote in message
news:eq*************@TK2MSFTNGP10.phx.gbl...
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.CurrentD omain.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.d ll");
cparams.ReferencedAssemblies.Add("System.Windows.F orms.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
jr****@hotmail.com


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

Nov 17 '05 #4
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" <jr****@hotmail.com> wrote in message
news:uo**************@TK2MSFTNGP10.phx.gbl...
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" <to*@nowhere.com> wrote in message
news:uT**************@TK2MSFTNGP14.phx.gbl...
One day, Jon Rista wrote:
Is there a better group I could ask this question in?

Jon Rista

"Jon Rista" <jr****@hotmail.com> wrote in message
news:eq*************@TK2MSFTNGP10.phx.gbl...
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.CurrentD omain.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.d ll");
cparams.ReferencedAssemblies.Add("System.Windows.F orms.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
jr****@hotmail.com


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


Nov 17 '05 #5

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

Similar topics

0
by: Philipp Seidel | last post by:
Hi there! I did not know, where this topic fits in, so I put it here. I have a minor problem with embedded resources, which puzzles me quite a lot. I'd be glad if anyone can help me on this: ...
0
by: Sherif ElMetainy | last post by:
Hello I am making an application that generates source code. I am facing some problems. 1- How can I generate code that uses the c# 'params' keyword to specify multiple arguments? I tried 2...
2
by: Kyle Kaitan | last post by:
I have an assembly (AppResources.dll) which contains a number of embedded resource files. Most of these are key/value pairs of relevant strings; a few are images and sounds; some more are XML...
0
by: Kyle Kaitan | last post by:
Is there a managed way to both read from *and* write to embedded resources?
16
by: Marina | last post by:
Hi, I am trying to find the minimum security settings to allow a windows control embedded in IE have full trust. If I give the entire Intranet zone full trust, this works. However, this is...
0
by: jcvoon | last post by:
Hi: My application will compile a source code and generate an executable assembly during run time, i'm able to generate the exe, but i don't know the correct way to link a resource file into...
11
by: Jan | last post by:
I'm using the CSharpCodeProvider to buils some assemblies @ runtime which are never saved as files (cp.GenerateInMemory = true;). The generated assemblies are hierachically dependent on each other...
7
by: Bilz | last post by:
I am planning to use the CSharpCodeProvider to generate some compiled functions in my app. In my current implementation, All of these functions are generated in one swipe... thus they all invoke...
2
by: CSharper | last post by:
I have a resource file I have created using ResourceWriter, next time when it runs, I want to check if the resource already exists and if does, I want to open it and add more objects to resource....
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.