1
votes

I have a Project that is meant to be used as an Add-In for Dynamics NAV. It is supposed to be shown in the currently used language with english being the standard. To ensure this I have a method that sets CurrentCulture and CurrentUICulture.

Inside a test project that runs outside Dynamics NAV, the forms are shown with the appropriate translations.

When using the add-In in Dynamics NAV though, the forms are always in english, dispite the current culture and current UI culture being set to the correct language (I checked this by debugging in multiple cases).

I have tried two setups:

  • localizable forms, where form1 contains form1.resx and form1.de.resx
  • resx-files resources.resx and resources.de.resx that are seperated from Form1 and called in the code right after InitializeComponent.

The result is the same in both cases:
Starting the program outside NAV: Translation succeeds
Starting the program from inside NAV: Always uses standard resources

Does anyone know if there is a detail i am missing?

1

1 Answers

0
votes

The issue was a very common one: The de-resources were compiled into a "de" folder and as a result NAV - like so often - was unable to find the files.

AssemblyResolve fixed this issue:

Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
    var location = Path.Combine(
        Path.GetDirectoryName(typeof(MyForm).Assembly.Location),
        CultureInfo.CurrentCulture.Parent.Name,
        args.Name.Substring(0, args.Name.IndexOf(",", StringComparison.OrdinalIgnoreCase)) + ".dll");

    if (File.Exists(location))
    {
        return Assembly.LoadFrom(location);
    }

    return null;
    }
}

The only detail to keep in mind is to subscribe to AssemblyResolve before the InitializeComponent function is executed.