473,625 Members | 2,853 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Adding references during runtime

How do i add references during runtime?
Jul 19 '05 #1
8 6578
filip stas <fi********@pan dora.be> wrote:
How do i add references during runtime?


Do you mean references to other assemblies? You don't. You have to load
them with reflection. What *exactly* do you want to do?

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too
Jul 19 '05 #2
reference to other assemblies
"Jon Skeet" <sk***@pobox.co m> wrote in message news:MP******** *************** *@news.microsof t.com...
filip stas <fi********@pan dora.be> wrote:
How do i add references during runtime?


Do you mean references to other assemblies? You don't. You have to load
them with reflection. What *exactly* do you want to do?

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too
Jul 19 '05 #3
filip stas <fi********@pan dora.be> wrote:
reference to other assemblies


That's not "exactly what you want to do" - that's 4 words. Say exactly
what situation you've got, what the *aim* of this is, etc.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too
Jul 19 '05 #4
[If you could make your newsreader wrap lines at about 70 characters it
would make your posts easier to reply to, by the way.]

filip stas <fi********@pan dora.be> wrote:
creating dll files containing forms so they can be applied as sort of
an add-in in to a main program. I want to call those dll files and then
dynamically add menus for the forms contained in the dll into the main
program


In that case use Assembly.Load, Assembly.LoadFr om or one of the
similarly named methods. They vary in subtle ways, so be careful which
you pick.

You then use Assembly.GetTyp e(String) to get the appropriate type, then
instantiate it by reflection etc.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too
Jul 19 '05 #5
Okay got at lot further for now, but have a following question

I have a main program wihich merges a menu created in a seperate dll. This mainprogram is an MDIcontainer. How can I make it so that the forms in thd dll use the form of the main program as mdiparent.
these are the codes i have:

testmodule.dll (seperate dll):
class menu
Private _hoofdIn As New MenuItem

Public Function getmenu()

Dim m As New MainMenu

_hoofdIn.Text = "TestModule "

_hoofdIn.MenuIt ems.Add("subtes t", New EventHandler(Ad dressOf _sub1_Click))

m.MenuItems.Add (_hoofdIn)

Return m

End Function

Protected Sub _sub1_Click(ByV al sender As Object, ByVal e As System.EventArg s)

Dim sf As New sub1

sf.Show()

End Sub

testmodule.dll also contains sub1 form.

The main program:

Imports System.reflecti on

Public Class Form1

Inherits System.Windows. Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()

MyBase.New()

'This call is required by the Windows Form Designer.

InitializeCompo nent()

'Add any initialization after the InitializeCompo nent() call

End Sub

'Form overrides dispose to clean up the component list.

Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)

If disposing Then

If Not (components Is Nothing) Then

components.Disp ose()

End If

End If

MyBase.Dispose( disposing)

End Sub

'Required by the Windows Form Designer

Private components As System.Componen tModel.IContain er

'NOTE: The following procedure is required by the Windows Form Designer

'It can be modified using the Windows Form Designer.

'Do not modify it using the code editor.

Friend WithEvents MainMenu1 As System.Windows. Forms.MainMenu

Friend WithEvents MenuItem1 As System.Windows. Forms.MenuItem

Friend WithEvents MenuItem2 As System.Windows. Forms.MenuItem

Friend WithEvents Button1 As System.Windows. Forms.Button

<System.Diagnos tics.DebuggerSt epThrough()> Private Sub InitializeCompo nent()

Me.MainMenu1 = New System.Windows. Forms.MainMenu

Me.MenuItem1 = New System.Windows. Forms.MenuItem

Me.MenuItem2 = New System.Windows. Forms.MenuItem

Me.Button1 = New System.Windows. Forms.Button

Me.SuspendLayou t()

'

'MainMenu1

'

Me.MainMenu1.Me nuItems.AddRang e(New System.Windows. Forms.MenuItem( ) {Me.MenuItem1})

'

'MenuItem1

'

Me.MenuItem1.In dex = 0

Me.MenuItem1.Me nuItems.AddRang e(New System.Windows. Forms.MenuItem( ) {Me.MenuItem2})

Me.MenuItem1.Te xt = "bestand"

'

'MenuItem2

'

Me.MenuItem2.In dex = 0

Me.MenuItem2.Te xt = "sluiten"

'

'Button1

'

Me.Button1.Loca tion = New System.Drawing. Point(104, 104)

Me.Button1.Name = "Button1"

Me.Button1.TabI ndex = 0

Me.Button1.Text = "merge"

'

'Form1

'

Me.AutoScaleBas eSize = New System.Drawing. Size(5, 13)

Me.ClientSize = New System.Drawing. Size(292, 273)

Me.Controls.Add (Me.Button1)

Me.IsMdiContain er = True

Me.Menu = Me.MainMenu1

Me.Name = "Form1"

Me.Text = "Form1"

Me.ResumeLayout (False)

End Sub

#End Region

Private Sub MenuItem2_Click (ByVal sender As System.Object, ByVal e As System.EventArg s) Handles MenuItem2.Click

End

