Can't get C# Reflection code to work in VB

C

Chris

I am looking at this code in C#

Assembly a=Assembly.LoadFrom("employee.dll");
Type t=a.GetType("Company.Employee");

I can't figure out what it is in VB.net can anyone help. I try

Dim login_assembly = Assembly.LoadFile(Server.MapPath("bin/login.dll"))
Dim login_type As Type = login_assembly.GetType("clsLogin")

and I get a blue squiggly line under get type saying there is no default
property for 'system.type'

Regards
 
G

Guest

The following is the equivalent:
Dim a As
System.Reflection.Assembly=System.Reflection.Assembly.LoadFrom("employee.dll")
Dim t As Type=a.GetType("Company.Employee")

You didn't specify a type for the "a" variable, causing it be 'Object' by
default, which of course doesn't have a "GetType" method.
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C#/VB to C++ converter
Instant Python: VB to Python converter
 
S

sloan

putting

Option Explicit On
Option Strict On

at the top of your vb.net code would have let you seen the error from the
get-go.

Dim login_assembly = Assembly.LoadFile(Server.MapPath("bin/login.dll"))
is about the same as

Dim login_assembly as object

this is leftover from vb6......
 
G

Guest

What might have led to more confusion is the fact that you can't use
"Assembly" unqualified as a type in VB - it must be qualified.
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C#/VB to C++ converter
Instant Python: VB to Python converter
 
S

Scott M.

You didn't specify a type for the "a" variable, causing it be 'Object' by
default, which of course doesn't have a "GetType" method.

Well, you're right that not specifiying a type for the variable is the
problem, but you are wrong that the Object type doesn't have a GetType
method. In fact, GetType is defined on the object type and that is why all
other objects have such a method.
 

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

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top