Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Parameter converting problem in a reflected method

Status
Not open for further replies.

pianoben

Programmer
May 8, 2006
13
US
I am trying to pass a complex object (a third-party component) as a parameter to a reflected method. The call to MethodBase.Invoke works properly, but when the actual method itself begins, so does the trouble.

Invariably, at runtime the method throws an exception stating that
Code:
Object of type 'RGA.Common.Services.FileMoverService.BLL.SecureFTP' cannot be converted to type 'RGA.Common.Services.FileMoverService.BLL.SecureFTP'.

As the exception text shows, each type is identical, and there should be no conversion problems. When I call the method without reflection, there are no conversion problems. With reflection, there are no problems with passing native types, i.e. ints and strings.

Can anyone shed some light on this problem?

Thanks!
 
Not shure but you can try to send it using ref or an IntPtr to that object using Marshal class to get that pointer.

________
George, M
Searches(faq333-4906),Carts(faq333-4911)
 
Thank you for your reply! Your suggestion to pass a pointer is interesting, but unfortunately the class is non-blittable, and Marshall.StructToPtr will not generate the pointer needed.
 
I've had a similar problem with a project of mine when i was trying to control and get data from a device driver.

The only solution i've managed to find it was to dynamicaly alloc memory for the structure, pass the pointer to that memory, and then Marshal it back to the structure or parse it byte by byte. Used a lot of Marshal.AllocHGlobal, Marshal.Copy and such. I even had to alloc memory for an Int64 type and then i converted it back.

I'm not shure if this can help you but i knw there's a solution maybe if you can provide more about this problem like what class you are using etc.

________
George, M
Searches(faq333-4906),Carts(faq333-4911)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top