Link to home
Start Free TrialLog in
Avatar of EugeneTrukhin
EugeneTrukhin

asked on

Converting one line from c# to vb.net

Hello,

I want to convert one simple c# line into vb.net and i can't do it. I don't know vb.net that much, and I spend some time searching on MSDN and I didnt find any samples.

protected ResourceManager LocRM;
LocRM= new ResourceManager("MyProject.Resources.ProjectControl", typeof(ProjectControl).Assembly);

And the purpose of this is to read data from my resource file which i have in /MyProject/Resources and which is called ProjectControl.resx

i did this:

Protected LocRM As ResourceManager
 and then the next line i cant convert...anyone can help?
Avatar of YZlat
YZlat
Flag of United States of America image

Protected LocRM As ResourceManager
LocRM=New ResourceManager("MyProject.Resources.ProjectControl", Me.GetType.Assembly)

or

Dim LocRM As ResourceManager = New ResourceManager("MyProject.Resources.ProjectControl", Me.GetType.Assembly)

Avatar of EugeneTrukhin
EugeneTrukhin

ASKER

Me.GetType.Assembly doesnt work because i want to read not from the resource file associated with that particular page but from another resource file which is stored in another directory. Me.GetType.Assembly --> Im getting an assembly associated with that particular page but I wanna read another assembly...

In c# it works LocRM= new ResourceManager("MyProject.Resources.ProjectControl", typeof(ProjectControl).Assembly); but this "typeof(ProjectControl).Assembly" part I dont know how to represent in vb.net
try  CType(ProjectControl).Assembly
no it doesnt work because Ctype expects an expression and the type.
I think
Type.GetType("ProjectControl").Assembly
should get you the Assembly associated with "ProjectControl", making the whole line:

Dim LocRM As ResourceManager = New ResourceManager("MyProject.Resources.ProjectControl", Type.GetType("ProjectControl").Assembly)

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemtypeclassgettypetopic.asp
I tried what you say but i get "Object reference not set to an instance of an object."....Hm, I wonder why it is so easy to do in c#, and i have so many problems with vb.net.

Does anyone have an experience reading stuff from the resource file based on the culture in vb.net?

ASKER CERTIFIED SOLUTION
Avatar of solublefish
solublefish

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
This worked:

LocRM = New ResourceManager("MyProject.ProjectControl", Type.GetType("MyProject.ProjectControl.__ProjectControl").Assembly)

I guess i had a problem because in vb.net the namespaces are handled differently than in c#. I tried to define the path to the resource file using c# mentality. In vb.net it's done differently.

Thank you solublefish.