Closed
Description
I'm not sure if this is a bug in the linker or the BCL, but if I enable the seal optimization:
<_ExtraTrimmerArgs>$(_ExtraTrimmerArgs) --enable-opt sealer</_ExtraTrimmerArgs>
then the xml serializer stops working with:
System.TypeLoadException: Could not load type 'Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializer1' from assembly 'Microsoft.GeneratedCode, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' because the parent type is sealed.
at System.Reflection.Emit.TypeBuilder.TermCreateClass(QCallModule , Int32 , ObjectHandleOnStack )
at System.Reflection.Emit.TypeBuilder.CreateTypeNoLock()
at System.Reflection.Emit.TypeBuilder.CreateTypeInfo()
at System.Xml.Serialization.XmlSerializationILGen.GenerateBaseSerializer(String , String , String , CodeIdentifiers )
at System.Xml.Serialization.TempAssembly.GenerateRefEmitAssembly(XmlMapping[] , Type[] , String )
at System.Xml.Serialization.TempAssembly..ctor(XmlMapping[] , Type[] , String , String )
at System.Xml.Serialization.XmlSerializer.GenerateTempAssembly(XmlMapping xmlMapping, Type type, String defaultNamespace, String location)
at System.Xml.Serialization.XmlSerializer.GenerateTempAssembly(XmlMapping xmlMapping, Type type, String defaultNamespace)
at System.Xml.Serialization.XmlSerializer..ctor(Type type, String defaultNamespace)
at System.Xml.Serialization.XmlSerializer..ctor(Type type)
at LinkSdk.Serialization.XmlSerializationTest.Response.get_Serializer() in /Users/rolf/test/dotnet/consoleapp/Program.cs:line 63
at LinkSdk.Serialization.XmlSerializationTest.Response.Deserialize(String xml) in /Users/rolf/test/dotnet/consoleapp/Program.cs:line 73
at LinkSdk.Serialization.XmlSerializationTest.Bug1820_GenericList() in /Users/rolf/test/dotnet/consoleapp/Program.cs:line 188
at App.Main() in /Users/rolf/test/dotnet/consoleapp/Program.cs:line 27
Repro:
consoleapp-18dd81d.zip
Download & extract & run "make linked notlinked" (you might have to adjust/remove NuGet.config depending on the version of .NET installed):
$ make linked notlinked
** Executing linked app
bin/Debug/net6.0/osx-x64/publish/myproject
❌ failed: System.TypeLoadException: Could not load type 'Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializer1' from assembly 'Microsoft.GeneratedCode, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' because the parent type is sealed.
at System.Reflection.Emit.TypeBuilder.TermCreateClass(QCallModule , Int32 , ObjectHandleOnStack )
at System.Reflection.Emit.TypeBuilder.CreateTypeNoLock()
at System.Reflection.Emit.TypeBuilder.CreateTypeInfo()
at System.Xml.Serialization.XmlSerializationILGen.GenerateBaseSerializer(String , String , String , CodeIdentifiers )
at System.Xml.Serialization.TempAssembly.GenerateRefEmitAssembly(XmlMapping[] , Type[] , String )
at System.Xml.Serialization.TempAssembly..ctor(XmlMapping[] , Type[] , String , String )
at System.Xml.Serialization.XmlSerializer.GenerateTempAssembly(XmlMapping xmlMapping, Type type, String defaultNamespace, String location)
at System.Xml.Serialization.XmlSerializer.GenerateTempAssembly(XmlMapping xmlMapping, Type type, String defaultNamespace)
at System.Xml.Serialization.XmlSerializer..ctor(Type type, String defaultNamespace)
at System.Xml.Serialization.XmlSerializer..ctor(Type type)
at LinkSdk.Serialization.XmlSerializationTest.Response.get_Serializer() in /Users/rolf/test/dotnet/consoleapp/Program.cs:line 63
at LinkSdk.Serialization.XmlSerializationTest.Response.Deserialize(String xml) in /Users/rolf/test/dotnet/consoleapp/Program.cs:line 73
at LinkSdk.Serialization.XmlSerializationTest.Bug1820_GenericList() in /Users/rolf/test/dotnet/consoleapp/Program.cs:line 188
at App.Main() in /Users/rolf/test/dotnet/consoleapp/Program.cs:line 27
** Executing notlinked app
bin/Debug/net6.0/osx-x64/publish/myproject
✅ succeeded: LinkSdk.Serialization.XmlSerializationTest+Response
$ dotnet --version
6.0.100-rc.2.21420.30
Binlogs:
binlogs.zip