我想从 .net 核心类库中的资源文件读取本地化值,但出现异常。我在 .net core wep api 项目中添加了我的类库。
这些是我的资源文件“Resource.de.resx”、“Resource.en.resx”、“Resource.tr.resx”,它们位于我的类库项目的根文件夹中。 web api项目中没有资源文件。当我构建我的类库时,创建了三个文件夹(de、en、tr),在这些文件夹中有一个名为“XXX.Model.Core.resources.dll”的 dll。
An exception of type 'System.Resources.MissingManifestResourceException' occurred in System.Private.CoreLib.ni.dll but was not handled in user code Additional information: Could not find any resources appropriate for the specified culture or the neutral culture.
Make sure "Resource.resources" was correctly embedded or linked into assembly "class library" at compile time, or that all the satellite assemblies required are loadable and fully signed.
这是我的类库 project.json 文件:
{
"version": "1.0.0-*",
"dependencies": {
"Microsoft.EntityFrameworkCore": "1.1.0",
"Microsoft.EntityFrameworkCore.DynamicLinq": "1.0.3.3",
"NETStandard.Library": "1.6.1",
"System.ComponentModel.Annotations": "4.3.0",
"System.ComponentModel.Primitives": "4.3.0",
"System.Reflection.Extensions": "4.3.0",
"System.Resources.Reader": "4.3.0"
},
"frameworks": {
"netstandard1.6": {
"imports": "dnxcore50"
}
},
**"buildOptions": {
"embed":
{ "include": [ "Resource.de.resx", "Resource.en.resx", "Resource.tr.resx" ]}}}**
这是我尝试访问资源的类(class):
var resourceManager = new ResourceManager("Resource", typeof(LanguageSupportedException).GetTypeInfo().Assembly);
resourceManager.GetString("xx");
我该如何解决?
最佳答案
我也在 XAML 中遇到了这个消息,结合 WPFLocalizationExtension。
我有这段 XAML 代码:
<Label
Content="{lex:Loc WindspeedArea}"
ToolTip="{lex:Loc TipResources:TT_WindSpeed}"/>
WindspeedArea 位于 Resources.resx 中。TT_WindSpeed 位于 TipResources.resx 中。
然后我有了在 Resources.resx 中组合所有字符串的想法。
忘记从所有 XAML 文件中删除所有“TipResource:”前缀。
从而得到异常。多次。
关于c# - .net 核心中的 MissingManifestResourceException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42796877/