Method not found??

T

Trapulo

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, initializecomponent, 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.PanelPreview..ctor(MyNameSpace.DisplayArea, Byte).

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



The constructor is:

Public Sub New(ByRef display As myobjecttype)

MyBase.New(DirectCast(display, DisplayHardwareDevice))

InitializeComponent()

' 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 initializecomponent

panelPreview.Width = CPU.Width * _scaleFactor

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



BindPageToPreview(display.Page(0))

End Sub



The sub is defined in the same -vb file as

Private Sub BindPageToPreview(ByVal page As DisplayPage)

[cut]

end sub





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



What can I do?



thanks
 
H

Herfried K. Wagner [MVP]

* "Trapulo said:
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, initializecomponent, 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.PanelPreview..ctor(MyNameSpace.DisplayArea, Byte).

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



The constructor is:

Public Sub New(ByRef display As myobjecttype)

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.
 
T

Trapulo

Herfried K. Wagner said:
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.

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.
The designer will always call the parameterless ctor to instantiate
classes.

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
 
P

Peter Huang

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.CreateInstance Method
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
frlrfsystemactivatorclasscreateinstancetopic.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.
 
T

Trapulo

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top