Load “loose” localized resources at runtime?

别等时光非礼了梦想. 提交于 2021-02-07 10:47:35

问题


I have a web service which supplies me with a generated .resx (XML only) which I then convert to binary a .resources file. I am currently generating an assembly file with that using al.exe. Here are my arguments:

/t:lib /c:{culture} /embed:"{.resource input}" /out:"{.dll output}"

Loading this assembly in via Assembly.LoadFrom(file) works fine, but I believe that my assembly is not properly generated. It has no type, namespace, or methods to invoke and therefor no ResourceManager apparently.

Essentially I am just wondering if it is at all possible to generate, load, and utilize resources that have no class or namespace which my project knows about at compile time. Thanks.


回答1:


Your assembly is a satellite assembly. From MSDN:

By definition, satellite assemblies can only contain resources. They cannot contain any executable code.

If you want to access the resources of this assembly - similar code should work:

ResourceManager rm = new ResourceManager(
    "ResourceTest.Properties.Resources", 
     Assembly.LoadAssembly(file));
MessageBox.Show(rm.GetString("helloWorldString"));

Also, the article from MSDN: Walkthrough: Loading Resources from a Satellite Assembly shows an alternative way of how to load a resource string from a satellite assembly.



来源:https://stackoverflow.com/questions/15281109/load-loose-localized-resources-at-runtime

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!