C# compiler error CS0006: metadata file is not found
- by Rob
I've built a c# compiler using the tutorial on MSDN and a few other resources including here, and I've gotten it to work until I add additional reference assemblies. My errors stem from adding "System.dll" and "System.Windows.Forms.dll" to the ReferenceAssemblies list.
here's my code:
private void SetUpCompilingParameters()
{
string ver = string.Format("{0}.{1}.{2}", Environment.Version.Major, Environment.Version.MajorRevision, Environment.Version.Build);
string libDir = string.Format(@"{0}", Environment.CurrentDirectory);
string raDir = @"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0";
string exWpfDir = string.Format(@"C:\WINDOWS\Microsoft.NET\Framework\v{0}\WPF", ver);
string exDir = string.Format(@"C:\WINDOWS\Microsoft.NET\Framework\v{0}", ver);
MyCompiler = new CSharpCodeProvider();
CompilingParam = new CompilerParameters();
CompilingParam.GenerateExecutable = false;
CompilingParam.GenerateInMemory = true;
CompilingParam.IncludeDebugInformation = false;
CompilingParam.TreatWarningsAsErrors = false;
CompilingParam.CompilerOptions = string.Format("/lib:{0}", libDir);
CompilingParam.CompilerOptions = string.Format("/lib:{0}", raDir);
CompilingParam.CompilerOptions = string.Format("/lib:{0}", exDir);
//CompilingParam.CompilerOptions = string.Format("/lib:{0}", exWpfDir);
CompilingParam.ReferencedAssemblies.Add("System.dll");
CompilingParam.ReferencedAssemblies.Add("System.Windows.Forms.dll");
}
As you can see, I've explicitly referenced directories in CompilerOptions but its not helping. I'd like to test the solution on here on stackoverflow
that utilizes:
CompilingParam.ReferencedAssemblies.Add(typeof(System.Xml.Linq.Extensions).Assembly.Location);
but I'm having trouble using it for the general System.dll etc...