PC Review


Reply
Thread Tools Rate Thread

Compile code at runtime & Add Reference & FileNotFoundException

 
 
=?Utf-8?B?bm9ybWRAa25vcnJhc3NvY2lhdGVzLmNvbQ==?=
Guest
Posts: n/a
 
      18th Feb 2005
I have a text file which contains VB.NET code. The VB.NET code is actually a
Class that can contain code, which simply displays a message box or does
something more complicated (i.e Excel/Word Automation, communicate with the
DB and/or WebServices, talk to other classes). To achieve a complicated task,
this class would need reference to other custom assemblies (not part of .net
framework) that are possibly not installed to the GAC.

In my application, I use the System.CodeDom.Compiler.ICodeCompiler's
CompileAssemblyFromSource method to compile the text file code into an
assembly. Before the new assembly is created, I use the
ReferencedAssemblies.Add method to add reference to all the DLL files needed
by it. The ReferencedAssemblies.Add method is given the full path to a DLL
file, but the full path is a directory other than the main application's App
Direcotry(=where the Main.Exe is run from). For assemblies that are in the
GAC (such as System.dll and System.Windows.Forms.dll) this works fine; the
text file source code compiles without errors and I can call its methods,
etc. When adding reference, a full path is also specified for custom dll
files, but I get an FileNotFoundException. If I place the Custom Dll files
int the App Directory I do not get an exception and the source code compiles,
but this is not a feasible option.

I've tried setting the CompilerOptions parameter to the full path from
above, but that directory is not even probed. The property is set as follows:
cpCompilerParameters.CompilerOptions = "/lib:\Reports\CustomFiles\". Is
this the correct way of doing it?

Are there any other mechanisms by which I can tell the Main application
where to probe for these custom dlls?

Thanks for your help.
Norm
 
Reply With Quote
 
 
 
 
ewolfman
Guest
Posts: n/a
 
      26th Feb 2005
Hi,

I'm also using the CodeDOM namespace and perform runtime compilations.
I ran into this exact same problem, only my DLLs were placed in the
same folder as the executable, but it still failed. What I did was to
get the full path of the executing assembly and concatenate it to the
dll name. This solved the problem.

I know that you've written that this is not an option (placing the DLLs
in the same folder as the executable), but I've listed it anyway to
share with you the information that at least a full path is supposed to
work (worked for me...).

BTW: I have not set the compiler options at all in order to achieve
this effect, as you demonstrated.

I'd check the Compiler Errors collection, if you haven't already done
so. Maybe you'll find somehow the actual path it _is_ looking for, and
then you'll figure out what your problem is.

One more thing - is it possible that you're placing the DLLs on a
mapped network drive or something like that ? Did you try placing the
DLLs in an actual local hard drive directory ?

Another advice - you mentioned that if the DLLs are placed in the
executable's folder, it compiles ok. Try placing it there, but specify
the full path name anyway - is it still working ?

 
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
Compile VB6 Code Runtime 2006.ayan@gmail.com Microsoft VB .NET 1 24th Aug 2006 12:48 PM
Re: In-memory compile / System.IO.FileNotFoundException Guest Microsoft ASP .NET 0 8th Jun 2005 04:03 PM
Compile a c# code at runtime =?Utf-8?B?bXJWaXRoYW4=?= Microsoft Dot NET Framework 3 19th Jan 2005 04:26 PM
RE: Code on the fly & ReferencedAssemblies & FileNotFoundException Peter Huang Microsoft Dot NET Framework 1 30th Jun 2004 04:12 AM
Compile code at runtime? Adam Clauss Microsoft C# .NET 1 9th Oct 2003 06:07 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:08 PM.