Referencing the GAC When Compiling C# Code in Code
If you need to compile C# code from within code, a very common approach is to use the CSharpCodeProvider class.
Unfortunately, the compiler invoked by this class does not automatically reference the GAC for compilation.
If you know which specific DLLs you need to reference, you can add them to the CompilerParameters.ReferencedAssemblies collection.
Otherwise, you can follow the suggestions in this thread.














