Skip to content

Commit

Permalink
BUGFIX: Add Culture identifier to AssemblyDescriptor.FullName
Browse files Browse the repository at this point in the history
  • Loading branch information
Washi1337 committed Jun 24, 2023
1 parent 3cfacc2 commit 9155d46
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
8 changes: 6 additions & 2 deletions src/AsmResolver.DotNet/AssemblyDescriptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,16 @@ public string FullName
{
get
{
var publicKeyToken = GetPublicKeyToken();
string cultureString = !Utf8String.IsNullOrEmpty(Culture)
? Culture
: "neutral";

byte[]? publicKeyToken = GetPublicKeyToken();
string publicKeyTokenString = publicKeyToken is not null
? string.Join(string.Empty, publicKeyToken.Select(x => x.ToString("x2")))
: "null";

return $"{Name}, Version={Version}, PublicKeyToken={publicKeyTokenString}";
return $"{Name}, Version={Version}, Culture={cultureString}, PublicKeyToken={publicKeyTokenString}";
}
}

Expand Down
30 changes: 27 additions & 3 deletions test/AsmResolver.DotNet.Tests/AssemblyReferenceTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Reflection;
using System.Runtime.InteropServices;
using Xunit;

Expand All @@ -13,15 +14,15 @@ public void ReadName()
var assemblyRef = module.AssemblyReferences[0];
Assert.Equal("mscorlib", assemblyRef.Name);
}

[Fact]
public void ReadVersion()
{
var module = ModuleDefinition.FromBytes(Properties.Resources.HelloWorld);
var assemblyRef = module.AssemblyReferences[0];
Assert.Equal(new Version(4,0,0,0), assemblyRef.Version);
}

[Fact]
public void ReadPublicKeyOrToken()
{
Expand All @@ -33,6 +34,29 @@ public void ReadPublicKeyOrToken()
Assert.Equal(expectedToken, assemblyRef.GetPublicKeyToken());
}

[Fact]
public void GetFullNameCultureNeutralAssembly()
{
var name = new AssemblyName(KnownCorLibs.MsCorLib_v4_0_0_0.FullName);
Assert.Equal("mscorlib", name.Name);
Assert.Equal(new Version(4,0,0,0), name.Version);
Assert.Equal(string.Empty, name.CultureName);
Assert.Equal(new byte[] {0xB7, 0x7A, 0x5C, 0x56, 0x19, 0x34, 0xE0, 0x89}, name.GetPublicKeyToken());
}

[Fact]
public void GetFullNameCultureNonNeutralAssembly()
{
var assembly = new AssemblyReference("SomeAssembly", new Version(1, 2, 3, 4));
assembly.Culture = "en-US";

var name = new AssemblyName(assembly.FullName);
Assert.Equal("SomeAssembly", name.Name);
Assert.Equal(new Version(1,2,3,4), name.Version);
Assert.Equal("en-US", name.CultureName);
Assert.Equal(Array.Empty<byte>(), name.GetPublicKeyToken());
}

[Fact]
public void CorLibResolution()
{
Expand All @@ -44,4 +68,4 @@ public void CorLibResolution()
Assert.Equal(assemblyDef.Version, assemblyDef.Version);
}
}
}
}

0 comments on commit 9155d46

Please sign in to comment.