Resourcemanager.GetString返回null [英] Resourcemanager.GetString returns null

查看:97
本文介绍了Resourcemanager.GetString返回null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!

我试图让我的用户控制(dll项目)多语言与资源,但我有一个昏暗的问题!

我可以得到我的aproaching字符串只是第一!我的意思是当resourcemanager.getstring返回一个字符串,然后它不会返回任何东西!它总是正确加载装配!问题是在运行GetString方法之后!

我应该在任何字符串返回后释放资源吗? (我用它与ReleaseAllResources()方法)

stacktrace显示.Net的内部方法!



系统抓住了System.NullReferenceException

HResult = -2147467261

消息=对象引用未设置为对象的实例。



这是我的代码!

hi!
I am trying to make my user control (dll project) multi language with resources, but i have a dim problem!
I can get my aproaching string just first! i mean when resourcemanager.getstring returns a string, then after that it doesnt return anything! it loads assembly correctly always! problem is after running line of GetString method!
should i release resource after any string returned? (i used it with ReleaseAllResources() method)
stacktrace show internal methods of .Net!

System.NullReferenceException was caught
HResult=-2147467261
Message=Object reference not set to an instance of an object.

here is my code!

Type t = Type.GetType("A CLASS IN NAMESPACE");
System.Reflection.Assembly asm = t.Assembly;
System.Resources.ResourceManager rm = new System.Resources.ResourceManager("Namespace.ResourceName", asm);
string s=rm.GetString(FieldName);
// rm.ReleaseAllResources();
return s;





我将这样的资源文件命名为



I named my resource files like this

fa-IR.resx
en-US.resx
es-MX.resx



这些是嵌入式资源!

谢谢!



编辑:

这是一个用户控制项目!


these are embedded resources!
thank you!


It is a user control project!

推荐答案

您正在尝试实现一些.NET全球化/本地化功能,这些功能已经使用.NET FCL为您开发和提供。这个想法是正确的,但是.NET实现可以让您更加深入地实现本地化,而您只是想做。它基于附属程序集(基本上是资源专用程序集,根据应用程序打开的当前文化自动使用它们命名),以及后备机制,自动选择卫星组件,试图将所需的文化与可用卫星组件的文化相匹配。



请参阅我过去的答案:

如何使用3种语言的单个resx文件 [ ^ ],

winform .net 中的全球化/本地化问题[ ^ ],

winforms中的全球化 [ ^ ]。



-SA
You are trying to achieve some .NET globalization/localization features which are already developed and provided for you with .NET FCL. The idea is correct, but .NET implementation automates the localization much deeper that you are only trying to do. It is based on satellite assemblies (basically, resource-only assemblies which are named properly for using them automatically, depending on the current culture your application switches on), and the fallback mechanism, where the satellite assemblies are chosen automatically trying to match the required culture with the cultures of available satellite assemblies.

Please see my past answers:
How to use a Single resx file for 3 languages[^],
globalization/localization problem in winform .net[^],
globalization in winforms[^].

—SA


这篇关于Resourcemanager.GetString返回null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