CompilerParameters.ReferencedAssemblies issue  
Author Message
mabxsi





PostPosted: Common Language Runtime, CompilerParameters.ReferencedAssemblies issue Top

Hello,

I have a C# assembly that compiled in memory using CodeDomProvider.CreateProvider("C#"). I use CompilerParameters.ReferencedAssemblies to add the referenced assemblies by passing a filename as arguments (e.g. MyAsm.dll). For some reasons, the C# compiler cannot find my custom assemblies eventhough they are registered in the gac. It does find the .NET ones though such as system.dll.

Why is that I don't have these kind of problems with the Boo compiler which seems to look up the gac for referenced assemblies.

thanks for your help.

-mab



.NET Development4  
 
 
TaylorMichaelL





PostPosted: Common Language Runtime, CompilerParameters.ReferencedAssemblies issue Top

The compiler doesn't use the GAC. The GAC is a runtime only feature of .NET. The compiler must still use a formal file path. If you dump the command line used by the C# compiler, for example, you'll see full paths to each of the system binaries that you link against. These paths will be of the form c:\windows\microsoft.net\framework\v2.0.50727\file. These are the files you actually use when you use references in the IDE as well. The assembly loader (fusion) is the component that knows to load from the GAC first and then the formal path.

Therefore you should specify the full path to your custom assemblies when you add them to the referenced assemblies list.

Michael Taylor - 10/27/06


 
 
SagayaNathan





PostPosted: Common Language Runtime, CompilerParameters.ReferencedAssemblies issue Top

Hi i tried the same by giving the full path as follows:

C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\embed\3556a345\5a92a48b\assembly\dl3\becd7eec\802de0eb_80a6c601\Interop.Shell32.DLL

but still it throws FilenotFoundexception. Is there any other way. pls advice

thanks

Sagayanathan John

11-09-06


 
 
TaylorMichaelL





PostPosted: Common Language Runtime, CompilerParameters.ReferencedAssemblies issue Top

You're trying to do this in an ASP.NET app then. Are you hard coding the path or using the HttRuntime.CodegenDir The path that you gave is actually dependent upon the run of the web site. Each web app gets its own dynamically generated directory and even within that there are more dynamically generated settings. Your best bet is to create a static directory under your web app and then reference it directly rather than using the codegen directory.

Assuming the following web layout:
/Bin/web binaries

//Not tested
string strPath = Path.Combine(Server.MapPath("/Bin"), "interop.shell32.dll");

Note that if the binary is in the Bin directory then it might pick it up automatically. I don't know that I've tried it.

Michael Taylor - 11/9/06


 
 
SagayaNathan





PostPosted: Common Language Runtime, CompilerParameters.ReferencedAssemblies issue Top

Hi Mike,

Have got the solution for it. Thanks.

I included using System.Runtime.InteropServices and it just worked fine.

also gave the path as you said /bin/interop.shell32.dll

Sagayanathan John 11-10-2006