I am trying to use the VBCodeProvider to dynamically compile an assembly. The problem I'm running in to is that I need to give the CompilerParameters class a list of referenced assemblies.
The code being used is this:
CompilerParameters parameters = new CompilerParameters();
parameters.ReferencedAssemblies.AddRange(AppDomain.CurrentDomain.GetAssemblies().Select(a => a.Location).ToArray());
parameters.GenerateExecutable = false;
parameters.GenerateInMemory = true;
parameters.IncludeDebugInformation = false;
CodeDomProvider provider = new Microsoft.VisualBasic.VBCodeProvider();
// Compile the assembly in memory.
CompilerResults results = provider.CompileAssemblyFromDom(parameters, compileUnit);
The problem is that when the provider.CompileAssemblyFromDom
line runs, it generates the following error:
vbc : Command line (0,0) : error BC2006: option 'r' requires':<file_list>'
However, if I use the CSharpCodeProvider
provider = new Microsoft.VisualBasic.CSharpCodeProvider();
everything works correctly.
Is this a known bug in the VBCodeProvider
?