End Sub

Private path As String = "c:\testmod "

Private objmenu As MainMenu

Public Sub CreateMenu()

Dim refmodule As [Assembly] = [Assembly].LoadFile(path & "\testmodule.dl l")

Dim t As Type = refmodule.GetTy pe("testmodule. menu")

Dim obj As Object = Activator.Creat eInstance(t)

Dim ar As Menu = obj.getmenu()

Me.MainMenu1.Me rgeMenu(ar)

End Sub

Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles Button1.Click

CreateMenu()

End Sub

End Class

"Jon Skeet" <sk***@pobox.co m> wrote in message news:MP******** *************** *@news.microsof t.com...
[If you could make your newsreader wrap lines at about 70 characters it
would make your posts easier to reply to, by the way.]

filip stas <fi********@pan dora.be> wrote:
creating dll files containing forms so they can be applied as sort of
an add-in in to a main program. I want to call those dll files and then
dynamically add menus for the forms contained in the dll into the main
program


In that case use Assembly.Load, Assembly.LoadFr om or one of the
similarly named methods. They vary in subtle ways, so be careful which
you pick.

You then use Assembly.GetTyp e(String) to get the appropriate type, then
instantiate it by reflection etc.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too
Jul 19 '05 #6
Okay got at lot further for now, but have a following question

I have a main program wihich merges a menu created in a seperate dll. This mainprogram is an MDIcontainer. How can I make it so that the forms in thd dll use the form of the main program as mdiparent.
these are the codes i have:

testmodule.dll (seperate dll):
class menu
Private _hoofdIn As New MenuItem

Public Function getmenu()

Dim m As New MainMenu

_hoofdIn.Text = "TestModule "

_hoofdIn.MenuIt ems.Add("subtes t", New EventHandler(Ad dressOf _sub1_Click))

m.MenuItems.Add (_hoofdIn)

Return m

End Function

Protected Sub _sub1_Click(ByV al sender As Object, ByVal e As System.EventArg s)

Dim sf As New sub1

sf.Show()

End Sub

testmodule.dll also contains sub1 form.

The main program:

Imports System.reflecti on

Public Class Form1

Inherits System.Windows. Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()

MyBase.New()

'This call is required by the Windows Form Designer.

InitializeCompo nent()

'Add any initialization after the InitializeCompo nent() call

End Sub

'Form overrides dispose to clean up the component list.

Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)

If disposing Then

If Not (components Is Nothing) Then

components.Disp ose()

End If

End If

MyBase.Dispose( disposing)

End Sub

'Required by the Windows Form Designer

Private components As System.Componen tModel.IContain er

'NOTE: The following procedure is required by the Windows Form Designer

'It can be modified using the Windows Form Designer.

'Do not modify it using the code editor.

Friend WithEvents MainMenu1 As System.Windows. Forms.MainMenu

Friend WithEvents MenuItem1 As System.Windows. Forms.MenuItem

Friend WithEvents MenuItem2 As System.Windows. Forms.MenuItem

Friend WithEvents Button1 As System.Windows. Forms.Button

<System.Diagnos tics.DebuggerSt epThrough()> Private Sub InitializeCompo nent()

Me.MainMenu1 = New System.Windows. Forms.MainMenu

Me.MenuItem1 = New System.Windows. Forms.MenuItem

Me.MenuItem2 = New System.Windows. Forms.MenuItem

Me.Button1 = New System.Windows. Forms.Button

Me.SuspendLayou t()

'

'MainMenu1

'

Me.MainMenu1.Me nuItems.AddRang e(New System.Windows. Forms.MenuItem( ) {Me.MenuItem1})

'

'MenuItem1

'

Me.MenuItem1.In dex = 0

Me.MenuItem1.Me nuItems.AddRang e(New System.Windows. Forms.MenuItem( ) {Me.MenuItem2})

Me.MenuItem1.Te xt = "bestand"

'

'MenuItem2

'

Me.MenuItem2.In dex = 0

Me.MenuItem2.Te xt = "sluiten"

'

'Button1

'

Me.Button1.Loca tion = New System.Drawing. Point(104, 104)

Me.Button1.Name = "Button1"

Me.Button1.TabI ndex = 0

Me.Button1.Text = "merge"

'

'Form1

'

Me.AutoScaleBas eSize = New System.Drawing. Size(5, 13)

Me.ClientSize = New System.Drawing. Size(292, 273)

Me.Controls.Add (Me.Button1)

Me.IsMdiContain er = True

Me.Menu = Me.MainMenu1

Me.Name = "Form1"

Me.Text = "Form1"

Me.ResumeLayout (False)

End Sub

#End Region

Private Sub MenuItem2_Click (ByVal sender As System.Object, ByVal e As System.EventArg s) Handles MenuItem2.Click

End

End Sub

Private path As String = "c:\testmod "

Private objmenu As MainMenu

Public Sub CreateMenu()

Dim refmodule As [Assembly] = [Assembly].LoadFile(path & "\testmodule.dl l")

Dim t As Type = refmodule.GetTy pe("testmodule. menu")

