|
| 1 | +--- |
| 2 | +title: "Breaking change - XsltSettings.EnableScript property is obsolete" |
| 3 | +description: "Learn about the breaking change in .NET 10 where XsltSettings.EnableScript property is marked as obsolete." |
| 4 | +ms.date: 01/14/2025 |
| 5 | +ai-usage: ai-assisted |
| 6 | +ms.custom: https://github.com/dotnet/docs/issues/47504 |
| 7 | +--- |
| 8 | + |
| 9 | +# XsltSettings.EnableScript property is obsolete |
| 10 | + |
| 11 | +The <xref:System.Xml.Xsl.XsltSettings.EnableScript?displayProperty=nameWithType> property is now marked as obsolete with diagnostic ID `SYSLIB0062`. XSLT script blocks are supported only in .NET Framework and are not supported on .NET Core or .NET 5+. |
| 12 | + |
| 13 | +## Version introduced |
| 14 | + |
| 15 | +.NET 10 Preview 1 |
| 16 | + |
| 17 | +## Previous behavior |
| 18 | + |
| 19 | +Previously, the <xref:System.Xml.Xsl.XsltSettings.EnableScript?displayProperty=nameWithType> property could be set without any compiler warnings: |
| 20 | + |
| 21 | +- When set to `false`: script blocks were skipped (expected behavior anyway) |
| 22 | +- When set to `true`: a <xref:System.PlatformNotSupportedException> was thrown at runtime because script compilation is not supported |
| 23 | + |
| 24 | +```csharp |
| 25 | +using System.Xml.Xsl; |
| 26 | + |
| 27 | +// No compiler warnings in previous versions |
| 28 | +XsltSettings settings = new XsltSettings(); |
| 29 | +settings.EnableScript = true; // Would throw PlatformNotSupportedException at runtime |
| 30 | +``` |
| 31 | + |
| 32 | +## New behavior |
| 33 | + |
| 34 | +Starting in .NET 10, the <xref:System.Xml.Xsl.XsltSettings.EnableScript?displayProperty=nameWithType> property is marked as obsolete. Setting or accessing this property generates a compile-time warning `SYSLIB0062`. |
| 35 | + |
| 36 | +```csharp |
| 37 | +using System.Xml.Xsl; |
| 38 | + |
| 39 | +// Generates SYSLIB0062 warning |
| 40 | +XsltSettings settings = new XsltSettings(); |
| 41 | +settings.EnableScript = true; // Warning: SYSLIB0062: XsltSettings.EnableScript is obsolete |
| 42 | +``` |
| 43 | + |
| 44 | +## Type of breaking change |
| 45 | + |
| 46 | +This change can affect [source compatibility](../../categories.md#source-compatibility). |
| 47 | + |
| 48 | +## Reason for change |
| 49 | + |
| 50 | +The property was obsoleted to turn a runtime error into a build warning, providing better guidance for migration. Since XSLT script blocks are not supported on modern .NET implementations, this property had no legitimate use case and would only result in runtime exceptions when set to `true`. |
| 51 | + |
| 52 | +## Recommended action |
| 53 | + |
| 54 | +Call sites should be reviewed for any assumptions made about the behavior of this property. References to the property can most likely be removed since the property did not truly enable script blocks on modern .NET. |
| 55 | + |
| 56 | +Remove any references to `EnableScript` in your code: |
| 57 | + |
| 58 | +```csharp |
| 59 | +// Before |
| 60 | +XsltSettings settings = new XsltSettings(); |
| 61 | +settings.EnableScript = true; // Remove this line |
| 62 | +
|
| 63 | +// After |
| 64 | +XsltSettings settings = new XsltSettings(); |
| 65 | +// No need to set EnableScript |
| 66 | +``` |
| 67 | + |
| 68 | +If you need to create XSLT settings with document function enabled but script disabled (which is the default behavior), use: |
| 69 | + |
| 70 | +```csharp |
| 71 | +XsltSettings settings = new XsltSettings(enableDocumentFunction: true, enableScript: false); |
| 72 | +// Or simply use XsltSettings.Default which has EnableScript = false |
| 73 | +XsltSettings settings = XsltSettings.Default; |
| 74 | +``` |
| 75 | + |
| 76 | +## Affected APIs |
| 77 | + |
| 78 | +- <xref:System.Xml.Xsl.XsltSettings.EnableScript?displayProperty=fullName> |
0 commit comments