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

System.Resources.Extensions fails to load due to missing binding redirect when transitively referenced (e.g. in test project) #50286

Closed
jnm2 opened this issue Mar 25, 2021 · 4 comments · Fixed by #50288
Assignees
Milestone

Comments

@jnm2
Copy link
Contributor

jnm2 commented Mar 25, 2021

Steps to reproduce:

   Test method Repro.Tests.Tests.Repro threw exception:
System.IO.FileLoadException: Could not load file or assembly 'System.Resources.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
  Stack Trace:
      at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMarkHandle stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName, ObjectHandleOnStack type)
   at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName)
   at System.RuntimeType.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark)
   at System.Type.GetType(String typeName, Boolean throwOnError)
   at System.Resources.ManifestBasedResourceGroveler.CreateResourceSet(Stream store, Assembly assembly)
   at System.Resources.ManifestBasedResourceGroveler.GrovelForResourceSet(CultureInfo culture, Dictionary`2 localResourceSets, Boolean tryParents, Boolean createIfNotExists, StackCrawlMark& stackMark)
   at System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo requestedCulture, Boolean createIfNotExists, Boolean tryParents, StackCrawlMark& stackMark)
   at System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo culture, Boolean createIfNotExists, Boolean tryParents)
   at System.Resources.ResourceManager.GetObject(String name, CultureInfo culture, Boolean wrapUnmanagedMemStream)
   at System.Resources.ResourceManager.GetObject(String name, CultureInfo culture)
   at Repro.Resources.get_Burning_ship_fb() in C:\Users\Joseph\Source\Repos\Repro\Repro\Resources.Designer.cs:line 68
   at Repro.Program.Main() in C:\Users\Joseph\Source\Repos\Repro\Repro\Program.cs:line 7
   at Repro.Tests.Tests.Repro() in C:\Users\Joseph\Source\Repos\Repro\Repro.Tests\Tests.cs:line 11

Upon inspection in both the real-world project and the attached repro, this is present in the main project's .config file but not in the test project's, even though the test project is transitively referencing System.Resources.Extensions:

      <dependentAssembly>
        <assemblyIdentity name="System.Resources.Extensions" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
      </dependentAssembly>

This workaround fixes the problem, but it should not be required to add this to projects that already transitively reference this package:

  <ItemGroup>
    <!-- Workaround for https://github.com/dotnet/sdk/issues/16522 -->
    <PackageReference Include="System.Resources.Extensions" Version="5.0.0" />
  </ItemGroup>
@dotnet-issue-labeler
Copy link

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

@jnm2
Copy link
Contributor Author

jnm2 commented Mar 25, 2021

This may be related to #39386. /cc @ericstj

@ericstj
Copy link
Member

ericstj commented Mar 26, 2021

I see. We should probably put this targets file into buildTransitive. Thanks for the report.

@ericstj ericstj self-assigned this Mar 26, 2021
@ericstj ericstj transferred this issue from dotnet/sdk Mar 26, 2021
@dotnet-issue-labeler dotnet-issue-labeler bot added area-System.Resources untriaged New issue has not been triaged by the area owner labels Mar 26, 2021
@ghost
Copy link

ghost commented Mar 26, 2021

Tagging subscribers to this area: @tarekgh, @buyaa-n, @krwq
See info in area-owners.md if you want to be subscribed.

Issue Details

Steps to reproduce:

   Test method Repro.Tests.Tests.Repro threw exception:
System.IO.FileLoadException: Could not load file or assembly 'System.Resources.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
  Stack Trace:
      at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMarkHandle stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName, ObjectHandleOnStack type)
   at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName)
   at System.RuntimeType.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark)
   at System.Type.GetType(String typeName, Boolean throwOnError)
   at System.Resources.ManifestBasedResourceGroveler.CreateResourceSet(Stream store, Assembly assembly)
   at System.Resources.ManifestBasedResourceGroveler.GrovelForResourceSet(CultureInfo culture, Dictionary`2 localResourceSets, Boolean tryParents, Boolean createIfNotExists, StackCrawlMark& stackMark)
   at System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo requestedCulture, Boolean createIfNotExists, Boolean tryParents, StackCrawlMark& stackMark)
   at System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo culture, Boolean createIfNotExists, Boolean tryParents)
   at System.Resources.ResourceManager.GetObject(String name, CultureInfo culture, Boolean wrapUnmanagedMemStream)
   at System.Resources.ResourceManager.GetObject(String name, CultureInfo culture)
   at Repro.Resources.get_Burning_ship_fb() in C:\Users\Joseph\Source\Repos\Repro\Repro\Resources.Designer.cs:line 68
   at Repro.Program.Main() in C:\Users\Joseph\Source\Repos\Repro\Repro\Program.cs:line 7
   at Repro.Tests.Tests.Repro() in C:\Users\Joseph\Source\Repos\Repro\Repro.Tests\Tests.cs:line 11

Upon inspection in both the real-world project and the attached repro, this is present in the main project's .config file but not in the test project's, even though the test project is transitively referencing System.Resources.Extensions:

      <dependentAssembly>
        <assemblyIdentity name="System.Resources.Extensions" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
      </dependentAssembly>

This workaround fixes the problem, but it should not be required to add this to projects that already transitively reference this package:

  <ItemGroup>
    <!-- Workaround for https://github.com/dotnet/sdk/issues/16522 -->
    <PackageReference Include="System.Resources.Extensions" Version="5.0.0" />
  </ItemGroup>
Author: jnm2
Assignees: ericstj
Labels:

area-System.Resources, untriaged

Milestone: -

@ericstj ericstj removed the untriaged New issue has not been triaged by the area owner label Mar 26, 2021
@ericstj ericstj added this to the 6.0.0 milestone Mar 26, 2021
@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Mar 26, 2021
@ghost ghost removed the in-pr There is an active PR which will close this issue when it is merged label Mar 26, 2021
@ghost ghost locked as resolved and limited conversation to collaborators Apr 25, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
No open projects
Development

Successfully merging a pull request may close this issue.

2 participants