Dim obj As Object = Activator.Creat eInstance(t)

Dim ar As Menu = obj.getmenu()

Me.MainMenu1.Me rgeMenu(ar)

End Sub

Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles Button1.Click

CreateMenu()

End Sub

End Class

"Jon Skeet" <sk***@pobox.co m> wrote in message news:MP******** *************** *@news.microsof t.com...
[If you could make your newsreader wrap lines at about 70 characters it
would make your posts easier to reply to, by the way.]

filip stas <fi********@pan dora.be> wrote:
creating dll files containing forms so they can be applied as sort of
an add-in in to a main program. I want to call those dll files and then
dynamically add menus for the forms contained in the dll into the main
program


In that case use Assembly.Load, Assembly.LoadFr om or one of the
similarly named methods. They vary in subtle ways, so be careful which
you pick.

You then use Assembly.GetTyp e(String) to get the appropriate type, then
instantiate it by reflection etc.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too
Jul 19 '05 #7
filip stas <fi********@pan dora.be> wrote:
Okay got at lot further for now, but have a following question


<snip>

I'm afraid the combination of:

o Your post's text still not wrapping pleasantly
o The program code having a blank line between each real line
o It being in VB.NET when I'm really a C# coder
o Me not quite understanding what you're after
o Me not knowing a lot about MDI containers
o It being nearly time to go home
o Me not having got much sleep last night

makes me reluctant to tackle this at the moment.

A quick look at it suggests you should:

a) Get familiar with reflection if you're not already
b) Alter the code so it loads the DLL, finds the type, instantiates it,
casts the instance to MenuItem, and then uses it as it would do any
other menu item.

That may well not be what you're after though...

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too
Jul 19 '05 #8
Hi,

I am planning to do a quite similar thing for my
application.
I have different function that belongs to different
assembly. Based on available function on the system I need
my application to be self configurable.
Kind of plug in as you mentionned with menu belonging to
the plugin and forms if any.

Did you finnaly make it happen ? if yes how
do u have sample?

For my case I have only a main form, not MDI

thanks for your info
(I am VB programmer)
regards
Serge
-----Original Message-----
creating dll files containing forms so they can be applied as sort of an add-in in to a main program. I want
to call those dll files and then dynamically add menus for
the forms contained in the dll into the main program "Jon Skeet" <sk***@pobox.co m> wrote in message news:MP******** *************** *@news.microsof t.com... filip stas <fi********@pan dora.be> wrote:
> reference to other assemblies
That's not "exactly what you want to do" - that's 4

words. Say exactly what situation you've got, what the *aim* of this is, etc.
--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too

Jul 19 '05 #9

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

Similar topics

2
2309
by: manohar.shankar | last post by:
Hi, I have been searching on this topic for quite sometime and didnt get any answer. Is there a way I can extend/add methods/properties to a C# class during runtime. eg., I have class: public class MyClass {
3
5757
by: MIGUEL | last post by:
Hi all, I'm quite lost with how adding web references to a project creates proxy classes. I've developed a web service with two classes inside and that contains three references to three DLLs. After building it up, I've deployed it on the web server. From my Windows application, I then add a web reference to that web service.
8
384
by: filip stas | last post by:
How do i add references during runtime?
3
1993
by: _DS | last post by:
The two obvious methods for ref'ing assemblies are: Add a reference and 'Browse' for the actual DLL OR Add existing project to the solution, then add a ref to 'Project'. 1: I'd like to find out what the latter method is doing. I'm assuming that it makes sure that debug exe gets matched to
5
49805
by: Michael Russell | last post by:
Hi all, Using C#, I've created a simple wrapper class for using Excel. I have Office Pro 2003 installed on my devel machine. The wrapper class works great, reading and writing to/from Excel. To do this, I created a reference to "Microsoft Excel 11.0 Object Library", and have a "using Excel;" directive. I decided to add a method for creating a TextBox using the Shapes.AddTextBox method, which requires a
32
1474
by: Zytan | last post by:
Are they possible? I am passing in a large array of Bytes, thus I don't want to use ByVal. Zytan
4
1395
by: krishm | last post by:
hi i have a COM dll and i want to access the methods in the dll through my program. but i need to add that dll as reference during runtime and not the way references are generally added (project-->add reference-->COM and all that) can anybody help me out with this plz thanx krish
5
4461
by: DBC User | last post by:
I have a situation, where I need to add 4 or 5 data files (they change every time I build) in my project during build time and somehow I need a way to access these files during runtime. So I have 2 questions 1. Is it possible to identify all the files in the resource file during runtime by name of the file? 2. Is it possible to add files to a project at build time to make an exe with those files? Thanks.
7
10066
by: chage | last post by:
Hi, I have been searching around to try adding reference assembly to another assembly during runtime, programatically. Is this possible in .Net? The reason for this is because i am having trouble using a library that creates an instance of a Type that i specified, and it failed the locate the Type during runtime, if i do not reference it during compile time.
0
8253
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8189
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8692
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8635
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8354
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8497
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7182
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4192
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2621
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.