未验证 提交 d836fd3f 编写于 作者: S Steve Molloy 提交者: GitHub

Don't fallback to PNSE, and give a more descriptive error message. (#88804)

* Don't fallback to PNSE, and give a more descriptive error message.

* CodeGeneratorConversionException is internal. Wrap it before re-throwing.

* Update src/libraries/System.Private.Xml/src/System/Xml/Serialization/Compilation.cs

Fixing comment about lack of compiler at runtime
Co-authored-by: NJan Kotas <jkotas@microsoft.com>

* Update Compilation.cs

Remove conditional code that was not needed.

---------
Co-authored-by: NMatt Connew <mconnew@users.noreply.github.com>
Co-authored-by: NJan Kotas <jkotas@microsoft.com>
上级 34b6db9a
...@@ -3426,6 +3426,9 @@ Usage: dotnet {0} [--assembly &lt;assembly file path&gt;] [--type &lt;type name& ...@@ -3426,6 +3426,9 @@ Usage: dotnet {0} [--assembly &lt;assembly file path&gt;] [--type &lt;type name&
<data name="GenerateSerializerNotFound" xml:space="preserve"> <data name="GenerateSerializerNotFound" xml:space="preserve">
<value>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.</value> <value>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.</value>
</data> </data>
<data name="CodeGenConvertError" xml:space="preserve">
<value>CodeGenError({0}): Cannot convert source type [{1}] to target type [{2}].</value>
</data>
<data name="CompilingScriptsNotSupported" xml:space="preserve"> <data name="CompilingScriptsNotSupported" xml:space="preserve">
<value>Compiling JScript/CSharp scripts is not supported</value> <value>Compiling JScript/CSharp scripts is not supported</value>
</data> </data>
......
...@@ -1628,7 +1628,7 @@ internal sealed class CodeGeneratorConversionException : Exception ...@@ -1628,7 +1628,7 @@ internal sealed class CodeGeneratorConversionException : Exception
private readonly string _reason; private readonly string _reason;
public CodeGeneratorConversionException(Type sourceType, Type targetType, bool isAddress, 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; _sourceType = sourceType;
_targetType = targetType; _targetType = targetType;
......
...@@ -59,9 +59,6 @@ internal TempAssembly(XmlMapping[] xmlMappings, Type?[] types, string? defaultNa ...@@ -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) if (!containsSoapMapping && !TempAssembly.UseLegacySerializerGeneration)
{ {
try try
...@@ -69,19 +66,18 @@ internal TempAssembly(XmlMapping[] xmlMappings, Type?[] types, string? defaultNa ...@@ -69,19 +66,18 @@ internal TempAssembly(XmlMapping[] xmlMappings, Type?[] types, string? defaultNa
_assembly = GenerateRefEmitAssembly(xmlMappings, types); _assembly = GenerateRefEmitAssembly(xmlMappings, types);
} }
// Only catch and handle known failures with RefEmit // 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... // Add other known exceptions here...
// //
} }
else else
{
fallbackToCSharpAssemblyGeneration = true;
}
if (fallbackToCSharpAssemblyGeneration)
{ {
throw new PlatformNotSupportedException(SR.CompilingScriptsNotSupported); throw new PlatformNotSupportedException(SR.CompilingScriptsNotSupported);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册