473,322 Members | 1,421 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Reflection Issue

I am moving over to C# from VB.NET and am having some problems replicating
functionality that I could do in VB.NET.

In VB.NET I used to use the code

Dim frm As Object
Dim frmType As Type
Dim SampleAssembly As [Assembly]

SampleAssembly = [Assembly].Load(strLibrary)

frmType = SampleAssembly.GetType(strLibrary & "." & strClass)
frm = Activator.CreateInstance(frmType)
frmType.InvokeMember("Show", BindingFlags.InvokeMethod, Nothing, frm, Nothing)

This would show a form (strClass) that existed in a dll library
(strLibrary), so long as the library was in the same folder as the
application. The key point was that the library was NOT included as a
referenced library in the application project - this is because I am using
the method in a generic menu system.

My question is that in C# when I use the code

object frm;
Type frmType;
Assembly SampleAssembly;

SampleAssembly = Assembly.Load(strLibrary);
frmType = SampleAssembly.GetType(strLibrary + "." + strClass);
frm = Activator.CreateInstance(frmType);

frmType.InvokeMember("Show",BindingFlags.InvokeMet hod,null,frm,null);

which I thought would do the same thing I find that it does not work unless
the strLibrary file is referenced into the application.....

What am I doing wrong in the C# code - how can I change it so that I DONT
have to reference in the library that contains the form I Want to run

Thanks all for you help in advance
Nov 16 '05 #1
2 1442
is this a compile time issue or runtime?
"hplloyd" <hp*****@discussions.microsoft.com> wrote in message
news:C9**********************************@microsof t.com...
I am moving over to C# from VB.NET and am having some problems replicating
functionality that I could do in VB.NET.

In VB.NET I used to use the code

Dim frm As Object
Dim frmType As Type
Dim SampleAssembly As [Assembly]

SampleAssembly = [Assembly].Load(strLibrary)

frmType = SampleAssembly.GetType(strLibrary & "." & strClass)
frm = Activator.CreateInstance(frmType)
frmType.InvokeMember("Show", BindingFlags.InvokeMethod, Nothing, frm, Nothing)
This would show a form (strClass) that existed in a dll library
(strLibrary), so long as the library was in the same folder as the
application. The key point was that the library was NOT included as a
referenced library in the application project - this is because I am using
the method in a generic menu system.

My question is that in C# when I use the code

object frm;
Type frmType;
Assembly SampleAssembly;

SampleAssembly = Assembly.Load(strLibrary);
frmType = SampleAssembly.GetType(strLibrary + "." + strClass);
frm = Activator.CreateInstance(frmType);

frmType.InvokeMember("Show",BindingFlags.InvokeMet hod,null,frm,null);

which I thought would do the same thing I find that it does not work unless the strLibrary file is referenced into the application.....

What am I doing wrong in the C# code - how can I change it so that I DONT
have to reference in the library that contains the form I Want to run

Thanks all for you help in advance

Nov 16 '05 #2
hplloyd <hp*****@discussions.microsoft.com> wrote:
I am moving over to C# from VB.NET and am having some problems replicating
functionality that I could do in VB.NET.


Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: maf | last post by:
Using reflection, I'm trying to get the value for a constant in an enum. Getting the contant name works fine using: FieldInfo fieldInfos = TYPE.GetFields(); foreach(FieldInfo fi in fieldInfos...
8
by: Robert W. | last post by:
I've almost completed building a Model-View-Controller but have run into a snag. When an event is fired on a form control I want to automatically updated the "connnected" property in the Model. ...
2
by: Jeff | last post by:
I am trying to dynamically load an assembly via reflection and then invoke a method of that assembly that will populate a custom type collection passed into the method byref. I am able to...
3
by: HL | last post by:
The requirement is to send some information to other objects. The objects to whom the information has to be sent is not available at compile time. The names of the types (objects) will be provided...
20
by: Shawnk | last post by:
I would like to get the class INSTANCE name (not type name) of an 'object'. I can get the object (l_obj_ref.GetType()) and then get the (l_obj_typ.Name) for the class name. I there any way of...
2
by: Wiktor Zychla [C# MVP] | last post by:
Could anyone confirm/deny that following is a bug (or at least an "unexpected behaviour")? If this is not a bug, I would be glad for a short explanation or a workaround. Issue: A generic...
15
by: Jeff Mason | last post by:
Hi, I'm having a reflection brain fog here, perhaps someone can set me on the right track. I'd like to define a custom attribute to be used in a class hierarchy. What I want to do is to...
2
by: =?Utf-8?B?UmVuYXVkIExhbmdpcw==?= | last post by:
Hello, I have an asp.net web page (say page.aspx) which derives from a custom base page object (CustomPage : BasePage : System.Web.UI.Page) Which has a method called DoSomething(params). My web...
7
by: =?Utf-8?B?UVNJRGV2ZWxvcGVy?= | last post by:
I have a C# logging assembly with a static constructor and methods that is called from another C# Assembly that is used as a COM interface for a VB6 Application. Ideally I need to build a file...
11
by: idoublepress | last post by:
Hi all, I've been struggling with an issue that I hope you can comment on or provide suggestions to. Our .NET 2.0 (VS2005) based product is crashing (when the user selects a particular feature on...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.