问题
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