473,396 Members | 1,766 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.

How to define the path for runtime compiled assembly


I am compiling and executing c# code at runtime and I need to define in
CompilerParameters.ReferencedAssemblies one of my own assemblies together
with the standard System.dll u others.

Example:

// compiler options
System.CodeDom.Compiler.CompilerParameters options = new
System.CodeDom.Compiler.CompilerParameters();
options.GenerateExecutable = false; // result is a dll
options.GenerateInMemory = true;
//options.CompilerOptions = "/target:library";
options.MainClass = "MyClass";
options.ReferencedAssemblies.AddRange(new string[]{"System.dll",
"System.Data.dll",
System.Windows.Forms.Application.StartupPath + @"\MyAssembly.dll"});
********
options.IncludeDebugInformation = false;

// create the compilker
ICodeCompiler compiler = (new
Microsoft.CSharp.CSharpCodeProvider()).CreateCompi ler();

// build and look for compiler errors
System.CodeDom.Compiler.CompilerResults result =
compiler.CompileAssemblyFromSource(options, source.ToString());

From the above code, on the line highlighted (*) if I don't define the
Application.StartupPath as the directory where to found my own assembly, the
"File not found" exception is thrown.

But that fact forces me to always define the location of the assembly as
same as the application startup path (where the main .exe resides).

The above code belongs also to other assembly used in applications and not
the application per se. So, that assembly is tied to reference the other
assembly used, with that path.

Then the question is: how can I do in order to avoid the path dependency of
the referenced assembly as described above ?

Thanks in advance.

Luis Arvayo

Jun 6 '06 #1
2 10920
That code is choosing to use applicationStartupPath

System.Windows.Forms.Application.StartupPath + @"\MyAssembly.dll"

You could use whatever path you would like there? Pass in a path from the
code calling your method .. use the executing assembly to get its path?
There are a score of ways of doing this.

I guess I am not following the question.

Cheers,

Greg Young
MVP - C#
http://geekswithblogs.net/gyoung
"Luis Arvayo" <am**********@prodigy.net.mx> wrote in message
news:uc**************@TK2MSFTNGP03.phx.gbl...

I am compiling and executing c# code at runtime and I need to define in
CompilerParameters.ReferencedAssemblies one of my own assemblies together
with the standard System.dll u others.

Example:

// compiler options
System.CodeDom.Compiler.CompilerParameters options = new
System.CodeDom.Compiler.CompilerParameters();
options.GenerateExecutable = false; // result is a dll
options.GenerateInMemory = true;
//options.CompilerOptions = "/target:library";
options.MainClass = "MyClass";
options.ReferencedAssemblies.AddRange(new string[]{"System.dll",
"System.Data.dll",
System.Windows.Forms.Application.StartupPath + @"\MyAssembly.dll"});
********
options.IncludeDebugInformation = false;

// create the compilker
ICodeCompiler compiler = (new
Microsoft.CSharp.CSharpCodeProvider()).CreateCompi ler();

// build and look for compiler errors
System.CodeDom.Compiler.CompilerResults result =
compiler.CompileAssemblyFromSource(options, source.ToString());

From the above code, on the line highlighted (*) if I don't define the
Application.StartupPath as the directory where to found my own assembly,
the "File not found" exception is thrown.

But that fact forces me to always define the location of the assembly as
same as the application startup path (where the main .exe resides).

The above code belongs also to other assembly used in applications and not
the application per se. So, that assembly is tied to reference the other
assembly used, with that path.

Then the question is: how can I do in order to avoid the path dependency
of the referenced assembly as described above ?

Thanks in advance.

Luis Arvayo

Jun 6 '06 #2
Hello,

Thanks for your answer.

I hope I can explain more clearly.

I have two assemblies. The assembly (we can call it assembly 1) that
compiles code at runtime and that depends on "MyAssembly.dll" (this is
assembly 2).

If I define the code inside assembly 1 like this:

options.ReferencedAssemblies.AddRange(new string[]{"System.dll",
"System.Data.dll", "MyAssembly.dll"});
Then a "File not found" for the "MyAssembly.dll" (or assembly 2) is raised.
that is to say. NET cannot find assembly 2.

But if I define this way:
Code inside assembly 1 :

options.ReferencedAssemblies.AddRange(new string[]{"System.dll",
"System.Data.dll",
System.Windows.Forms.Application.StartupPath + @"\MyAssembly.dll"});
Then no error is raised.

