gpt4 book ai didi

c# - A 类 DLL 不能转换为 B 类 DLL。 Type A originates.. from in the context LoadFrom

转载 作者:太空狗 更新时间:2023-10-29 23:14:06 25 4
gpt4 key购买 nike

我正在尝试使用 TestProject 在 Visual Studio 中测试第三方 API。我收到错误。我在测试项目和业务逻辑项目中引用了第三个 API。现在我将测试数据从测试项目传递到业务逻辑项目,出现以下错误。

[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'.

这里的问题是什么?我尝试将测试项目引用的 DLL 设置为 Copy Localfalse,反之亦然。

最佳答案

假设两个程序集(项目引用的一个和使用 LoadFrom 加载的一个)中的类型确实相同(或可转换),将“LoadFrom”程序集加载到应用程序域中应该可以解决问题。这可能不是线程安全的,但值得一试。

// 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());

关于c# - A 类 DLL 不能转换为 B 类 DLL。 Type A originates.. from in the context LoadFrom,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29978888/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com