Solved

Converting one line from c# to vb.net

Posted on 2004-04-16
8
723 Views
Last Modified: 2007-12-19
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?
0
Comment
Question by:EugeneTrukhin
  • 4
  • 2
  • 2
8 Comments
 
LVL 35

Expert Comment

by:YZlat
ID: 10843134
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)

0
 
LVL 1

Author Comment

by:EugeneTrukhin
ID: 10843239
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
0
 
LVL 35

Expert Comment

by:YZlat
ID: 10844840
try  CType(ProjectControl).Assembly
0
 
LVL 1

Author Comment

by:EugeneTrukhin
ID: 10845110
no it doesnt work because Ctype expects an expression and the type.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 3

Expert Comment

by:solublefish
ID: 10846875
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
0
 
LVL 1

Author Comment

by:EugeneTrukhin
ID: 10859351
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?

0
 
LVL 3

Accepted Solution

by:
solublefish earned 125 total points
ID: 10862162
I don't think the problem is with reading the resource file - I suspect the ResourceManager will work fine once you pass it the right type. Your C# code works, so all you need to do is get the equivalent of typeof in VB.NET to get a Type object representing your ProjectControl. Unfortunately, VB.NET doesn't have a regular typeof operator, so you have to make do with GetType.

Try using the fully-qualified name of the ProjectControl type -Type.GetType("MyCompany.MyProduct.ProjectControl") or whatever:
Dim LocRM As ResourceManager = New ResourceManager("MyProject.Resources.ProjectControl", Type.GetType("MyCompany.MyProduct.ProjectControl").Assembly)


Or if it doesn't have any side effects, create a new ProjectControl object, and use the actual instance's .GetType() method:

Dim pc as ProjectControl
set pc = new ProjectControl()
Dim LocRM As ResourceManager = New ResourceManager("MyProject.Resources.ProjectControl", pc.GetType().Assembly)
0
 
LVL 1

Author Comment

by:EugeneTrukhin
ID: 10863262
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.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now