Note that, according to documentation, “Script blocks are supported only in .NET Framework. They are not supported on .NET Core or .NET 5.0 or later”. Try creating a new “Console App (.NET Framework)” project.
XSLT compile error-PlatformNotSupportedException: Compiling JScript/CSharp scripts is not supported
Hi Team,
I am calling an xslt in console application, the xslt has cdata section having a function. using cdata is causing the below issue, not calling any function in xslt is working as expected.
below is the console application code-
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Xml;
using System.Xml.Xsl;
using System.IO;
namespace ConsoleApp1
{
class Class3
{
public static void Main()
{
StringBuilder stringBuilder = new StringBuilder();
XslCompiledTransform xslt = new XslCompiledTransform();
XmlWriterSettings settings = new XmlWriterSettings();
XsltSettings xslt_setting = new XsltSettings();
xslt_setting.EnableScript = true;
settings.OmitXmlDeclaration = true;
settings.ConformanceLevel = ConformanceLevel.Fragment;
settings.CloseOutput = false;
string xml_string = System.IO.File.ReadAllText("xmlpath");
string xslt_string = System.IO.File.ReadAllText("xslt path");
byte[] byteArray = Encoding.UTF8.GetBytes(xslt_string);
var tmpFile = Path.GetTempFileName();
var tmpFileStream = System.IO.File.OpenWrite(tmpFile);
tmpFileStream.Write(byteArray, 0, byteArray.Length);
tmpFileStream.Close();
xslt.Load(tmpFile, xslt_setting, null);
byte[] byteArray1 = Encoding.UTF8.GetBytes(xml_string);
var tmpFile1 = Path.GetTempFileName();
var tmpFileStream1 = System.IO.File.OpenWrite(tmpFile1);
tmpFileStream1.Write(byteArray1, 0, byteArray1.Length);
tmpFileStream1.Close();
xslt.Transform(tmpFile1, XmlWriter.Create(stringBuilder, settings));
}
}
}
and error message is:
.net framework -.net core tool 3.1
Please help to resolve this issue