Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CodeDomProvider.CreateCompiler() is obsolete

Tags:

c#

obsolete

CSharpCodeProvider codeProvider = new CSharpCodeProvider();
ICodeCompiler MyCompiler = codeProvider.CreateCompiler();
CompilerParameters myParameters = new CompilerParameters();
myParameters.GenerateExecutable = true;
myParameters.OutputAssembly = @"prog.exe";
myParameters.TreatWarningsAsErrors = false;
CompilerResults results = myCompiler.CompileAssemblyFromFile(myParameters,"prog.txt");

How can I write this code to eliminate this warning:

System.CodeDom.Compiler.CodeDomProvider.CreateCompiler()' is obsolete: '"Callers should not use the ICodeCompiler interface and should instead use the methods directly on the CodeDomProvider class. Those inheriting from CodeDomProvider must still implement this interface, and should exclude this warning or also obsolete this method.**

like image 299
mkam Avatar asked Jan 18 '13 19:01

mkam


1 Answers

Use this method instead:

CodeDomProvider provider = CodeDomProvider.CreateProvider("CSharp");

Extended:

if (CodeDomProvider.IsDefinedLanguage(language))
{
    CodeDomProvider provider = CodeDomProvider.CreateProvider(language);
    // ...
}
else
    Console.WriteLine("ERROR");
like image 142
Tommaso Belluzzo Avatar answered Oct 06 '22 01:10

Tommaso Belluzzo