Assembly.CreateInstance

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Osvaldo Bisignano

    #1

    Assembly.CreateInstance

    I'm using Assembly.Create Instance (3rd overload) to create an instance of one of the types included on that dll.
    But what the hell are the bindingflags? I get this exception:

    MissingMethodEx ception
    Constructor not Found on class ...

    Source: mscorlib
    TargetSite:Syst em.Object CreateInstanceI mpl(System.Refl ection.BindingF lags, System.Reflecti on.Binder, System.Object[], System.Globaliz ation.CultureIn fo, System.Object[])
    STACKTRACE:
    at System.RuntimeT ype.CreateInsta nceImpl(Binding Flags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttri butes)
    at System.Activato r.CreateInstanc e(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttri butes)
    at System.Reflecti on.Assembly.Cre ateInstance(Str ing typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttri butes)
    at Legion.Comun.fr mABM.EjecutarCo mandoDeMenu(Com andoEnum Comando) in C:\Mis Documentos\Proy ectos de Visual Studio\Local\Le gion\Legion.Com un\frmABM.vb:li ne 324

    I only want to access the default constructor.

    Thanks very much


  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: Assembly.Create Instance

    Osvaldo,

    I am curious, why are you not using Activator.Creat eInstance? It looks
    like you want to use Assembly.Create Instance so that you can pass parameters
    to the constructor, which you can do in an easier manner with
    Activator.Creat eInstance.

    You probably want to use the following combination of flags:

    BindingFlags.Cr eateInstance | BindingFlags.In stance | BindingFlags.Pu blic

    Hope this helps.


    --
    - Nicholas Paldino [.NET/C# MVP]
    - mvp@spam.guard. caspershouse.co m

    "Osvaldo Bisignano" <valdonanoNOSPA M@yahoo.com.ar> wrote in message
    news:ePk0NH6oDH A.2584@TK2MSFTN GP09.phx.gbl...
    I'm using Assembly.Create Instance (3rd overload) to create an instance of
    one of the types included on that dll.
    But what the hell are the bindingflags? I get this exception:

    MissingMethodEx ception
    Constructor not Found on class ...

    Source: mscorlib
    TargetSite:Syst em.Object CreateInstanceI mpl(System.Refl ection.BindingF lags,
    System.Reflecti on.Binder, System.Object[], System.Globaliz ation.CultureIn fo,
    System.Object[])
    STACKTRACE:
    at System.RuntimeT ype.CreateInsta nceImpl(Binding Flags bindingAttr, Binder
    binder, Object[] args, CultureInfo culture, Object[] activationAttri butes)
    at System.Activato r.CreateInstanc e(Type type, BindingFlags bindingAttr,
    Binder binder, Object[] args, CultureInfo culture, Object[]
    activationAttri butes)
    at System.Reflecti on.Assembly.Cre ateInstance(Str ing typeName, Boolean
    ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args,
    CultureInfo culture, Object[] activationAttri butes)
    at Legion.Comun.fr mABM.EjecutarCo mandoDeMenu(Com andoEnum Comando) in
    C:\Mis Documentos\Proy ectos de Visual
    Studio\Local\Le gion\Legion.Com un\frmABM.vb:li ne 324

    I only want to access the default constructor.

    Thanks very much


    Comment

    • Osvaldo Bisignano

      #3
      Re: Assembly.Create Instance

      It's a little complex. The type I want to instanciate is allocated in an
      assembly not referenced in my application. So I receive an Assembly variable
      with reflection info inside.


      "Nicholas Paldino [.NET/C# MVP]" <mvp@spam.guard .caspershouse.c om> escribió
      en el mensaje news:Ohk3DP6oDH A.3256@tk2msftn gp13.phx.gbl...[color=blue]
      > Osvaldo,
      >
      > I am curious, why are you not using Activator.Creat eInstance? It[/color]
      looks[color=blue]
      > like you want to use Assembly.Create Instance so that you can pass[/color]
      parameters[color=blue]
      > to the constructor, which you can do in an easier manner with
      > Activator.Creat eInstance.
      >
      > You probably want to use the following combination of flags:
      >
      > BindingFlags.Cr eateInstance | BindingFlags.In stance | BindingFlags.Pu blic
      >
      > Hope this helps.
      >
      >
      > --
      > - Nicholas Paldino [.NET/C# MVP]
      > - mvp@spam.guard. caspershouse.co m
      >
      > "Osvaldo Bisignano" <valdonanoNOSPA M@yahoo.com.ar> wrote in message
      > news:ePk0NH6oDH A.2584@TK2MSFTN GP09.phx.gbl...
      > I'm using Assembly.Create Instance (3rd overload) to create an instance of
      > one of the types included on that dll.
      > But what the hell are the bindingflags? I get this exception:
      >
      > MissingMethodEx ception
      > Constructor not Found on class ...
      >
      > Source: mscorlib
      > TargetSite:Syst em.Object[/color]
      CreateInstanceI mpl(System.Refl ection.BindingF lags,[color=blue]
      > System.Reflecti on.Binder, System.Object[],[/color]
      System.Globaliz ation.CultureIn fo,[color=blue]
      > System.Object[])
      > STACKTRACE:
      > at System.RuntimeT ype.CreateInsta nceImpl(Binding Flags bindingAttr,[/color]
      Binder[color=blue]
      > binder, Object[] args, CultureInfo culture, Object[] activationAttri butes)
      > at System.Activato r.CreateInstanc e(Type type, BindingFlags bindingAttr,
      > Binder binder, Object[] args, CultureInfo culture, Object[]
      > activationAttri butes)
      > at System.Reflecti on.Assembly.Cre ateInstance(Str ing typeName, Boolean
      > ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args,
      > CultureInfo culture, Object[] activationAttri butes)
      > at Legion.Comun.fr mABM.EjecutarCo mandoDeMenu(Com andoEnum Comando) in
      > C:\Mis Documentos\Proy ectos de Visual
      > Studio\Local\Le gion\Legion.Com un\frmABM.vb:li ne 324
      >
      > I only want to access the default constructor.
      >
      > Thanks very much
      >
      >[/color]


      Comment

      • Osvaldo Bisignano

        #4
        Re: Assembly.Create Instance

        May the force be with you Nicholas .... :)

        I see a reflection friend in you... it's good to know...
        Thanks very much guy, you've really helped me



        Paldino [.NET/C# MVP]" <mvp@spam.guard .caspershouse.c om> escribió en el mensaje news:Ohk3DP6oDH A.3256@tk2msftn gp13.phx.gbl...[color=blue]
        > Osvaldo,
        >
        > I am curious, why are you not using Activator.Creat eInstance? It looks
        > like you want to use Assembly.Create Instance so that you can pass parameters
        > to the constructor, which you can do in an easier manner with
        > Activator.Creat eInstance.
        >
        > You probably want to use the following combination of flags:
        >
        > BindingFlags.Cr eateInstance | BindingFlags.In stance | BindingFlags.Pu blic
        >
        > Hope this helps.
        >
        >
        > --
        > - Nicholas Paldino [.NET/C# MVP]
        > - mvp@spam.guard. caspershouse.co m
        >
        > "Osvaldo Bisignano" <valdonanoNOSPA M@yahoo.com.ar> wrote in message
        > news:ePk0NH6oDH A.2584@TK2MSFTN GP09.phx.gbl...
        > I'm using Assembly.Create Instance (3rd overload) to create an instance of
        > one of the types included on that dll.
        > But what the hell are the bindingflags? I get this exception:
        >
        > MissingMethodEx ception
        > Constructor not Found on class ...
        >
        > Source: mscorlib
        > TargetSite:Syst em.Object CreateInstanceI mpl(System.Refl ection.BindingF lags,
        > System.Reflecti on.Binder, System.Object[], System.Globaliz ation.CultureIn fo,
        > System.Object[])
        > STACKTRACE:
        > at System.RuntimeT ype.CreateInsta nceImpl(Binding Flags bindingAttr, Binder
        > binder, Object[] args, CultureInfo culture, Object[] activationAttri butes)
        > at System.Activato r.CreateInstanc e(Type type, BindingFlags bindingAttr,
        > Binder binder, Object[] args, CultureInfo culture, Object[]
        > activationAttri butes)
        > at System.Reflecti on.Assembly.Cre ateInstance(Str ing typeName, Boolean
        > ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args,
        > CultureInfo culture, Object[] activationAttri butes)
        > at Legion.Comun.fr mABM.EjecutarCo mandoDeMenu(Com andoEnum Comando) in
        > C:\Mis Documentos\Proy ectos de Visual
        > Studio\Local\Le gion\Legion.Com un\frmABM.vb:li ne 324
        >
        > I only want to access the default constructor.
        >
        > Thanks very much
        >
        > [/color]

        Comment

        • Bogdan Lachendro

          #5
          Re: Assembly.Create Instance

          On 11/5/2003 3:02 PM, Osvaldo Bisignano wrote:
          [color=blue]
          > It's a little complex. The type I want to instanciate is allocated in an
          > assembly not referenced in my application. So I receive an Assembly variable
          > with reflection info inside.[/color]

          Could you please send the code you use when you invoke
          Assembly.Create Instance(...) ? How do you create this assembly object?
          Is the type you want to instantiate public?

          regards
          Bogdan

          Comment

          • Nicholas Paldino [.NET/C# MVP]

            #6
            Re: Assembly.Create Instance

            Osvaldo,

            Does that mean it worked? =)

            --
            - Nicholas Paldino [.NET/C# MVP]
            - mvp@spam.guard. caspershouse.co m

            "Osvaldo Bisignano" <valdonanoNOSPA M@yahoo.com.ar> wrote in message
            news:%23M0zpl6o DHA.2416@TK2MSF TNGP10.phx.gbl. ..
            May the force be with you Nicholas .... :)

            I see a reflection friend in you... it's good to know...
            Thanks very much guy, you've really helped me



            Paldino [.NET/C# MVP]" <mvp@spam.guard .caspershouse.c om> escribió en el
            mensaje news:Ohk3DP6oDH A.3256@tk2msftn gp13.phx.gbl...[color=blue]
            > Osvaldo,
            >
            > I am curious, why are you not using Activator.Creat eInstance? It[/color]
            looks[color=blue]
            > like you want to use Assembly.Create Instance so that you can pass[/color]
            parameters[color=blue]
            > to the constructor, which you can do in an easier manner with
            > Activator.Creat eInstance.
            >
            > You probably want to use the following combination of flags:
            >
            > BindingFlags.Cr eateInstance | BindingFlags.In stance | BindingFlags.Pu blic
            >
            > Hope this helps.
            >
            >
            > --
            > - Nicholas Paldino [.NET/C# MVP]
            > - mvp@spam.guard. caspershouse.co m
            >
            > "Osvaldo Bisignano" <valdonanoNOSPA M@yahoo.com.ar> wrote in message
            > news:ePk0NH6oDH A.2584@TK2MSFTN GP09.phx.gbl...
            > I'm using Assembly.Create Instance (3rd overload) to create an instance of
            > one of the types included on that dll.
            > But what the hell are the bindingflags? I get this exception:
            >
            > MissingMethodEx ception
            > Constructor not Found on class ...
            >
            > Source: mscorlib
            > TargetSite:Syst em.Object[/color]
            CreateInstanceI mpl(System.Refl ection.BindingF lags,[color=blue]
            > System.Reflecti on.Binder, System.Object[],[/color]
            System.Globaliz ation.CultureIn fo,[color=blue]
            > System.Object[])
            > STACKTRACE:
            > at System.RuntimeT ype.CreateInsta nceImpl(Binding Flags bindingAttr,[/color]
            Binder[color=blue]
            > binder, Object[] args, CultureInfo culture, Object[] activationAttri butes)
            > at System.Activato r.CreateInstanc e(Type type, BindingFlags bindingAttr,
            > Binder binder, Object[] args, CultureInfo culture, Object[]
            > activationAttri butes)
            > at System.Reflecti on.Assembly.Cre ateInstance(Str ing typeName, Boolean
            > ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args,
            > CultureInfo culture, Object[] activationAttri butes)
            > at Legion.Comun.fr mABM.EjecutarCo mandoDeMenu(Com andoEnum Comando) in
            > C:\Mis Documentos\Proy ectos de Visual
            > Studio\Local\Le gion\Legion.Com un\frmABM.vb:li ne 324
            >
            > I only want to access the default constructor.
            >
            > Thanks very much
            >
            >[/color]


            Comment

            • Osvaldo Bisignano

              #7
              Re: Assembly.Create Instance

              I'ts important to note that if your constructor has optional parameters (thing, I Know, shoudn't be done) you have to pass an object array with same number of elements as constructor's parameters in the args() parameters of CreateInstance


              "Nicholas Paldino [.NET/C# MVP]" <mvp@spam.guard .caspershouse.c om> escribió en el mensaje news:Ohk3DP6oDH A.3256@tk2msftn gp13.phx.gbl...[color=blue]
              > Osvaldo,
              >
              > I am curious, why are you not using Activator.Creat eInstance? It looks
              > like you want to use Assembly.Create Instance so that you can pass parameters
              > to the constructor, which you can do in an easier manner with
              > Activator.Creat eInstance.
              >
              > You probably want to use the following combination of flags:
              >
              > BindingFlags.Cr eateInstance | BindingFlags.In stance | BindingFlags.Pu blic
              >
              > Hope this helps.
              >
              >
              > --
              > - Nicholas Paldino [.NET/C# MVP]
              > - mvp@spam.guard. caspershouse.co m
              >
              > "Osvaldo Bisignano" <valdonanoNOSPA M@yahoo.com.ar> wrote in message
              > news:ePk0NH6oDH A.2584@TK2MSFTN GP09.phx.gbl...
              > I'm using Assembly.Create Instance (3rd overload) to create an instance of
              > one of the types included on that dll.
              > But what the hell are the bindingflags? I get this exception:
              >
              > MissingMethodEx ception
              > Constructor not Found on class ...
              >
              > Source: mscorlib
              > TargetSite:Syst em.Object CreateInstanceI mpl(System.Refl ection.BindingF lags,
              > System.Reflecti on.Binder, System.Object[], System.Globaliz ation.CultureIn fo,
              > System.Object[])
              > STACKTRACE:
              > at System.RuntimeT ype.CreateInsta nceImpl(Binding Flags bindingAttr, Binder
              > binder, Object[] args, CultureInfo culture, Object[] activationAttri butes)
              > at System.Activato r.CreateInstanc e(Type type, BindingFlags bindingAttr,
              > Binder binder, Object[] args, CultureInfo culture, Object[]
              > activationAttri butes)
              > at System.Reflecti on.Assembly.Cre ateInstance(Str ing typeName, Boolean
              > ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args,
              > CultureInfo culture, Object[] activationAttri butes)
              > at Legion.Comun.fr mABM.EjecutarCo mandoDeMenu(Com andoEnum Comando) in
              > C:\Mis Documentos\Proy ectos de Visual
              > Studio\Local\Le gion\Legion.Com un\frmABM.vb:li ne 324
              >
              > I only want to access the default constructor.
              >
              > Thanks very much
              >
              > [/color]

              Comment

              • Osvaldo Bisignano

                #8
                Re: Assembly.Create Instance

                of course...

                thank you

                "Nicholas Paldino [.NET/C# MVP]" <mvp@spam.guard .caspershouse.c om> escribió
                en el mensaje news:uv8Irs6oDH A.2536@tk2msftn gp13.phx.gbl...[color=blue]
                > Osvaldo,
                >
                > Does that mean it worked? =)
                >
                > --
                > - Nicholas Paldino [.NET/C# MVP]
                > - mvp@spam.guard. caspershouse.co m
                >
                > "Osvaldo Bisignano" <valdonanoNOSPA M@yahoo.com.ar> wrote in message
                > news:%23M0zpl6o DHA.2416@TK2MSF TNGP10.phx.gbl. ..
                > May the force be with you Nicholas .... :)
                >
                > I see a reflection friend in you... it's good to know...
                > Thanks very much guy, you've really helped me
                >
                >
                >
                > Paldino [.NET/C# MVP]" <mvp@spam.guard .caspershouse.c om> escribió en el
                > mensaje news:Ohk3DP6oDH A.3256@tk2msftn gp13.phx.gbl...[color=green]
                > > Osvaldo,
                > >
                > > I am curious, why are you not using Activator.Creat eInstance? It[/color]
                > looks[color=green]
                > > like you want to use Assembly.Create Instance so that you can pass[/color]
                > parameters[color=green]
                > > to the constructor, which you can do in an easier manner with
                > > Activator.Creat eInstance.
                > >
                > > You probably want to use the following combination of flags:
                > >
                > > BindingFlags.Cr eateInstance | BindingFlags.In stance |[/color][/color]
                BindingFlags.Pu blic[color=blue][color=green]
                > >
                > > Hope this helps.
                > >
                > >
                > > --
                > > - Nicholas Paldino [.NET/C# MVP]
                > > - mvp@spam.guard. caspershouse.co m
                > >
                > > "Osvaldo Bisignano" <valdonanoNOSPA M@yahoo.com.ar> wrote in message
                > > news:ePk0NH6oDH A.2584@TK2MSFTN GP09.phx.gbl...
                > > I'm using Assembly.Create Instance (3rd overload) to create an instance[/color][/color]
                of[color=blue][color=green]
                > > one of the types included on that dll.
                > > But what the hell are the bindingflags? I get this exception:
                > >
                > > MissingMethodEx ception
                > > Constructor not Found on class ...
                > >
                > > Source: mscorlib
                > > TargetSite:Syst em.Object[/color]
                > CreateInstanceI mpl(System.Refl ection.BindingF lags,[color=green]
                > > System.Reflecti on.Binder, System.Object[],[/color]
                > System.Globaliz ation.CultureIn fo,[color=green]
                > > System.Object[])
                > > STACKTRACE:
                > > at System.RuntimeT ype.CreateInsta nceImpl(Binding Flags bindingAttr,[/color]
                > Binder[color=green]
                > > binder, Object[] args, CultureInfo culture, Object[][/color][/color]
                activationAttri butes)[color=blue][color=green]
                > > at System.Activato r.CreateInstanc e(Type type, BindingFlags[/color][/color]
                bindingAttr,[color=blue][color=green]
                > > Binder binder, Object[] args, CultureInfo culture, Object[]
                > > activationAttri butes)
                > > at System.Reflecti on.Assembly.Cre ateInstance(Str ing typeName, Boolean
                > > ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args,
                > > CultureInfo culture, Object[] activationAttri butes)
                > > at Legion.Comun.fr mABM.EjecutarCo mandoDeMenu(Com andoEnum Comando) in
                > > C:\Mis Documentos\Proy ectos de Visual
                > > Studio\Local\Le gion\Legion.Com un\frmABM.vb:li ne 324
                > >
                > > I only want to access the default constructor.
                > >
                > > Thanks very much
                > >
                > >[/color]
                >
                >[/color]


                Comment

                Working...