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

[wasm] Fix tests failing due to trimming - System.Runtime.Loader #52088

Closed
wants to merge 1 commit into from

Commits on Apr 30, 2021

  1. [wasm] Fix tests failing due to trimming - System.Runtime.Loader

    Test failing with:
    
    ```
    fail: [FAIL] System.Runtime.Loader.Tests.AssemblyLoadContextTest.LoadAssemblyByPath_ValidUserAssembly
    info: System.TypeLoadException : Could not resolve type with token 01000014 from typeref (expected class 'System.MulticastDelegate' in assembly 'System.Runtime, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a')
    info:    at System.Reflection.RuntimeModule.GetTypes()
    info:    at System.Reflection.Assembly.GetTypes()
    info:    at System.Reflection.Assembly.get_DefinedTypes()
    info:    at System.Runtime.Loader.Tests.AssemblyLoadContextTest.LoadAssemblyByPath_ValidUserAssembly()
    info:    at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
    ```
    
    This is failing while trying to enumerate the types on a dependent test
    assembly - `System.Runtime.Loader.Test.Assembly`. This assembly is
    loaded by the test explicitly, into an ALC. But it is loaded from the
    assembly's embedded resources.
    
    The main test project(`System.Runtime.Loader.Tests.csproj`) has:
    ```xml
        <ProjectReference Include="System.Runtime.Loader.Test.Assembly\System.Runtime.Loader.Test.Assembly.csproj"
                          ReferenceOutputAssembly="false"
                          OutputItemType="EmbeddedResource" />
    ```
    
    - This will cause the referenced project to get built
        - And the assembly(`System.Runtime.Loader.Test.Assembly.dll`) added to `@(EmbeddedResource)`
        - but since we have `ReferenceOutputAssembly=false`, it won't be added
          to the list of references used for compiling the main tests assembly
          (`System.Runtime.Loader.Tests`).
          - but this also means that the test assembly from the referenced
            project does *not* get added to the list of assemblies to be linked.
    
    - The result of all this is that when trimming:
        - the linker has the set of assemblies to trim, edits the
          assemblies, and updates the metadata tokens (type references, for
          example) to be consistent within that set.
        - Since, `*Test.Assembly.dll` was *not* in the above set, it still
          has some old tokens which are no longer valid.
          - and that fails when resolving the tokens in the `*Test.Assembly`
            to assemblies like `System.Runtime`.
    
    - the fix is to add such assemblies to `@(ManagedAssemblyToLink)`, so
      they are included in the linker's set.
    
    Fixes dotnet#51893
    radical committed Apr 30, 2021
    Configuration menu
    Copy the full SHA
    fff9070 View commit details
    Browse the repository at this point in the history