I am trying to test third pary API in visual studio using TestProject. I am getting error. I have referenced 3rd API in Test Project as well as in Business Logic project. Now I am passing test data from Test project to Business logic project getting bellow error.
[A]TIMSS.API.User.UserDefinedInfo.UserDefinedCustomerTechnicalDisciplinees cannot be cast to [B]TIMSS.API.User.UserDefinedInfo.UserDefinedCustomerTechnicalDisciplinees. Type A originates from 'TIMSS.API.User, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' in the context 'LoadFrom' at location 'C:\Svad\Trunk\Source\EBusiness\EBusiness.Test\bin\bin\TIMSS.API.User.dll'. Type B originates from 'TIMSS.API.User, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' in the context 'Default' at location 'C:\Svadlakonda\Srikanth\Trunk\Source\EBusiness\EBusiness.Test\bin\TIMSS.API.User.dll'.
What is the the problem here? I tried making Test Project referenced DLL to Copy Local
to false
and vice versa still did not work.
Assuming the types are really the same (or castable) in both assemblies (the one referenced by the project and the one loaded using LoadFrom), loading the "LoadFrom" assembly into the application domain should fix the problem. This probably isn't thread safe but it's worth trying.
// This can cause "A cannot be cast to B" errors even using two exact copies of the same DLL.
var uncastableAssembly = Assembly.LoadFrom(filename);
// This shoud solve the casting issue but there still could be other issues.
var castableAssembly = AppDomain.CurrentDomain.Load(Assembly.LoadFrom(filename).GetName());
My error was caused by loading an assembly with a target framework version (e.g 4.5.2) lower than another that it was referencing (e.g 4.6.1)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With