Method not found??

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

    #1

    Method not found??

    I've an exe that creates an object with reflection using Createinstance. All
    ok.
    Then I call method in this object, that returns a user-defined control. This
    code is executed.
    I've very strange problem in the user-defined control constructor. Some code
    is executed. This calls mybase.new, initializecompo nent, and sets some
    property on contained panels. Then the constructor calls an internal sub
    (public or private is the same, I've tried either). This sub may create some
    other objects, but this is not the problem. The problem is that when I call
    the sub from the constructor, I get this strange error:

    Method not found: Void
    MyNameSpace.Pan elPreview..ctor (MyNameSpace.Di splayArea, Byte).

    The sub I'm trying to call is
    Private Sub BindPageToPrevi ew(ByVal page As DisplayPage)



    The constructor is:

    Public Sub New(ByRef display As myobjecttype)

    MyBase.New(Dire ctCast(display, DisplayHardware Device))

    InitializeCompo nent()

    ' please note that this panelPreview is not a normal windows panel, not
    a panelpreview type object. Is it created yb designer, so it is instantiated
    by initializecompo nent

    panelPreview.Wi dth = CPU.Width * _scaleFactor

    panelPreview.He ight = (CPU.Height + display.Page(0) .Area(0).Height ) *
    _scaleFactor



    BindPageToPrevi ew(display.Page (0))

    End Sub



    The sub is defined in the same -vb file as

    Private Sub BindPageToPrevi ew(ByVal page As DisplayPage)

    [cut]

    end sub





    This same code, if called by a simple test program, works well.



    What can I do?



    thanks




  • Herfried K. Wagner [MVP]

    #2
    Re: Method not found??

    * "Trapulo" <nonscrivermi@q ui.it> scripsit:[color=blue]
    > I've an exe that creates an object with reflection using Createinstance. All
    > ok.
    > Then I call method in this object, that returns a user-defined control. This
    > code is executed.
    > I've very strange problem in the user-defined control constructor. Some code
    > is executed. This calls mybase.new, initializecompo nent, and sets some
    > property on contained panels. Then the constructor calls an internal sub
    > (public or private is the same, I've tried either). This sub may create some
    > other objects, but this is not the problem. The problem is that when I call
    > the sub from the constructor, I get this strange error:
    >
    > Method not found: Void
    > MyNameSpace.Pan elPreview..ctor (MyNameSpace.Di splayArea, Byte).
    >
    > The sub I'm trying to call is
    > Private Sub BindPageToPrevi ew(ByVal page As DisplayPage)
    >
    >
    >
    > The constructor is:
    >
    > Public Sub New(ByRef display As myobjecttype)[/color]

    Is that the ctor of 'PanelView'? Why do you pass 'display' 'ByRef'?
    The signature of this ctor is different from the ctor you try to call.

    The designer will always call the parameterless ctor to instantiate
    classes.

    --
    Herfried K. Wagner [MVP]
    <URL:http://dotnet.mvps.org/>

    Comment

    • Trapulo

      #3
      Re: Method not found??


      "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message
      news:2h16i6F831 mtU5@uni-berlin.de...[color=blue]
      > * "Trapulo" <nonscrivermi@q ui.it> scripsit:[color=green]
      > > I've an exe that creates an object with reflection using Createinstance.[/color][/color]
      All[color=blue][color=green]
      > > ok.
      > > Then I call method in this object, that returns a user-defined control.[/color][/color]
      This[color=blue][color=green]
      > > code is executed.
      > > I've very strange problem in the user-defined control constructor. Some[/color][/color]
      code[color=blue][color=green]
      > > is executed. This calls mybase.new, initializecompo nent, and sets some
      > > property on contained panels. Then the constructor calls an internal sub
      > > (public or private is the same, I've tried either). This sub may create[/color][/color]
      some[color=blue][color=green]
      > > other objects, but this is not the problem. The problem is that when I[/color][/color]
      call[color=blue][color=green]
      > > the sub from the constructor, I get this strange error:
      > >
      > > Method not found: Void
      > > MyNameSpace.Pan elPreview..ctor (MyNameSpace.Di splayArea, Byte).
      > >
      > > The sub I'm trying to call is
      > > Private Sub BindPageToPrevi ew(ByVal page As DisplayPage)
      > >
      > >
      > >
      > > The constructor is:
      > >
      > > Public Sub New(ByRef display As myobjecttype)[/color]
      >
      > Is that the ctor of 'PanelView'? Why do you pass 'display' 'ByRef'?
      > The signature of this ctor is different from the ctor you try to call.[/color]

      No, the sequence is:
      1- the client calls constructor of "display" object
      2 - on the created object the client calls a method (getEmulator)
      3 - this method create a new emulator object (the one with this sub new) and
      passes a reference to itself: return new emulator(me)...
      4 - this constructor (of emulator) fails when it calls the internal sub. All
      other construcotor's code runs.
      [color=blue]
      > The designer will always call the parameterless ctor to instantiate
      > classes.[/color]

      I know this, but the problem is at runtime and only with the client that
      creates the first object with reflection's createInstance. .. With a simple
      test client it works.

      thanks


      Comment

      • Peter Huang

        #4
        Re: Method not found??

        Hi Trapulo,

        First of all, I would like to confirm my understanding of your issue.
        From your description, I understand that you have an test Application which
        will use an object.
        If the object is created by CreateInstance( i.e. by reflection), there will
        be an exception thrown when the object is trying to new an user control.
        But if the object is created by adding reference to the object assembly and
        then New the object directly, the problem will not occur.
        That is to say, all the other code is same exception the protion how the
        object is created in the test Applicaion, and all the other code did not
        use reflection to create object.
        Have I fully understood you? If there is anything I misunderstood, please
        feel free to let me know.

        One possible cause is that you did not use the full qulified name to
        createinstance, so that the reflection did not bind to the correct version
        of assembly. So how do you use reflection to CreateInstance?

        You may try to strongname the object assembly and use the Full Qualified
        Name of the Assembly to create the object. You may follow the sample in the
        link below.
        Activator.Creat eInstance Method
        http://msdn.microsoft.com/library/de...us/cpref/html/
        frlrfsystemacti vatorclasscreat einstancetopic. asp

        Please apply my suggestion above and let me know if it helps resolve your
        problem.
        If this does not resolved the problem, can you build a reproduce sample as
        simple as possible and send to by removing the online from my email
        address? So that we can do further troubleshooting .

        Best regards,

        Peter Huang
        Microsoft Online Partner Support

        Get Secure! - www.microsoft.com/security
        This posting is provided "AS IS" with no warranties, and confers no rights.

        Comment

        • Trapulo

          #5
          Re: Method not found??

          I solved.

          You suggested the right way where to search the problem.
          The problem was that an assembly used by the object created by reflection
          was in wrong version in production application's domain. So when the created
          object created some objects from this assembly, it failed.
          Now it works.

          Thanks for your assistance.


          ""Peter Huang"" <v-phuang@online.m icrosoft.com> wrote in message
          news:ok424iiPEH A.3232@cpmsftng xa10.phx.gbl...[color=blue]
          > Hi Trapulo,
          >
          > First of all, I would like to confirm my understanding of your issue.
          > From your description, I understand that you have an test Application[/color]
          which[color=blue]
          > will use an object.
          > If the object is created by CreateInstance( i.e. by reflection), there will
          > be an exception thrown when the object is trying to new an user control.
          > But if the object is created by adding reference to the object assembly[/color]
          and[color=blue]
          > then New the object directly, the problem will not occur.
          > That is to say, all the other code is same exception the protion how the
          > object is created in the test Applicaion, and all the other code did not
          > use reflection to create object.
          > Have I fully understood you? If there is anything I misunderstood, please
          > feel free to let me know.
          >
          > One possible cause is that you did not use the full qulified name to
          > createinstance, so that the reflection did not bind to the correct version
          > of assembly. So how do you use reflection to CreateInstance?
          >
          > You may try to strongname the object assembly and use the Full Qualified
          > Name of the Assembly to create the object. You may follow the sample in[/color]
          the[color=blue]
          > link below.
          > Activator.Creat eInstance Method
          >[/color]
          http://msdn.microsoft.com/library/de...us/cpref/html/[color=blue]
          > frlrfsystemacti vatorclasscreat einstancetopic. asp
          >
          > Please apply my suggestion above and let me know if it helps resolve your
          > problem.
          > If this does not resolved the problem, can you build a reproduce sample as
          > simple as possible and send to by removing the online from my email
          > address? So that we can do further troubleshooting .
          >
          > Best regards,
          >
          > Peter Huang
          > Microsoft Online Partner Support
          >
          > Get Secure! - www.microsoft.com/security
          > This posting is provided "AS IS" with no warranties, and confers no[/color]
          rights.[color=blue]
          >[/color]


          Comment

          Working...