[英]Does Assembly.GetExecutingAssembly().GetManifestResourceNames() return resources from App_LocalResources?
I have global and local embedded resources in my project as shown in the image. 如图所示,我的项目中具有全局和本地嵌入式资源。
Resources files in my project with build action as embedded resources 我的项目中的资源文件,将构建操作作为嵌入式资源
I have a function ResourceText as below 我有一个功能ResourceText如下
public static string GLOBAL_RESOURCES = "SampleClient.App_GlobalResources.Global.resources";
/// <summary>
/// Used in JavaScript/front code to return resource translations for current page or global resource file
/// </summary>
/// <param name="pResourceKey"></param>
/// <returns></returns>
/// <remarks></remarks>
public string ResourceText(string pResourceKey, bool pGlobalResource = false)
{
if (string.IsNullOrEmpty(pResourceKey)) throw new ArgumentNullException("ResourceKey cannot be empty");
if (pGlobalResource)
{
// Find the value from the global resource
ResourceManager tResourceManager = new System.Resources.ResourceManager(GLOBAL_RESOURCES.Replace(".resources", ""), this.GetType().BaseType.Assembly);
tResourceManager.IgnoreCase = true;
string tTranlsation = tResourceManager.GetString(pResourceKey);
return string.IsNullOrEmpty(tTranlsation) ? pResourceKey : tTranlsation;
}
else
{
string[] tAssemblyNames = Assembly.GetExecutingAssembly().GetManifestResourceNames();
try
{
if (tAssemblyNames.Length >= 1) // There is a local file associated
{
// Get value from the local resource
string tAssemblyName = this.Page.GetType().BaseType.FullName.Insert(this.Page.GetType().BaseType.FullName.LastIndexOf(".") + 1, "App_LocalResources.");
string tResName = (from n in tAssemblyNames where n.Contains(tAssemblyName + ".aspx") select n).First().Replace(".resources", "");
ResourceManager tResourceManager = new System.Resources.ResourceManager(tResName, this.GetType().BaseType.Assembly);
tResourceManager.IgnoreCase = true;
string tTranlsation = tResourceManager.GetString(pResourceKey);
return string.IsNullOrEmpty(tTranlsation) ? pResourceKey : tTranlsation;
}
}
catch (Exception ex)
{
throw (ex);
// Check the local resources
}
}
// Fall back
return pResourceKey;
}
Which is called in my aspx page as 在我的aspx页面中称为
<input type="search" id="inputCustomerGroupGridSearch" placeholder="<%= ResourceText("PlaceholderSearch")%>" />
<button type="button" id="buttonNewCustomerGroup" style="float: right" class="PrimaryButton"><%=ResourceText("ButtonNew")%></button>
When I debugged the function ResourceText, the line of code 当我调试功能ResourceText时,代码行
string[] tAssemblyNames = Assembly.GetExecutingAssembly().GetManifestResourceNames();
returns only "SampleClient.App_GlobalResources.Global.resources" not "SampleClient.Modules.Customers.App_LocalResources.Customers.resouces". 仅返回“ SampleClient.App_GlobalResources.Global.resources”,而不返回“ SampleClient.Modules.Customers.App_LocalResources.Customers.resouces”。 Why is the resources in App_LocalResources not returned by Assembly.GetExecutingAssembly().GetManifestResourceNames()?
为什么Assembly.GetExecutingAssembly()。GetManifestResourceNames()不返回App_LocalResources中的资源?
Resolved: I added strong typed assembly App_LocalResources.resources.dll in my bin folder. 解决:我在bin文件夹中添加了强类型程序集App_LocalResources.resources.dll。 Then it was listed in resources names when executing Assembly.GetExecutingAssembly().GetManifestResourceNames();
然后在执行Assembly.GetExecutingAssembly()。GetManifestResourceNames();时将其列在资源名称中。
So, I could call my ResourceText function for both global and local resources. 因此,我可以为全局和本地资源调用ResourceText函数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.