diff --git a/src/Providers/ResxLocalizationProviderBase.cs b/src/Providers/ResxLocalizationProviderBase.cs index c96469ed..f76185e3 100644 --- a/src/Providers/ResxLocalizationProviderBase.cs +++ b/src/Providers/ResxLocalizationProviderBase.cs @@ -470,6 +470,13 @@ string TryGetNamespace(Type type) // remove ".resources" from the end foundResource = foundResource.Substring(0, foundResource.Length - ResourceFileExtension.Length); + if (TryCreateResourceManager(foundResource, assembly, out ResourceManager resourceManager)) + { + CacheResourceManager(resManKey, resourceManager); + + return resourceManager; + } + // First try the simple retrieval Type resourceManagerType; try @@ -519,27 +526,46 @@ bool MatchesDictTypeName(Type type) if (resManager == null) throw new ArgumentException(string.Format("No resource manager for dictionary '{0}' in assembly '{1}' found! ({1}.{0})", resourceDictionary, resourceAssembly)); - // Add the ResourceManager to the cachelist - Add(resManKey, resManager); + CacheResourceManager(resManKey, resManager); + } - try - { - // Look in all cultures and check available ressources. - foreach (var c in SearchCultures) - { - var rs = resManager.GetResourceSet(c, true, false); - if (rs != null) - AddCulture(c); - } - } - catch + // return the found ResourceManager + return resManager; + } + + private void CacheResourceManager(string resManKey, ResourceManager resManager) + { + // Add the ResourceManager to the cachelist + Add(resManKey, resManager); + + try + { + // Look in all cultures and check available ressources. + foreach (var c in SearchCultures) { - // ignored + var rs = resManager.GetResourceSet(c, true, false); + if (rs != null) + AddCulture(c); } } + catch + { + // ignored + } + } - // return the found ResourceManager - return resManager; + private bool TryCreateResourceManager(string resourceManagerBaseName, Assembly resourceManagerAssembly, out ResourceManager resourceManager) + { + try + { + resourceManager = new ResourceManager(resourceManagerBaseName, resourceManagerAssembly); + } + catch + { + resourceManager = null; + } + + return resourceManager != null; } private ResourceManager GetResourceManagerFromType(IReflect type) @@ -561,9 +587,9 @@ private ResourceManager GetResourceManagerFromType(IReflect type) return null; } } - #endregion +#endregion - #region ILocalizationProvider implementation +#region ILocalizationProvider implementation /// /// Uses the key and target to build a fully qualified resource key (Assembly, Dictionary, Key) /// @@ -711,6 +737,6 @@ public virtual object GetLocalizedObject(string key, DependencyObject target, Cu /// An observable list of available cultures. /// public ObservableCollection AvailableCultures { get; protected set; } - #endregion +#endregion } } diff --git a/tests/HelloWorldWPF.NoDesignFiles.sln b/tests/HelloWorldWPF.NoDesignFiles.sln new file mode 100644 index 00000000..699c6d81 --- /dev/null +++ b/tests/HelloWorldWPF.NoDesignFiles.sln @@ -0,0 +1,51 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.30011.22 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WPFLocalizeExtension", "..\src\WPFLocalizeExtension.csproj", "{3B2FA6D1-6EC0-4C0F-BDF0-D90158904ED3}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HelloWorldWPF.NoDesignFiles", "HelloWorldWPF.NoDesignFiles\HelloWorldWPF.NoDesignFiles.csproj", "{585EA5B3-C6A5-4444-8890-4D06561B4914}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Debug|Mixed Platforms = Debug|Mixed Platforms + Debug|x86 = Debug|x86 + Release|Any CPU = Release|Any CPU + Release|Mixed Platforms = Release|Mixed Platforms + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {3B2FA6D1-6EC0-4C0F-BDF0-D90158904ED3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3B2FA6D1-6EC0-4C0F-BDF0-D90158904ED3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3B2FA6D1-6EC0-4C0F-BDF0-D90158904ED3}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {3B2FA6D1-6EC0-4C0F-BDF0-D90158904ED3}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {3B2FA6D1-6EC0-4C0F-BDF0-D90158904ED3}.Debug|x86.ActiveCfg = Debug|Any CPU + {3B2FA6D1-6EC0-4C0F-BDF0-D90158904ED3}.Debug|x86.Build.0 = Debug|Any CPU + {3B2FA6D1-6EC0-4C0F-BDF0-D90158904ED3}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3B2FA6D1-6EC0-4C0F-BDF0-D90158904ED3}.Release|Any CPU.Build.0 = Release|Any CPU + {3B2FA6D1-6EC0-4C0F-BDF0-D90158904ED3}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {3B2FA6D1-6EC0-4C0F-BDF0-D90158904ED3}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {3B2FA6D1-6EC0-4C0F-BDF0-D90158904ED3}.Release|x86.ActiveCfg = Release|Any CPU + {3B2FA6D1-6EC0-4C0F-BDF0-D90158904ED3}.Release|x86.Build.0 = Release|Any CPU + {585EA5B3-C6A5-4444-8890-4D06561B4914}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {585EA5B3-C6A5-4444-8890-4D06561B4914}.Debug|Any CPU.Build.0 = Debug|Any CPU + {585EA5B3-C6A5-4444-8890-4D06561B4914}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {585EA5B3-C6A5-4444-8890-4D06561B4914}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {585EA5B3-C6A5-4444-8890-4D06561B4914}.Debug|x86.ActiveCfg = Debug|Any CPU + {585EA5B3-C6A5-4444-8890-4D06561B4914}.Debug|x86.Build.0 = Debug|Any CPU + {585EA5B3-C6A5-4444-8890-4D06561B4914}.Release|Any CPU.ActiveCfg = Release|Any CPU + {585EA5B3-C6A5-4444-8890-4D06561B4914}.Release|Any CPU.Build.0 = Release|Any CPU + {585EA5B3-C6A5-4444-8890-4D06561B4914}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {585EA5B3-C6A5-4444-8890-4D06561B4914}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {585EA5B3-C6A5-4444-8890-4D06561B4914}.Release|x86.ActiveCfg = Release|Any CPU + {585EA5B3-C6A5-4444-8890-4D06561B4914}.Release|x86.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {F0544A03-17E3-4EFB-BB50-4EDEB145B721} + EndGlobalSection +EndGlobal diff --git a/tests/HelloWorldWPF.NoDesignFiles/App.xaml b/tests/HelloWorldWPF.NoDesignFiles/App.xaml new file mode 100644 index 00000000..8da038e1 --- /dev/null +++ b/tests/HelloWorldWPF.NoDesignFiles/App.xaml @@ -0,0 +1,7 @@ + + + diff --git a/tests/HelloWorldWPF.NoDesignFiles/App.xaml.cs b/tests/HelloWorldWPF.NoDesignFiles/App.xaml.cs new file mode 100644 index 00000000..70be8cad --- /dev/null +++ b/tests/HelloWorldWPF.NoDesignFiles/App.xaml.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Configuration; +using System.Data; +using System.Linq; +using System.Windows; + +namespace HalloWeltWPF +{ + /// + /// Interaction logic for App.xaml + /// + public partial class App : Application + { + } +} diff --git a/tests/HelloWorldWPF.NoDesignFiles/HelloWorldWPF.NoDesignFiles.csproj b/tests/HelloWorldWPF.NoDesignFiles/HelloWorldWPF.NoDesignFiles.csproj new file mode 100644 index 00000000..d33b0574 --- /dev/null +++ b/tests/HelloWorldWPF.NoDesignFiles/HelloWorldWPF.NoDesignFiles.csproj @@ -0,0 +1,42 @@ + + + + + netcoreapp3.1 + HalloWeltWPF + WinExe + + True + true + HelloWorldWPF + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tests/HelloWorldWPF.NoDesignFiles/MainWindow.xaml b/tests/HelloWorldWPF.NoDesignFiles/MainWindow.xaml new file mode 100644 index 00000000..4c4fba01 --- /dev/null +++ b/tests/HelloWorldWPF.NoDesignFiles/MainWindow.xaml @@ -0,0 +1,91 @@ + + + + + + + + + + + + +