Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XmlSerializer.Serialize doesn't work when using TrimMode=link #1454

Closed
rolfbjarne opened this issue Aug 26, 2020 · 1 comment
Closed

XmlSerializer.Serialize doesn't work when using TrimMode=link #1454

rolfbjarne opened this issue Aug 26, 2020 · 1 comment

Comments

@rolfbjarne
Copy link
Member

Repro: consoleapp-bfe9f43.zip

Run make linked to run with TrimMode=link, and make notlinked to run the same command, except without setting TrimMode.

$ make linked
** Executing linked app
bin/Debug/netcoreapp5.0/osx-x64/publish/myproject
❌ failed: System.InvalidOperationException: There was an error reflecting type 'LinkSdk.Serialization.XmlSerializationTest.Response'.
 ---> System.InvalidOperationException: There was an error reflecting property 'DataUpdates'.
 ---> System.InvalidOperationException: There was an error reflecting type 'LinkSdk.Serialization.XmlSerializationTest.DataUpdates'.
 ---> System.NullReferenceException: Object reference not set to an instance of an object.
   at System.RuntimeType.RuntimeTypeCache.GetDefaultMemberName()
   at System.RuntimeType.GetDefaultMemberName()
   at System.RuntimeType.GetDefaultMembers()
   at System.Xml.Serialization.TypeScope.GetDefaultIndexer(Type type, String memberInfo)
   at System.Xml.Serialization.TypeScope.ImportTypeDesc(Type type, MemberInfo memberInfo, Boolean directReference)
   at System.Xml.Serialization.TypeScope.GetTypeDesc(Type type, MemberInfo source, Boolean directReference, Boolean throwOnError)
   at System.Xml.Serialization.StructModel.GetPropertyModel(PropertyInfo propertyInfo)
   at System.Xml.Serialization.StructModel.GetFieldModel(MemberInfo memberInfo)
   at System.Xml.Serialization.XmlReflectionImporter.InitializeStructMembers(StructMapping mapping, StructModel model, Boolean openModel, String typeName, RecursionLimiter limiter)
   at System.Xml.Serialization.XmlReflectionImporter.ImportStructLikeMapping(StructModel model, String ns, Boolean openModel, XmlAttributes a, RecursionLimiter limiter)
   at System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping(TypeModel model, String ns, ImportContext context, String dataType, XmlAttributes a, Boolean repeats, Boolean openModel, RecursionLimiter limiter)
   --- End of inner exception stack trace ---
   at System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping(TypeModel model, String ns, ImportContext context, String dataType, XmlAttributes a, Boolean repeats, Boolean openModel, RecursionLimiter limiter)
   at System.Xml.Serialization.XmlReflectionImporter.ImportAccessorMapping(MemberMapping accessor, FieldModel model, XmlAttributes a, String ns, Type choiceIdentifierType, Boolean rpc, Boolean openModel, RecursionLimiter limiter)
   at System.Xml.Serialization.XmlReflectionImporter.ImportFieldMapping(StructModel parent, FieldModel model, XmlAttributes a, String ns, RecursionLimiter limiter)
   at System.Xml.Serialization.XmlReflectionImporter.InitializeStructMembers(StructMapping mapping, StructModel model, Boolean openModel, String typeName, RecursionLimiter limiter)
   --- End of inner exception stack trace ---
   at System.Xml.Serialization.XmlReflectionImporter.InitializeStructMembers(StructMapping mapping, StructModel model, Boolean openModel, String typeName, RecursionLimiter limiter)
   at System.Xml.Serialization.XmlReflectionImporter.ImportStructLikeMapping(StructModel model, String ns, Boolean openModel, XmlAttributes a, RecursionLimiter limiter)
   at System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping(TypeModel model, String ns, ImportContext context, String dataType, XmlAttributes a, Boolean repeats, Boolean openModel, RecursionLimiter limiter)
   --- End of inner exception stack trace ---
   at System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping(TypeModel model, String ns, ImportContext context, String dataType, XmlAttributes a, Boolean repeats, Boolean openModel, RecursionLimiter limiter)
   at System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping(TypeModel model, String ns, ImportContext context, String dataType, XmlAttributes a, RecursionLimiter limiter)
   at System.Xml.Serialization.XmlReflectionImporter.ImportElement(TypeModel model, XmlRootAttribute root, String defaultNamespace, RecursionLimiter limiter)
   at System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping(Type type, XmlRootAttribute root, 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

$ make notlinked
** Executing notlinked app
bin/Debug/netcoreapp5.0/osx-x64/publish/myproject
✅ succeeded: LinkSdk.Serialization.XmlSerializationTest+Response
$ dotnet --version
5.0.100-rc.1.20414.5
@marek-safar
Copy link
Contributor

Moved to correct repo

rolfbjarne added a commit to rolfbjarne/xamarin-macios that referenced this issue Aug 26, 2020
…NET due to a linker bug.

Ref: dotnet/linker#1454

Fixes this link sdk test failure:

    LinkSdk.Serialization.XmlSerializationTest
        [FAIL] Bug1820_GenericList : System.ArgumentNullException : Value cannot be null. (Parameter 'obj')
            at System.Reflection.Emit.ModuleBuilder.GetToken(MemberInfo member, Boolean create_open_instance)
            at System.Reflection.Emit.ModuleBuilderTokenGenerator.GetToken(MemberInfo member, Boolean create_open_instance)
            at System.Reflection.Emit.ILGenerator.Emit(OpCode opcode, ConstructorInfo con)
            at System.Xml.Serialization.CodeGenerator.Call(ConstructorInfo ctor)
            at System.Xml.Serialization.XmlSerializationILGen.GenerateSerializerContract(String className, XmlMapping[] xmlMappings, Type[] types, String readerType, String[] readMethods, String writerType, String[] writerMethods, Dictionary`2 serializers)
            at System.Xml.Serialization.TempAssembly.GenerateRefEmitAssembly(XmlMapping[] xmlMappings, Type[] types, String defaultNamespace)
            at System.Xml.Serialization.TempAssembly..ctor(XmlMapping[] xmlMappings, Type[] types, String defaultNamespace, String location)
            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 [...]/xamarin-macios/tests/linker/ios/link sdk/Bug1820Test.cs:line 38
            at LinkSdk.Serialization.XmlSerializationTest.Response.Deserialize(String xml) in [...]/xamarin-macios/tests/linker/ios/link sdk/Bug1820Test.cs:line 48
            at LinkSdk.Serialization.XmlSerializationTest.Bug1820_GenericList() in [...]/xamarin-macios/tests/linker/ios/link sdk/Bug1820Test.cs:line 166
            at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
spouliot pushed a commit to spouliot/xamarin-macios that referenced this issue Mar 31, 2021
…est in .NET due to a linker bug."

This reverts commit 9cbf145.

The original issue dotnet/linker#1454 -> dotnet/runtime#41389 was fixed a while ago.
dalexsoto pushed a commit to xamarin/xamarin-macios that referenced this issue Apr 2, 2021
…est in .NET due to a linker bug." (#11053)

This reverts commit 9cbf145.

The original issue dotnet/linker#1454 -> dotnet/runtime#41389 was fixed a while ago.

Co-authored-by: Sebastien Pouliot <sebastien.pouliot@microsoft.com>
tj-devel709 pushed a commit to xamarin/xamarin-macios that referenced this issue Apr 7, 2021
…est in .NET due to a linker bug." (#11053)

This reverts commit 9cbf145.

The original issue dotnet/linker#1454 -> dotnet/runtime#41389 was fixed a while ago.

Co-authored-by: Sebastien Pouliot <sebastien.pouliot@microsoft.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants