VB.NET DLL's With A VB.NET App 
Author Message
 VB.NET DLL's With A VB.NET App

OK I'm New to VB.NET And I'm Trying To Do Something I Do In VB6 But Can't Seem
To Do In .NET for the life of me.

What I Used To:

If VB6 I Would Right Various DLL's to Use As Plug-Ins In My Applications, I
Didn't Create A Reference For Them In The Project. I The CreateObject Function
Soemthing Like This:

Dim obj as object
set obj = CreateObject("ApplicationPlugIn.PlugInName")

Since The .NET DLL's Aren't Registered I'm Getting Errors Trying To Do The Same
Thing. I'm Hoping Someone Can Shed Some Light On What I Need To Do.

The biggest problem is I do NOT want a reference for the DLL in the Application
since The DLL May or May Not Be On The System.

Any Help Would Be Appreciated, Any code Appreciated even more!

Thanks To All,
Mike



Fri, 07 Jan 2005 05:23:48 GMT  
 VB.NET DLL's With A VB.NET App
Michael,
Look at System.Activator.CreateInstance.

What I would suggest is combine it with a custom section in your app.config
file. The section would contain a list of Plug-Ins available. Your app would
read the list. One attribute of this list would be the 'type' of object to
create. It would take the form "mynamespace.myclass, myassembly"

Where myassembly is the name of your DLL (no .DLL on the end). mynamespace
is the namespace within that DLL, and myclass would be the name of the
class...

in app.config:
<configuration>
    <configSections>
        <section name="PlugIns" type="MyApp.PlugInsSectionHandler, MyApp">
    </configSection>
    <PlugIns>
        <add plugin="My First Plug-In"
            type="MyPlugIn.PlugInClass, MyPlugIn" />
    </PlugIns>
</configuration>

A  class in your main app:
    Public Class PlugInsSectionHandler
        Inherits System.Configuration.DctioanrySectionHandler

        Protected Overrides ReadOnly Property KeyAttributeName() As String
            Get
                Return "plugin"
            End Get
        End Property

        Protected Overrides ReadOnly Property ValueAttributeName() As String
            Get
                Return "type"
            End Get
        End Property
    End Class

' In your main app initialization:
    Dim settings As IDictionary

    settings = Configuration.ConfigurationSettings.GetConfig("PlugIns")
    Dim setting As System.Collections.DictionaryEntry
    For Each setting In settings
        Debug.WriteLine(setting.Value, setting.Key)
        Dim type As Type
        type = type.GetType(setting.Value.ToString())
        If Not type Is Nothing Then
            Dim obj As Object
            obj = Activator.CreateInstance(type, New Object() {setting.Key})
        End If
    Next setting

NOTE: In the above sample my 'PlugIn' accepts the name of the plugin as a
parameter (the New Object() stuff)...

Hope this helps
Jay



Quote:
> OK I'm New to VB.NET And I'm Trying To Do Something I Do In VB6 But Can't
Seem
> To Do In .NET for the life of me.

> What I Used To:

> If VB6 I Would Right Various DLL's to Use As Plug-Ins In My Applications,
I
> Didn't Create A Reference For Them In The Project. I The CreateObject
Function
> Soemthing Like This:

> Dim obj as object
> set obj = CreateObject("ApplicationPlugIn.PlugInName")

> Since The .NET DLL's Aren't Registered I'm Getting Errors Trying To Do The
Same
> Thing. I'm Hoping Someone Can Shed Some Light On What I Need To Do.

> The biggest problem is I do NOT want a reference for the DLL in the
Application
> since The DLL May or May Not Be On The System.

> Any Help Would Be Appreciated, Any code Appreciated even more!

> Thanks To All,
> Mike



Fri, 07 Jan 2005 06:29:42 GMT  
 VB.NET DLL's With A VB.NET App
Hi Jay,

I Tried What You Suggested And On:

obj = Activator.CreateInstance(type, New Object() {Setting.Key})

I'm Getting This Error:

An Unhandled exception of type 'System.MissingMethodExpression' occurred in
mscorlib.dll

Additional information: Constructor on type PTCore.InitialModule not found.

Config File Reads:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <configSections>
        <section name="PlugIns" type="PT.PlugInSectionHandler, PT" />
    </configSections>
    <PlugIns>
        <add plugin="Initial Module" type="PTCore.InitialModule, PTCore" />
    </PlugIns>
</configuration>

Any Ideas Why? I Have The DLL Compiled And In The Same Directory As The EXE

Thanks For The Help

Mike



Quote:
> Michael,
> Look at System.Activator.CreateInstance.

> What I would suggest is combine it with a custom section in your
app.config
> file. The section would contain a list of Plug-Ins available. Your app
would
> read the list. One attribute of this list would be the 'type' of object to
> create. It would take the form "mynamespace.myclass, myassembly"

> Where myassembly is the name of your DLL (no .DLL on the end). mynamespace
> is the namespace within that DLL, and myclass would be the name of the
> class...

> in app.config:
> <configuration>
>     <configSections>
>         <section name="PlugIns" type="MyApp.PlugInsSectionHandler, MyApp">
>     </configSection>
>     <PlugIns>
>         <add plugin="My First Plug-In"
>             type="MyPlugIn.PlugInClass, MyPlugIn" />
>     </PlugIns>
> </configuration>

> A  class in your main app:
>     Public Class PlugInsSectionHandler
>         Inherits System.Configuration.DctioanrySectionHandler

>         Protected Overrides ReadOnly Property KeyAttributeName() As String
>             Get
>                 Return "plugin"
>             End Get
>         End Property

>         Protected Overrides ReadOnly Property ValueAttributeName() As
String
>             Get
>                 Return "type"
>             End Get
>         End Property
>     End Class

> ' In your main app initialization:
>     Dim settings As IDictionary

>     settings = Configuration.ConfigurationSettings.GetConfig("PlugIns")
>     Dim setting As System.Collections.DictionaryEntry
>     For Each setting In settings
>         Debug.WriteLine(setting.Value, setting.Key)
>         Dim type As Type
>         type = type.GetType(setting.Value.ToString())
>         If Not type Is Nothing Then
>             Dim obj As Object
>             obj = Activator.CreateInstance(type, New Object()
{setting.Key})
>         End If
>     Next setting

> NOTE: In the above sample my 'PlugIn' accepts the name of the plugin as a
> parameter (the New Object() stuff)...

> Hope this helps
> Jay



> > OK I'm New to VB.NET And I'm Trying To Do Something I Do In VB6 But
Can't
> Seem
> > To Do In .NET for the life of me.

> > What I Used To:

> > If VB6 I Would Right Various DLL's to Use As Plug-Ins In My
Applications,
> I
> > Didn't Create A Reference For Them In The Project. I The CreateObject
> Function
> > Soemthing Like This:

> > Dim obj as object
> > set obj = CreateObject("ApplicationPlugIn.PlugInName")

> > Since The .NET DLL's Aren't Registered I'm Getting Errors Trying To Do
The
> Same
> > Thing. I'm Hoping Someone Can Shed Some Light On What I Need To Do.

> > The biggest problem is I do NOT want a reference for the DLL in the
> Application
> > since The DLL May or May Not Be On The System.

> > Any Help Would Be Appreciated, Any code Appreciated even more!

> > Thanks To All,
> > Mike



Fri, 07 Jan 2005 11:50:44 GMT  
 VB.NET DLL's With A VB.NET App
I Got It To Work By Changeing:

obj = Activator.CreateInstance(type, New Object() {Setting.Key})

To:

obj = Activator.CreateInstance(type)

Is That Correct?

Mike



Quote:
> Hi Jay,

> I Tried What You Suggested And On:

> obj = Activator.CreateInstance(type, New Object() {Setting.Key})

> I'm Getting This Error:

> An Unhandled exception of type 'System.MissingMethodExpression' occurred
in
> mscorlib.dll

> Additional information: Constructor on type PTCore.InitialModule not
found.

> Config File Reads:

> <?xml version="1.0" encoding="utf-8" ?>
> <configuration>
>     <configSections>
>         <section name="PlugIns" type="PT.PlugInSectionHandler, PT" />
>     </configSections>
>     <PlugIns>
>         <add plugin="Initial Module" type="PTCore.InitialModule, PTCore"
/>
>     </PlugIns>
> </configuration>

> Any Ideas Why? I Have The DLL Compiled And In The Same Directory As The
EXE

> Thanks For The Help

> Mike


message

> > Michael,
> > Look at System.Activator.CreateInstance.

> > What I would suggest is combine it with a custom section in your
> app.config
> > file. The section would contain a list of Plug-Ins available. Your app
> would
> > read the list. One attribute of this list would be the 'type' of object
to
> > create. It would take the form "mynamespace.myclass, myassembly"

> > Where myassembly is the name of your DLL (no .DLL on the end).
mynamespace
> > is the namespace within that DLL, and myclass would be the name of the
> > class...

> > in app.config:
> > <configuration>
> >     <configSections>
> >         <section name="PlugIns" type="MyApp.PlugInsSectionHandler,
MyApp">
> >     </configSection>
> >     <PlugIns>
> >         <add plugin="My First Plug-In"
> >             type="MyPlugIn.PlugInClass, MyPlugIn" />
> >     </PlugIns>
> > </configuration>

> > A  class in your main app:
> >     Public Class PlugInsSectionHandler
> >         Inherits System.Configuration.DctioanrySectionHandler

> >         Protected Overrides ReadOnly Property KeyAttributeName() As
String
> >             Get
> >                 Return "plugin"
> >             End Get
> >         End Property

> >         Protected Overrides ReadOnly Property ValueAttributeName() As
> String
> >             Get
> >                 Return "type"
> >             End Get
> >         End Property
> >     End Class

> > ' In your main app initialization:
> >     Dim settings As IDictionary

> >     settings = Configuration.ConfigurationSettings.GetConfig("PlugIns")
> >     Dim setting As System.Collections.DictionaryEntry
> >     For Each setting In settings
> >         Debug.WriteLine(setting.Value, setting.Key)
> >         Dim type As Type
> >         type = type.GetType(setting.Value.ToString())
> >         If Not type Is Nothing Then
> >             Dim obj As Object
> >             obj = Activator.CreateInstance(type, New Object()
> {setting.Key})
> >         End If
> >     Next setting

> > NOTE: In the above sample my 'PlugIn' accepts the name of the plugin as
a
> > parameter (the New Object() stuff)...

> > Hope this helps
> > Jay



> > > OK I'm New to VB.NET And I'm Trying To Do Something I Do In VB6 But
> Can't
> > Seem
> > > To Do In .NET for the life of me.

> > > What I Used To:

> > > If VB6 I Would Right Various DLL's to Use As Plug-Ins In My
> Applications,
> > I
> > > Didn't Create A Reference For Them In The Project. I The CreateObject
> > Function
> > > Soemthing Like This:

> > > Dim obj as object
> > > set obj = CreateObject("ApplicationPlugIn.PlugInName")

> > > Since The .NET DLL's Aren't Registered I'm Getting Errors Trying To Do
> The
> > Same
> > > Thing. I'm Hoping Someone Can Shed Some Light On What I Need To Do.

> > > The biggest problem is I do NOT want a reference for the DLL in the
> > Application
> > > since The DLL May or May Not Be On The System.

> > > Any Help Would Be Appreciated, Any code Appreciated even more!

> > > Thanks To All,
> > > Mike



Fri, 07 Jan 2005 13:53:00 GMT  
 VB.NET DLL's With A VB.NET App
Michael,
That looks correct assuming that your class only has a default constructor
(either implicit or explicit).

BTW: A default constructor is a 'Sub New' with no parameters... My Sub New
accepted a String parameter...

Hope this helps
Jay



Quote:
> I Got It To Work By Changeing:

> obj = Activator.CreateInstance(type, New Object() {Setting.Key})

> To:

> obj = Activator.CreateInstance(type)

> Is That Correct?

> Mike



> > Hi Jay,

> > I Tried What You Suggested And On:

> > obj = Activator.CreateInstance(type, New Object() {Setting.Key})

> > I'm Getting This Error:

> > An Unhandled exception of type 'System.MissingMethodExpression' occurred
> in
> > mscorlib.dll

> > Additional information: Constructor on type PTCore.InitialModule not
> found.

> > Config File Reads:

> > <?xml version="1.0" encoding="utf-8" ?>
> > <configuration>
> >     <configSections>
> >         <section name="PlugIns" type="PT.PlugInSectionHandler, PT" />
> >     </configSections>
> >     <PlugIns>
> >         <add plugin="Initial Module" type="PTCore.InitialModule, PTCore"
> />
> >     </PlugIns>
> > </configuration>

> > Any Ideas Why? I Have The DLL Compiled And In The Same Directory As The
> EXE

> > Thanks For The Help

> > Mike


> message

> > > Michael,
> > > Look at System.Activator.CreateInstance.

> > > What I would suggest is combine it with a custom section in your
> > app.config
> > > file. The section would contain a list of Plug-Ins available. Your app
> > would
> > > read the list. One attribute of this list would be the 'type' of
object
> to
> > > create. It would take the form "mynamespace.myclass, myassembly"

> > > Where myassembly is the name of your DLL (no .DLL on the end).
> mynamespace
> > > is the namespace within that DLL, and myclass would be the name of the
> > > class...

> > > in app.config:
> > > <configuration>
> > >     <configSections>
> > >         <section name="PlugIns" type="MyApp.PlugInsSectionHandler,
> MyApp">
> > >     </configSection>
> > >     <PlugIns>
> > >         <add plugin="My First Plug-In"
> > >             type="MyPlugIn.PlugInClass, MyPlugIn" />
> > >     </PlugIns>
> > > </configuration>

> > > A  class in your main app:
> > >     Public Class PlugInsSectionHandler
> > >         Inherits System.Configuration.DctioanrySectionHandler

> > >         Protected Overrides ReadOnly Property KeyAttributeName() As
> String
> > >             Get
> > >                 Return "plugin"
> > >             End Get
> > >         End Property

> > >         Protected Overrides ReadOnly Property ValueAttributeName() As
> > String
> > >             Get
> > >                 Return "type"
> > >             End Get
> > >         End Property
> > >     End Class

> > > ' In your main app initialization:
> > >     Dim settings As IDictionary

> > >     settings =

Configuration.ConfigurationSettings.GetConfig("PlugIns")

- Show quoted text -

Quote:
> > >     Dim setting As System.Collections.DictionaryEntry
> > >     For Each setting In settings
> > >         Debug.WriteLine(setting.Value, setting.Key)
> > >         Dim type As Type
> > >         type = type.GetType(setting.Value.ToString())
> > >         If Not type Is Nothing Then
> > >             Dim obj As Object
> > >             obj = Activator.CreateInstance(type, New Object()
> > {setting.Key})
> > >         End If
> > >     Next setting

> > > NOTE: In the above sample my 'PlugIn' accepts the name of the plugin
as
> a
> > > parameter (the New Object() stuff)...

> > > Hope this helps
> > > Jay



> > > > OK I'm New to VB.NET And I'm Trying To Do Something I Do In VB6 But
> > Can't
> > > Seem
> > > > To Do In .NET for the life of me.

> > > > What I Used To:

> > > > If VB6 I Would Right Various DLL's to Use As Plug-Ins In My
> > Applications,
> > > I
> > > > Didn't Create A Reference For Them In The Project. I The
CreateObject
> > > Function
> > > > Soemthing Like This:

> > > > Dim obj as object
> > > > set obj = CreateObject("ApplicationPlugIn.PlugInName")

> > > > Since The .NET DLL's Aren't Registered I'm Getting Errors Trying To
Do
> > The
> > > Same
> > > > Thing. I'm Hoping Someone Can Shed Some Light On What I Need To Do.

> > > > The biggest problem is I do NOT want a reference for the DLL in the
> > > Application
> > > > since The DLL May or May Not Be On The System.

> > > > Any Help Would Be Appreciated, Any code Appreciated even more!

> > > > Thanks To All,
> > > > Mike



Sat, 08 Jan 2005 07:22:11 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. My Vb.Net Apps will not run on other machine's with .Net Framework installed

2. Accessing vb.net class from non.vb.net apps

3. ASP.NET App v. VB.NET App

4. Conversion of VB.Net App to ASP .Net App

5. 'net use \\servername' in VB.NET

6. .NET Configuration/ VB.NET app help

7. VB.NET app does not run on OS having .NET redistributable files installed

8. VB.Net Localhost for ASP.Net app?

9. Crystal Rpts and VB.NET/ASP.NET App ?

10. Debug VB.NET DLL(Class Library) from ASP.NET page

11. (Newbie) Minimum spec for pc's running VB.net app

12. VB.NET app won't work after update to WinXP SP1

 

 
Powered by phpBB® Forum Software