943,673 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Unsolved
  • Views: 5603
  • C# RSS
Dec 5th, 2008
0

Return value failed in Invoke

Expand 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:
==========
C# Syntax (Toggle Plain Text)
  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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
diviner is offline Offline
1 posts
since Jun 2008
Dec 9th, 2008
0

Re: Return value failed in Invoke

hi divine
im also not sure plz
Quote ...
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

Click to Expand / Collapse  Quote originally posted by diviner ...
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:
==========
C# Syntax (Toggle Plain Text)
  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.
Reputation Points: 10
Solved Threads: 23
Junior Poster
Renukavani is offline Offline
123 posts
since Jul 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: Error
Next Thread in C# Forum Timeline: changing cell color datagridvew c#





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC