Return value failed in Invoke

Please support our C# advertiser: Intel Parallel Studio Home
Reply

Join Date: Jun 2008
Posts: 1
Reputation: diviner is an unknown quantity at this point 
Solved Threads: 0
diviner diviner is offline Offline
Newbie Poster

Return value failed in Invoke

 
0
  #1
Dec 5th, 2008
Hi all,

My problem is continue from this post:
http://social.msdn.microsoft.com/For...d-4c13d959e5f1

I created a Unit Test by NUnit to test the method which is stored in DLL. The method should return a complex type variable (an object instance, Company for example). When the calling side (in Unit Test module) cast the type from Object to Company, the simular error is thrown:

==========
Unit Test side:
==========
  1. private Company CreateCompany(Client client)
  2. {
  3. PluginManager.Plugins.FindPlugins(@"C:\...\Plugins", null);
  4. Object Xyz_Plugin = PluginManager.Plugins.AvailablePlugins.Find("Xyz_Plugin").Instance;
  5. Object company = QuickReflection.Invoke(Xyz_Plugin, "CreateCompany", client);
  6. return (Company)company; // Error here...
  7. }

I started to understand what is binding context in assembly. This is the error message which thrown by casting task (can see it from NUnit working form):

word8.Plugin_test.CreateCompany_test:
System.InvalidCastException :
[A]word8.Xyz_Library.CompanyModule.Company cannot be cast to [B]word8.Xyz_Library.CompanyModule.Company.

Type A originates from 'Xyz_Library, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' in the context 'LoadNeither' at location 'C:\Development(5)\Projects\word8_net\word8\word8\bin\Debug\Plugins\Xyz_Library.dll'.

Type B originates from 'Xyz_Library, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' in the context 'Default' at location 'C:\Documents and Settings\Administrator\Local Settings\Temp\nunit20\ShadowCopyCache\3816_633640437807493750\Tests\assembly\dl3\e0402b93\6c49ad91_4456c901\Xyz_Library.DLL'.


I think becase the custom type Company are come from difference DLL. But, I still do not know how to get rid of it.

The project source is short like before, and place here: http://www.box.net/shared/1y7o6r5xtu
Or here: http://www.adrive.com/public/76d8dc4...fbfaa853e.html

Hope you can help me again. Thank you very much.

Best regards,
Diviner.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 66
Reputation: Renukavani is an unknown quantity at this point 
Solved Threads: 6
Renukavani Renukavani is offline Offline
Junior Poster in Training

Re: Return value failed in Invoke

 
0
  #2
Dec 9th, 2008
hi divine
im also not sure plz
Object plugin = PluginManager.Plugins.AvailablePlugins.Find("Xyz_Plugin").Instance;
return (Form)QuickReflection.MyInvoke(plugin, "CreateXyzForm", client);


public static Object MyInvoke(Object target, String method, params Object[] args)
{
MethodInfo methodInfo = target.GetType().GetMethod(method);
return methodInfo.Invoke(target, args);
}

The Called side (DLL party) like this:

public Form CreateXyzForm(Client client)
{
.....
}
first let chk client s what datatype
passing parameter datatype and geting val datatype, the both datatype should be same.in my knowledge i think datatype s differ.makeit same then wil c ? s the probelm

Originally Posted by diviner View Post
Hi all,

My problem is continue from this post:
http://social.msdn.microsoft.com/For...d-4c13d959e5f1

I created a Unit Test by NUnit to test the method which is stored in DLL. The method should return a complex type variable (an object instance, Company for example). When the calling side (in Unit Test module) cast the type from Object to Company, the simular error is thrown:

==========
Unit Test side:
==========
  1. private Company CreateCompany(Client client)
  2. {
  3. PluginManager.Plugins.FindPlugins(@"C:\...\Plugins", null);
  4. Object Xyz_Plugin = PluginManager.Plugins.AvailablePlugins.Find("Xyz_Plugin").Instance;
  5. Object company = QuickReflection.Invoke(Xyz_Plugin, "CreateCompany", client);
  6. return (Company)company; // Error here...
  7. }

I started to understand what is binding context in assembly. This is the error message which thrown by casting task (can see it from NUnit working form):

word8.Plugin_test.CreateCompany_test:
System.InvalidCastException :
[A]word8.Xyz_Library.CompanyModule.Company cannot be cast to [B]word8.Xyz_Library.CompanyModule.Company.

Type A originates from 'Xyz_Library, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' in the context 'LoadNeither' at location 'C:\Development(5)\Projects\word8_net\word8\word8\bin\Debug\Plugins\Xyz_Library.dll'.

Type B originates from 'Xyz_Library, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' in the context 'Default' at location 'C:\Documents and Settings\Administrator\Local Settings\Temp\nunit20\ShadowCopyCache\3816_633640437807493750\Tests\assembly\dl3\e0402b93\6c49ad91_4456c901\Xyz_Library.DLL'.


I think becase the custom type Company are come from difference DLL. But, I still do not know how to get rid of it.

The project source is short like before, and place here: http://www.box.net/shared/1y7o6r5xtu
Or here: http://www.adrive.com/public/76d8dc4...fbfaa853e.html

Hope you can help me again. Thank you very much.

Best regards,
Diviner.
signOut
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC