XSLT compile error-PlatformNotSupportedException: Compiling JScript/CSharp scripts is not supported

Eva Baishya 61 Reputation points
2021-06-23T18:13:33.443+00:00

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:

108667-image.png

.net framework -.net core tool 3.1

Please help to resolve this issue

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,962 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Viorel 117.6K Reputation points
    2021-06-24T07:50:07.773+00:00

    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.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.