.net 核心中的 MissingManifestResourceException

ays*_*yse 5 .net c# asp.net-core-webapi

我想从 .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。

System.Private.CoreLib.ni.dll 中出现类型为“System.Resources.MissingManifestResourceException”的异常,但未在用户代码中处理附加信息:找不到适合指定区域性或中性区域性的任何资源。
确保在编译时将“Resource.resources”正确嵌入或链接到程序集“类库”中,或者确保所有所需的附属程序集都可加载并完全签名。

这是我的类库 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" ]}}}**
Run Code Online (Sandbox Code Playgroud)

这是我尝试访问资源的课程:

 var resourceManager = new ResourceManager("Resource", typeof(LanguageSupportedException).GetTypeInfo().Assembly);

resourceManager.GetString("xx");
Run Code Online (Sandbox Code Playgroud)

我该如何解决?

Eri*_*rik 0

我还在 XAML 中与 WPFLocalizationExtension 结合使用时遇到了此消息。我有这段 XAML 代码:

<Label 
    Content="{lex:Loc WindspeedArea}" 
    ToolTip="{lex:Loc TipResources:TT_WindSpeed}"/>
Run Code Online (Sandbox Code Playgroud)

WindspeedArea 位于 Resources.resx 中。

TT_WindSpeed 位于 TipResources.resx 中。

然后我想到了将 Resources.resx 中的所有字符串组合起来。

并且忘记从所有 XAML 文件中删除所有“TipResource:”前缀。

从而得到异常。多次。