Hi all,

My problem is continue from this post:
http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/353b5bd8-b86e-403a-883d-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:
==========

private Company CreateCompany(Client client)
{
    PluginManager.Plugins.FindPlugins(@"C:\...\Plugins", null);
    Object Xyz_Plugin = PluginManager.Plugins.AvailablePlugins.Find("Xyz_Plugin").Instance;
    Object company = QuickReflection.Invoke(Xyz_Plugin, "CreateCompany", client);
    return (Company)company;   // Error here...
}

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 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/76d8dc4d6ad0b6c31a6bdd9a181ede62cd6fa5d2941d4802711a9b5fbfaa853e.html

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

Best regards,
Diviner.

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

Hi all,

My problem is continue from this post:
http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/353b5bd8-b86e-403a-883d-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:
==========

private Company CreateCompany(Client client)
{
    PluginManager.Plugins.FindPlugins(@"C:\...\Plugins", null);
    Object Xyz_Plugin = PluginManager.Plugins.AvailablePlugins.Find("Xyz_Plugin").Instance;
    Object company = QuickReflection.Invoke(Xyz_Plugin, "CreateCompany", client);
    return (Company)company;   // Error here...
}

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 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/76d8dc4d6ad0b6c31a6bdd9a181ede62cd6fa5d2941d4802711a9b5fbfaa853e.html

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

Best regards,
Diviner.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.