System.CodeDom.Compiler.CompilerParameters.Referen cedAssemblies

IfYouSaySo

Well-known member
Joined
Jan 4, 2006
Messages
102
Location
Hermosa Beach, CA
Programming Experience
3-5
I have a program that dynamically compiles and runs code. It uses the System.CodeDom.Compiler namespace to achieve this. I recently ran into a problem where it does not seem to find certain assemblies when they are referenced in the compiler parameters. For example:

System.data.dll
System.xml.dll
System.Web.dll

are found, but the assemblies:

CrystalDecisions.Shared.dll
CrystalDecisions.CrystalReports.Engine.dll

are not. If I reference the CR dll's with a full pathname everything works OK, for example:

VB.NET:
Dim x As New System.CodeDom.Compiler.CompilerParameters
x.ReferencedAssemblies.Add("C:\Program Files\Common7\CrystalDecisions\1.1\Managed\CrystalDecisions.CrystalReports.Engine.dll")
 
' and then compile the code, it works ok...
 
' but this fails...
x.ReferencedAssemblies.Add("CrystalDecisions.Shared.dll")

My understanding is that these Crystal Reports DLL's are in the GAC, so I shouldn't need to give a full path. Definately if I do "gacutil -l" they show up in the output list. Am I missing something here?
 
During development (which is the mode you are in dynamically through code) one never references directly an assembly in GAC, always reference the local file. During runtime (after assembly is compiled) if the assembly referenced is installed and found in GAC that is the one that is used. This is the same procedure as when developing through the VS IDE.
 
I'm not sure if I quite understand your response, but let me put my question another way:

If I compile with this line:

vbc.exe /t:exe /r:CrystalDecisions.Shared.dll myprogram.vb

I get the error: The system cannot find the file specified.

But when I compile with:

vbc.exe /t:exe /r:"C:\Program Files\Common Files\Crystal Decisions\1.1\Managed\CrystalDecisions.Shared.dll" myprogram.exe

The compilation works OK.

Specifically, my confusion is that CrystalDecisions.Shared.dll is in the GAC, and I thought that this was a problem that the GAC was supposed to solve (i.e. assemblies in the GAC do not require an absolute path to the assembly when compiling). Am I wrong about that fact?

My understanding certainly holds true for things like:
System.dll, System.data.dll, System.Web.dll, System.XML.dll, etc. Because for these assemblies I do not need to specify the full path to the DLL on the compile line, but only the DLL name.

What is different between these two cases?
 
If you're using the Visual Studio Command Prompt the explanation for this is that the framework folder containing the framework libraries are included in the PATH variable. You can verify this with the clean 'path' command that will list this environment variable and the folder is standard X:\Windows\Microsoft.Net\Framework\vY.Y.YYYY\, this is where the framework assemblies reside for local reference and these are files used when the /r switch is applied for compile, these are also the files pointed to in the Add Reference dialog used inside the IDE.

Edit: Mind you also, employing private local assemblies is the preferred .Net way for class libraries, the GAC is an exception, only for use when explicit sharing is required, as documentation states.
 
Back
Top