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

CultureNotFoundException when decompiling a satellite assembly #2691

Closed
pvoosten opened this issue May 16, 2022 · 4 comments
Closed

CultureNotFoundException when decompiling a satellite assembly #2691

pvoosten opened this issue May 16, 2022 · 4 comments

Comments

@pvoosten
Copy link

Since version 7.2.0.6791-preview3, trying to extract the resources from a satellite assembly often results in the following stack trace:

System.Globalization.CultureNotFoundException: Only the invariant culture is supported in globalization-invariant mode. See https://aka.ms/GlobalizationInvariantMode for more information. (Parameter 'name')
it is an invalid culture identifier.
   at System.Globalization.CultureInfo..ctor(String name, Boolean useUserOverride)
   at System.Reflection.AssemblyName.set_CultureName(String value)
   at System.Reflection.Metadata.MetadataReader.GetAssemblyName(StringHandle nameHandle, Version version, StringHandle cultureHandle, BlobHandle publicKeyOrTokenHandle, AssemblyHashAlgorithm assemblyHashAlgorithm, AssemblyFlags flags)
   at System.Reflection.Metadata.AssemblyDefinition.GetAssemblyName()
   at ICSharpCode.Decompiler.Metadata.DotNetCorePathFinderExtensions.DetectTargetFrameworkId(PEReader assembly, String assemblyPath) in D:\GitWorkspace\ILSpy_72\ICSharpCode.Decompiler\Metadata\DotNetCorePathFinderExtensions.cs:line 56
   at ICSharpCode.Decompiler.Console.ILSpyCmdProgram.DecompileAsProject(String assemblyFileName, String outputDirectory) in D:\GitWorkspace\ILSpy_72\ICSharpCode.Decompiler.Console\IlspyCmdProgram.cs:line 217
   at ICSharpCode.Decompiler.Console.ILSpyCmdProgram.OnExecute(CommandLineApplication app) in D:\GitWorkspace\ILSpy_72\ICSharpCode.Decompiler.Console\IlspyCmdProgram.cs:line 101

In the previous version, 7.2.0.6702-preview2, the issue was not present yet.

To reproduce the issue, I used the following commands:

dotnet tool uninstall ilspycmd -g
dotnet tool install ilspycmd --version <version> -g
rm -Recurse <output-directory>\*
ilspycmd <assembly-name>.resources.dll -p -o <output-directory>

A workaround is to use an older version of ilspycmd.

@pvoosten pvoosten changed the title CultureNotFoundException when decompiling a satellite assembly since version CultureNotFoundException when decompiling a satellite assembly May 16, 2022
@siegfriedpammer
Copy link
Member

The error message hints at the following change: db6b085

However, this has been present in ilspycmd ever since version 7.1. Would you be able to provide an example for us to try to reproduce this error? Thanks!

@pvoosten
Copy link
Author

I crafted a simple example. The zip file contains the solution to create the contained satellite assemblies. The satellite assemblies can be found in Ilspy2691\ClasslibExample\bin\Debug\net6.0\nl or Ilspy2691\ClasslibExample\bin\Debug\net6.0\de

Ilspy2691.zip

@pvoosten
Copy link
Author

The fix for #2417 indeed caused the issue. Another workaround is to change %userprofile%.dotnet\tools.store\ilspycmd\7.2.1.6856\ilspycmd\7.2.1.6856\tools\net6.0\any\ilspycmd.runtimeconfig.json:

{
  "runtimeOptions": {
    "tfm": "net6.0",
    "framework": {
      "name": "Microsoft.NETCore.App",
      "version": "6.0.0"
    },
    "configProperties": {
      "System.GC.Server": true,
      "System.Globalization.Invariant": false, // was true
      "System.Globalization.PredefinedCulturesOnly": true,
      "System.Reflection.Metadata.MetadataUpdater.IsSupported": false
    }
  }
}

siegfriedpammer added a commit that referenced this issue May 17, 2022
This fails in culture-invariant mode (ilspycmd) when trying to work with satellite assemblies, because System.Reflection.AssemblyName tries to retrieve CultureInfo of the assembly culture.
@siegfriedpammer
Copy link
Member

Thank you for reporting this.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants