Cannot access resource (resx) file

自闭症网瘾萝莉.ら 提交于 2019-12-25 07:25:10

问题


I am using VS2015 and have a project called "CultureTest" (this is my project name and root namespace). I created a folder in my project "Languages" and in this folder created a new resource item named "English.resx". I only have one string in there now called "Start" with the value being the same.

In my VB.NET code I have the following

Imports System.Globalization
Imports System.Reflection
Imports System.Resources

Public Class Form1
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim ci As CultureInfo = New CultureInfo("en-US")
        Dim rm As ResourceManager = New ResourceManager("CultureTest.Languages.English", Assembly.GetExecutingAssembly())

        MessageBox.Show(rm.GetString("Start", ci))
    End Sub
End Class

Every time I run this, I get the following error:

'rm.getstring("Start",ci)' threw an exception of type 'System.Resources.MissingManifestResourceException'
Data: {System.Collections.ListDictionaryInternal}
HResult: -2146233038
HelpLink: Nothing
InnerException: Nothing
Message: "Could not find any resources appropriate for the specified culture or the neutral culture.  Make sure ""CultureTest.Languages.English.resources"" was correctly embedded or linked into assembly ""CultureTest"" at compile time, or that all the satellite assemblies required are loadable and fully signed."
Source: "mscorlib"
StackTrace: "   at System.Resources.ManifestBasedResourceGroveler.HandleResourceStreamMissing(String fileName)" & vbCrLf & "   at System.Resources.ManifestBasedResourceGroveler.GrovelForResourceSet(CultureInfo culture, Dictionary`2 localResourceSets, Boolean tryParents, Boolean createIfNotExists, StackCrawlMark& stackMark)" & vbCrLf & "   at System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo requestedCulture, Boolean createIfNotExists, Boolean tryParents, StackCrawlMark& stackMark)" & vbCrLf & "   at System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo culture, Boolean createIfNotExists, Boolean tryParents)" & vbCrLf & "   at System.Resources.ResourceManager.GetString(String name, CultureInfo culture)"
TargetSite: {Void HandleResourceStreamMissing(System.String)}

For the life of me I cannot seem to read my resource file. What am I doing wrong? Any help and examples would be greatly appreciated!

Kind Regards

来源:https://stackoverflow.com/questions/38058623/cannot-access-resource-resx-file

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