Bif*_*iff 7 vb.net embedded-resource winforms
我是Visual Basic的新手,我在访问项目的资源文件时遇到问题.
Dim rm As Resources.ResourceManager = New Resources.ResourceManager("MyProjectName.My.Resources.Resources", [Assembly].GetExecutingAssembly())
Dim myValue = rm.GetString(lookUpKey) 'boom Object reference not set to an instance of an object.
Run Code Online (Sandbox Code Playgroud)
我认为问题在于字符串"MyProjectName.My.Resources.Resources".
将字符串移动到自己的资源文件中会更好吗?
在我将 .resx 文件移至其自己的项目并从我的主项目中引用该项目之前,我无法访问该资源文件。我还必须在该项目中创建一个虚拟类,以便它可以编译成 DLL 文件。
访问资源文件的代码实际上位于生成的Resource.resx.vb 文件中。
我能够使用以下代码访问资源文件。
'Name of Class Library where I moved the resx file
Dim classLibraryName As String = "ResourceProj"
'Name of Resource File without the .resx suffix
Dim resourceFileName As String = "Mappings"
'Finding the assembly of the resx file, ResourceProjClass is a dummy class I created so that the dll would build.
Dim myAssembly As Assembly = GetType(ResourceProj.ResourceProjClass).Assembly
Dim rm As Resources.ResourceManager = Nothing
rm = New Resources.ResourceManager(classLibraryName & "." & resourceFileName, GetType(myAssembly)
Return rm.GetString(lookUpKey)
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
37742 次 |
最近记录: |