Fody / Costura

Embed references as resources
MIT License
2.41k stars 275 forks source link

Can't locate embedded satellite assembly #912

Closed MikiraSora closed 2 months ago

MikiraSora commented 1 year ago

Please check all of the platforms you are having the issue on (if platform is not listed, it is not supported)

Component

AssemblyLoader.ReadFromEmbeddedResources() can't locate embedded satellite assembly because name contain uppercase letter https://github.com/Fody/Costura/blob/develop/src/Costura.Template/Common.cs#L134C7-L134C7 requestedAssemblyName.CultureInfo.Name may contain uppercase letters

Version of Library

5.7.0

Version of OS(s) listed above with issue

Win

Steps to Reproduce

  1. get Costura.Fody 5.7.0 from nuget
  2. run

Expected Behavior

locate embedded satellite assembly successfully

Actual Behavior

LLI6 H1F5WKT~2T1E@%37SJ

GeertvanHorrik commented 1 year ago

Excellent find. Are you interested in providing a fix? A few ways to help out could be:

  1. Write a failing unit test
  2. Include the actual fix

Thank you!

MikiraSora commented 1 year ago

I will try write a fix but I have to read and learn repo fully

MikiraSora commented 1 year ago

It's hard to compile source and take unit test. I don't think I have the ability to fix these codes. So I hope you can personally repair it, after all, the reason has already been found.

JerryJian commented 10 months ago

A workaround, at the entry point of the program, modify the assemblyNames cache:

static int Main(string[] args)
{
    var loader = typeof(Program).Assembly.GetType("Costura.AssemblyLoader");
    if (loader != null)
    {
        var field = loader.GetField("assemblyNames", BindingFlags.Static | BindingFlags.NonPublic);
        if (field != null && field.GetValue(null) is Dictionary<string, string> dict)
        {
            foreach (var item in dict.Keys.ToList())
            {
                if (item.Contains("zh-hans"))
                {
                    var upperName = item.Replace("zh-hans", "zh-Hans");
                    if (!dict.ContainsKey(upperName))
                    {
                        dict.Add(upperName, dict[item]);
                    }
                }
            }
        }
    }
    ...
}
MikiraSora commented 10 months ago

here is my method to solve : link

GeertvanHorrik commented 2 months ago

Now covered by unit tests.