c# - .net 核心中的 MissingManifestResourceException

标签 c# .net 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。

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/

相关文章:

c# - 如何用循环和条件做单行代码?

c# - 带有 FlagsAttributes 的枚举

c# - 我的深拷贝不是真正的深拷贝

c# - Entity Framework Core 是否支持数据库密码轮换

c# - 从 C# 调用 C++ 模板函数

c# - 获取子元素的所有属性

c# - 将可选的 OrderBy 添加到已编译的 Entity Framework linq 查询

c# - 有没有更好的方法来处理 LINQ to SQL 中的验证?

c# - 如何在 Angular 10 中使用 DevExpress 报表设计器和报表查看器

c# - 如何创建一个 web Api 具有 http post 功能,它可以从正文中获取任何动态 json 内容并能够将其解析为字符串