How do I get all th resources dynamically from my current assembly? I have tried two methods, GetManifestResourceNames and GetResourceSet with no success. I am comfortable with solutions in VB.net or C#.
First Method
This first method only returns an array of length 1 with this value "MyNameSpace.Resources.resource". The problem is that there are more than 1 resource in this file.
Dim ca As Assembly = Assembly.GetExecutingAssembly
Dim rn() As String = CurrentAssembly.GetManifestResourceNames()
Second Method
Dim ca As Assembly = Assembly.GetExecutingAssembly
Dim crm As New ResourceManager("", ca)
''//Dim CurrentResourceManager As New ResourceManager(_
"MyNamespace.Resources.resources", CurrentAssembly)
''//Dim CurrentResourceManager As New ResourceManager( _
"My.Resources", CurrentAssembly)
Dim rs As ResourceSet = CurrentResourceManager.GetResourceSet(CultureInfo.CurrentCulture, True, True)
Dim rs As ResourceSet = crm.GetResourceSet( _
CultureInfo.CurrentCulture, True, True)
MissingManifestResourceException was unhandled
Could not find any resources appropriate for the specified culture or the neutral culture. Make sure ".resources" was correctly embedded or linked into assembly "MyProgram" at compile time, or that all the satellite assemblies required are loadable and fully signed.loadable and fully signed.
Solution (as per Hans Passant)
Copy the Namespace from the Resources.Designer.vb
<Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _
Friend ReadOnly Property ResourceManager() As Global.System.Resources.ResourceManager
Get
If Object.ReferenceEquals(resourceMan, Nothing) Then
Dim temp As Global.System.Resources.ResourceManager = New Global.System.Resources.ResourceManager("MyNamespace.Resources", GetType(Resources).Assembly)
resourceMan = temp
End If
Return resourceMan
End Get
End Property
and place it in the code
Dim CurrentResourceManager As New ResourceManager( _
"MyNamespace.Resources", CurrentAssembly)
Dim rs As ResourceSet = CurrentResourceManager.GetResourceSet( _
CultureInfo.CurrentCulture, True, True)
Yes, there's more than 1 resource in MyNameSpace.Resources.resource. Which is the name you have to pass to ResourceManager, an empty string isn't going to work.
To see the kind of code you have to write, start a Windows Forms application and add a couple of resources to the Project + Properties, Resources tab. In the Solution Explorer, click the "Show All Files" icon. Open the My Project node, open the Resources.resx node and double-click the Resources.Designer.vb file. Note the code for the ResourceManager property.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With