Skip to content

XmlSerializer tries to use Reflection.Emit even if RuntimeFeature.IsDynamicCodeSupported is false #59167

Closed

Description

@rolfbjarne

Description

We have a test case that fails with when IsDynamicCodeSupported=false (when executing in a FullAOT scenario on an iOS device):

[FAIL] Bug1820_GenericList : System.TypeLoadException : Could not load type 'Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializer1' from assembly 'Microsoft.GeneratedCode, Version=1.0.0.0' because the parent type is sealed.
    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()
    at LinkSdk.Serialization.XmlSerializationTest.Response.Deserialize(String xml)
    at LinkSdk.Serialization.XmlSerializationTest.Bug1820_GenericList()
    at System.Reflection.RuntimeMethodInfo.Invoke(Object , BindingFlags , Binder , Object[] , CultureInfo )

the actual test failure message is misleading: the problem is that RuntimeFeature.IsDynamicCodeSupported is false, so XmlSerializer shouldn't try to use Reflection.Emit in the first place.

Configuration

.NET RC 1

Regression?

With regards to legacy Xamarin.iOS: yes.

Activity

  1. ghost added
    untriaged
    on Sep 15, 2021
  2. MichalStrehovsky commented on Sep 16, 2021

    @MichalStrehovsky
    Member

    @marek-safar Do we need an issue making sure we run libraries tests with the interpreter disabled? This feels like something that should have been caught in libs tests.

  3. added this to the 6.0.0 milestone on Sep 16, 2021
  4. removed
    untriaged
    on Sep 16, 2021
  5. marek-safar commented on Sep 16, 2021

    @marek-safar
    Contributor

    @eerhardt could you help with getting this fixed for 6.0?

    @MichalStrehovsky I agree that ideally this should be uncovered in libraries AOT mode run but right now we can run only the runtime tests in this mode. Running all libraries tests under AOT won't be trivial as there is a lot of tests and a lot of assumptions to fix.

    /cc @SamMonoRT

  6. jkotas commented on Sep 17, 2021

    @jkotas
    Member

    We have a fix for this in the NativeAOT experiment that worked fine for us so far.

    Look for the XmlSerializer.cs delta in dotnet/runtimelab@runtime-main...feature/NativeAOT

  7. eerhardt commented on Sep 20, 2021

    @eerhardt
    Member

    Looking now.

  8. self-assigned this
    on Sep 20, 2021
  9. eerhardt commented on Sep 20, 2021

    @eerhardt
    Member

    Looks like I can port the changes of XmlSerializer from runtimelab / NativeAOT to runtime.

    My biggest question is: how can I test this to ensure it works? @rolfbjarne - Do you have instructions on how to run your test that is failing? So I can ensure my change fixes it?

  10. added a commit that references this issue on Sep 21, 2021
    9a82ac3
  11. ghost added
    in-pr
    on Sep 21, 2021
  12. rolfbjarne commented on Sep 21, 2021

    @rolfbjarne
    MemberAuthor

    @eerhardt AFAIK the only way to be sure this works is to actually run in a FullAOT scenario (i.e. on an iOS device), but I don't know how to make that happen inside dotnet/runtime (I'm guessing there already are FullAOT tests somewhere in dotnet/runtime?)

  13. SamMonoRT commented on Sep 21, 2021

    @SamMonoRT
    Member

    @imhameed - please can you verify if the newly enabled FullAOT lane has similar tests running ?

  14. added a commit that references this issue on Sep 23, 2021
    9114f77
  15. ghost removed
    in-pr
    on Sep 23, 2021
  16. added a commit that references this issue on Sep 23, 2021
    fd5a47d
  17. eerhardt commented on Sep 23, 2021

    @eerhardt
    Member

    Re-opening to backport to 6.0.

  18. added a commit that references this issue on Sep 24, 2021
    67a48ec
  19. ghost locked as resolved and limited conversation to collaborators on Nov 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions