我刚刚升级到 Rc2,以前的工作不再起作用。我在一个单独的项目中有几个 resx 文件,我使用自定义类来访问数据。现在运行它时出现以下错误:
MissingManifestResourceException:找不到适合指定区域性或中性区域性的任何资源。确保“GarageWeb.Core.CoreResources.resources”在编译时正确嵌入或链接到程序集“GarageWeb.Core”中,或者所有所需的附属程序集都是可加载的并且完全签名。
编辑:我对此进行了简化并创建了一个控制台应用程序,该应用程序被剥离了所有内容,但在此处重现错误所需的内容:https ://github.com/GarageWeb/ResourceTest
这是访问资源的类:
public class ResourceService : IResourceService
{
private readonly ILoggingService _loggingService;
private readonly ICoreGlobalResourceService _coreGlobalResources;
private readonly ISiteGlobalResourceService _siteGlobalResources;
public ResourceService(ILoggingService loggingService, ICoreGlobalResourceService coreGlobalResourceService, ISiteGlobalResourceService siteGlobalResources)
{
_loggingService = loggingService;
_coreGlobalResources = coreGlobalResourceService;
_siteGlobalResources = siteGlobalResources;
}
public string GetGlobalText(string resourceKey, bool includeBrackets = true)
{
var localizedString = _coreGlobalResources.ResourceManager.GetString(resourceKey);
if (string.IsNullOrEmpty(localizedString))
{
localizedString = _siteGlobalResources.ResourceManager.GetString(resourceKey);
}
if (string.IsNullOrEmpty(localizedString) && includeBrackets)
{
_loggingService.LogInvalidResource(resourceKey);
}
if (includeBrackets)
{
return localizedString ?? "[" + resourceKey + "]";
}
return localizedString ?? resourceKey;
}
public string BuildMessageFromResource(string resourceKey, string placeHolderResourceKey1,
bool includeBrackets = true)
{
var errorString = string.Format(CultureInfo.CurrentCulture, GetGlobalText(resourceKey, includeBrackets),
GetGlobalText(placeHolderResourceKey1, includeBrackets));
return errorString;
}
public string BuildMessageFromResourceAndArray(string resourceKey, string[] arrayOfValues,
bool includeBrackets = true)
{
var placeHolderValue = "";
for (var i = 0; i < arrayOfValues.Length; i++)
{
if (i + 1 == arrayOfValues.Length)
{
placeHolderValue += GetGlobalText(arrayOfValues[i], includeBrackets);
}
else
{
placeHolderValue += GetGlobalText(arrayOfValues[i], includeBrackets) + ", ";
}
}
var errorString = string.Format(CultureInfo.CurrentCulture, GetGlobalText(resourceKey, includeBrackets),
placeHolderValue);
return errorString;
}
public string BuildMessageFromResourceAndTwoArrays(string resourceKey, string[] firstArrayOfValues,
string[] secondArrayOfValues,
bool includeBrackets = true)
{
var placeHolderOneValue = "";
var placeHolderTwoValue = "";
for (var i = 0; i < firstArrayOfValues.Length; i++)
{
if (i + 1 == firstArrayOfValues.Length)
{
placeHolderOneValue += GetGlobalText(firstArrayOfValues[i], includeBrackets);
}
else
{
placeHolderOneValue += GetGlobalText(firstArrayOfValues[i], includeBrackets) + ", ";
}
}
for (var i = 0; i < secondArrayOfValues.Length; i++)
{
if (i + 1 == secondArrayOfValues.Length)
{
placeHolderTwoValue += GetGlobalText(secondArrayOfValues[i], includeBrackets);
}
else
{
placeHolderTwoValue += GetGlobalText(secondArrayOfValues[i], includeBrackets) + ", ";
}
}
var errorString = string.Format(CultureInfo.CurrentCulture, GetGlobalText(resourceKey, includeBrackets),
placeHolderOneValue, placeHolderTwoValue);
return errorString;
}
public string BuildMessageFromResource(string resourceKey, string placeHolderResourceKey1,
string placeHolderResourceKey2, bool includeBrackets = true)
{
var errorString = string.Format(CultureInfo.CurrentCulture, GetGlobalText(resourceKey, includeBrackets),
GetGlobalText(placeHolderResourceKey1, includeBrackets),
GetGlobalText(placeHolderResourceKey2, includeBrackets));
return errorString;
}
public string BuildMessageFromResource(string resourceKey, string placeHolderResourceKey1,
string placeHolderResourceKey2, string placeHolderResourceKey3,
bool includeBrackets = true)
{
var errorString = string.Format(CultureInfo.CurrentCulture, GetGlobalText(resourceKey, includeBrackets),
GetGlobalText(placeHolderResourceKey1, includeBrackets),
GetGlobalText(placeHolderResourceKey2, includeBrackets),
GetGlobalText(placeHolderResourceKey3, includeBrackets));
return errorString;
}
}
它在这里失败: var本地化字符串 = _coreGlobalResources.ResourceManager.GetString(resourceKey);
有任何想法吗?有没有新的方法来嵌入这些资源?