Resources of classes

L

Lucio Menci

Hi,

I d'like to use a resource file to a class isn't a usercontrol.

If I edit the main .resx of the project, I can found that resource by the
command:

Dim WantedResource As Object = My.Resources.MyResrouceName

If I make a UserControl, VS creates three files: a.vb, a.designer.vb and
a.resx.
If I edit the a.resx and I add a resource into it, I can use that resource
from a sub of the UserControl by the sequent commands:

Dim RSManager As New Resources.ResourceManager(Me.GetType)
Dim WantedResource As Object = RSManager.GetObject("NewImage")

I tried to create a Class isn't a UserControl (b.vb), and put a new empty
file into the same directory called b.resx, create a new project, import that
Class and, if I have all files shown on the solution explorer, I see that the
b.vb have the b.resx linked. If I edit the b.resx and I add the same
resource into it, I noted that b.resx is very similar to a.resx, but if I try
to call the same commands above, the second one throws an exception
(MissingManifestResourceException). Why?
 
G

Gregory A. Beamer

I tried to create a Class isn't a UserControl (b.vb), and put a new
empty file into the same directory called b.resx, create a new
project, import that Class and, if I have all files shown on the
solution explorer, I see that the b.vb have the b.resx linked. If I
edit the b.resx and I add the same resource into it, I noted that
b.resx is very similar to a.resx, but if I try to call the same
commands above, the second one throws an exception
(MissingManifestResourceException). Why?


My first thought is a namespace issue.Either way, for general resources you
are better to make a resource only assembly and call it where needed.
http://snurl.com/t807y

Peace and Grace,
Greg


--
Vote for Miranda's Christmas Story
http://tinyurl.com/mirandabelieve

Twitter: @gbworld
Blog: http://gregorybeamer.spaces.live.com

*******************************************
| Think outside the box! |
*******************************************
 
L

Lucio Menci

I found something of different. If I Create a new project with my class with
the resource already existaint, my project runs well. If I open an old one
using that class where I add the resource file, I have to put thoose lines to
the .vbproj file:

<EmbeddedResource Include="..\Risorsa da incorporare\Class1.resx">
<Link>Class1.resx</Link>
<DependentUpon>Class1.vb</DependentUpon>
<SubType>Designer</SubType>
</EmbeddedResource>

into the ItemGroup where there are the other resources. Now all runs well
(and, naturally, make the resx file points to the resources with absolute
paths).

Thank you!
Lucio
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top