diff --git a/src/libraries/System.Private.Xml/src/Resources/Strings.resx b/src/libraries/System.Private.Xml/src/Resources/Strings.resx
index 10cdf232ba66a23c7b1570db60617d534d1b67b7..9fae0abca7c9fc2a09a2d0826cb13a43762991b0 100644
--- a/src/libraries/System.Private.Xml/src/Resources/Strings.resx
+++ b/src/libraries/System.Private.Xml/src/Resources/Strings.resx
@@ -3426,6 +3426,9 @@ Usage: dotnet {0} [--assembly <assembly file path>] [--type <type name&
Method 'System.Xml.Serialization.XmlSerializer.GenerateSerializer' was not found. This is likely because you are using an older version of the framework. Please update to .NET Core v2.1 or later.
+
+ CodeGenError({0}): Cannot convert source type [{1}] to target type [{2}].
+
Compiling JScript/CSharp scripts is not supported
diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Serialization/CodeGenerator.cs b/src/libraries/System.Private.Xml/src/System/Xml/Serialization/CodeGenerator.cs
index 20e9d52fa5867d7066c560e75941276a12a66608..a39da73d5832e931c62987f38142e4657515c31a 100644
--- a/src/libraries/System.Private.Xml/src/System/Xml/Serialization/CodeGenerator.cs
+++ b/src/libraries/System.Private.Xml/src/System/Xml/Serialization/CodeGenerator.cs
@@ -1628,7 +1628,7 @@ internal sealed class CodeGeneratorConversionException : Exception
private readonly string _reason;
public CodeGeneratorConversionException(Type sourceType, Type targetType, bool isAddress, string reason)
- : base()
+ : base(SR.Format(SR.CodeGenConvertError, reason, sourceType.ToString(), targetType.ToString()))
{
_sourceType = sourceType;
_targetType = targetType;
diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Serialization/Compilation.cs b/src/libraries/System.Private.Xml/src/System/Xml/Serialization/Compilation.cs
index dcb937e6a187ea2d85f72a93d901b0d1f4754871..8b87f1ce777564e5747ca01c1953ab0e7534df78 100644
--- a/src/libraries/System.Private.Xml/src/System/Xml/Serialization/Compilation.cs
+++ b/src/libraries/System.Private.Xml/src/System/Xml/Serialization/Compilation.cs
@@ -59,9 +59,6 @@ internal TempAssembly(XmlMapping[] xmlMappings, Type?[] types, string? defaultNa
}
}
- // We will make best effort to use RefEmit for assembly generation
- bool fallbackToCSharpAssemblyGeneration = false;
-
if (!containsSoapMapping && !TempAssembly.UseLegacySerializerGeneration)
{
try
@@ -69,19 +66,18 @@ internal TempAssembly(XmlMapping[] xmlMappings, Type?[] types, string? defaultNa
_assembly = GenerateRefEmitAssembly(xmlMappings, types);
}
// Only catch and handle known failures with RefEmit
- catch (CodeGeneratorConversionException)
+ catch (CodeGeneratorConversionException ex)
{
- fallbackToCSharpAssemblyGeneration = true;
+ // There is no CSharp-generating/compiling fallback in .Net Core because compilers are not part of the runtime.
+ // Instead of throwing a PNSE as a result of trying this "fallback" which doesn't exist, lets just let the
+ // original error bubble up.
+ //fallbackToCSharpAssemblyGeneration = true;
+ throw new InvalidOperationException(ex.Message, ex);
}
// Add other known exceptions here...
//
}
else
- {
- fallbackToCSharpAssemblyGeneration = true;
- }
-
- if (fallbackToCSharpAssemblyGeneration)
{
throw new PlatformNotSupportedException(SR.CompilingScriptsNotSupported);
}