End Google Ads 201810 - BS.net 01 --> Have some issues and questions about creating a .dll from code in the form of a string array and a file. I seem to be close, but errors are raised when the code tries to creat the .dll.

Main question is, does the 'OutputAssembly' refer to the file name to create? Whenever I run the code below it says it could not find the file that 'cp.OutputAssembly' is set to. Also if this line is commented out, it says it could not find a randomly named file in a temporary directory.

The other question I have is if there is any difference between creating the .dll from an existing file or a string array. I plan on having the system create a common .dll for both the main program and for other .dll's the main program creates. These non-common .dll's can then be used directly in other programs.

This code is to create the common .dll .

public CompilerResults CompileImageAquisition(string OutputFile)
{
CodeDomProvider provider = CodeDomProvider.CreateProvider("CSharp");

CompilerParameters cp = new CompilerParameters();

CodeTypeReferenceCollection cref = new CodeTypeReferenceCollection();

cp.OutputAssembly = OutputFile;
cp.GenerateInMemory = false;
cp.TreatWarningsAsErrors = false;
cp.ReferencedAssemblies.Add("C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework\\.NETFramework\\v4.0\\PresentationCore.dll");
cp.ReferencedAssemblies.Add("System.Drawing.dll");
cp.ReferencedAssemblies.Add("C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework\\.NETFramework\\v4.0\\System.Windows.Forms.dll");
cp.ReferencedAssemblies.Add("C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework\\.NETFramework\\v4.0\\System.XML.dll");

CompilerResults cr = provider.CompileAssemblyFromFile(cp, ImageCoderSource********);

if (cr.Errors.Count > 0)
{
// Display compilation errors.
Console.WriteLine("Errors building {0} into {1}", ImageCoderSource********, cr.PathToAssembly);
foreach (CompilerError ce in cr.Errors)
{
Console.WriteLine(" {0}", ce.ToString());
Console.WriteLine();
}
}
else
{
// Display a successful compilation message.
Console.WriteLine("Source {0} built into {1} successfully.", ImageCoderSource********, cr.PathToAssembly);
}

return cr;
}

modified on Wednesday, July 22, 2009 6:51 AM