user304582
user304582

Reputation: 2020

Using CSharpCodeProvider in .Net Core

I have some C# code that dynamically generates source code from SOAP WSDLs and Swagger documents, and then compiles it using the CSharpCodeProvider class's method called CompileAssemblyFromSource. Using .Net 4.8 this works fine, but in trying to port to .Net Core 3.0, I now get this error:

"Operation is not supported on this platform."

Is there support for this functionality in .Net Core, or is it likely to be added soon? Here's a simplified code extract:

CSharpCodeProvider codeProvider = new CSharpCodeProvider();
string[] m_References = new string[] { "System.dll", "System.Core.dll", "System.Data.dll", "System.Net.dll", "System.Net.Http.dll", "System.Runtime.Serialization.dll", "System.ServiceModel.dll", "System.Xml.dll" };
CompilerParameters compilerParameters = CreateCompilerParameters(m_References);
m_CompilerResults = codeProvider.CompileAssemblyFromSource(compilerParameters, m_SourceStringArray);
if (!m_CompilerResults.Errors.HasErrors)
{
    /* render UI using compiled code */
}
else
{
    /* log compiler errors */
}

Upvotes: 6

Views: 9923

Answers (1)

Alsein
Alsein

Reputation: 4775

It is obsoleted in .NET Core and you can use roslyn (github | nuget | docs) instead.

Upvotes: 10

Related Questions