But I don't want to tell to the developer/customer:

"You must place assembly 2 on the Application.Startup subdirectory".

Is there a more general solution in order to that .NET can find assembly 2
withouth defining the full path ?
That is to say, I need to define it in a more general solution. But the
question is how to do that ?
Thanks.

"Greg Young" <dr*******************@hotmail.com> escribió en el mensaje
news:eA**************@TK2MSFTNGP04.phx.gbl...
That code is choosing to use applicationStartupPath

System.Windows.Forms.Application.StartupPath + @"\MyAssembly.dll"

You could use whatever path you would like there? Pass in a path from the
code calling your method .. use the executing assembly to get its path?
There are a score of ways of doing this.

I guess I am not following the question.

Cheers,

Greg Young
MVP - C#
http://geekswithblogs.net/gyoung
"Luis Arvayo" <am**********@prodigy.net.mx> wrote in message
news:uc**************@TK2MSFTNGP03.phx.gbl...

I am compiling and executing c# code at runtime and I need to define in
CompilerParameters.ReferencedAssemblies one of my own assemblies together
with the standard System.dll u others.

Example:

// compiler options
System.CodeDom.Compiler.CompilerParameters options = new
System.CodeDom.Compiler.CompilerParameters();
options.GenerateExecutable = false; // result is a dll
options.GenerateInMemory = true;
//options.CompilerOptions = "/target:library";
options.MainClass = "MyClass";
options.ReferencedAssemblies.AddRange(new string[]{"System.dll",
"System.Data.dll",
System.Windows.Forms.Application.StartupPath + @"\MyAssembly.dll"});
********
options.IncludeDebugInformation = false;

// create the compilker
ICodeCompiler compiler = (new
Microsoft.CSharp.CSharpCodeProvider()).CreateCompi ler();

// build and look for compiler errors
System.CodeDom.Compiler.CompilerResults result =
compiler.CompileAssemblyFromSource(options, source.ToString());

From the above code, on the line highlighted (*) if I don't define the
Application.StartupPath as the directory where to found my own assembly,
the "File not found" exception is thrown.

But that fact forces me to always define the location of the assembly as
same as the application startup path (where the main .exe resides).

The above code belongs also to other assembly used in applications and
not the application per se. So, that assembly is tied to reference the
other assembly used, with that path.

Then the question is: how can I do in order to avoid the path dependency
of the referenced assembly as described above ?

Thanks in advance.

Luis Arvayo


Jun 7 '06 #3

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

Similar topics

10
by: jojobar | last post by:
Hello, I am trying to use vs.net 2005 to migrate a project originally in vs.net 2003. I started with creation of a "web site", and then created folders for each component of the site. I read...
2
by: SLE | last post by:
Hi there, We have a class method which is invoked through Remoting/IIS. Within this class method, we need to get the physical path of the assembly (dll) in which the method is executing. we have...
2
by: Charles Leonard | last post by:
I have a web service running impersonation of a domain account on Windows Server 2003. I need to access a share which the Web Service classes, themselves, appear to be able to create and access. ...
0
by: Charlie Calvert | last post by:
I want to use some pragma's in C# code written against .NET 2.0. Somewhat ironically, I find that these Pragma's won't work when I try to compile the same code against .NET 1.X. That is, when I'm...
2
by: theinvisibleGhost | last post by:
I'm trying to work out if theres a way to get the file path of my assembly. That is not the Application path. My assembly is a plugin to another project. I need to know the location of my...
0
by: raghu sunkara | last post by:
Hi, Can I Change Resources In A Compiled Assembly At Runtime.I Need To Modify A String Resource Which is Embedded in Assembly. Thanks, Raghu
4
by: james | last post by:
Hi All, Would anyone mind going over how to strong name an assembly after it has been compiled? I was looking at AL.exe, but it won't take in .dll files. I'm not sure if I can strip out the...
0
by: =?Utf-8?B?SmF0aW5kZXI=?= | last post by:
Hi, I have written dlls in c# that are being used by other applications. My application works fine if I add these dlls to executable folder,but when I place these dlls in another folder my...
0
by: David Rutten | last post by:
Hello, this is a bit of a complicated issue, I'll try to be succinct. 1) my application allows people to add 'scripts' to it. 2) these scripts are written in VB.NET or C#.NET language, and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.