简体   繁体   English

无法将类型A DLL强制转换为类型B DLL。 类型A起源于上下文。

[英]Type A DLL cannot be cast to type B DLL. Type A originates.. from in the context LoadFrom

I am trying to test third pary API in visual studio using TestProject. 我正在尝试使用TestProject在Visual Studio中测试第三个pary API。 I am getting error. 我出错了。 I have referenced 3rd API in Test Project as well as in Business Logic project. 我已经在测试项目以及业务逻辑项目中引用了第三API。 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. 无法将[A] TIMSS.API.User.UserDefinedInfo.UserDefinedCustomerTechnicalDisciplinees强制转换为[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'. 类型A源自上下文'LoadFrom'中位置'C:\\ Svad \\ Trunk \\ Source \\ EBusiness \\ EBusiness.Test \\ bin'的'TIMSS.API.User,Version = 1.0.0.0,Culture = neutral,PublicKeyToken = null' \\ 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'. 类型B源自位置``C:\\ Svadlakonda \\ Srikanth \\ Trunk \\ Source \\ EBusiness \\ EBusiness.Test''的``默认''上下文中的'TIMSS.API.User,Version = 1.0.0.0,Culture = neutral,PublicKeyToken = null' \\ 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. 我试图使Test Project引用的DLL Copy Localfalse ,反之亦然。

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. 假设两个程序集中的类型确实相同(或可转换)(项目引用的类型和使用LoadFrom加载的类型),则将“ LoadFrom”程序集加载到应用程序域中应该可以解决此问题。 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());

Target framework discrepancy: 目标框架差异:

My error was caused by loading an assembly with a target framework version (eg 4.5.2) lower than another that it was referencing (eg 4.6.1) 我的错误是由加载目标框架版本(例如4.5.2)比其引用的另一个版本(例如4.6.1)低的程序集引起的

I had this error, and the only thing that fixed it was installing Microsoft .NET Framework 4.5.2 (Offline Installer) https://www.microsoft.com/en-us/download/details.aspx?id=42642 我遇到了此错误,唯一修复此错误的方法是安装Microsoft .NET Framework 4.5.2(脱机安装程序) https://www.microsoft.com/zh-cn/download/details.aspx?id=42642

I also installed SQL Server 2014 Client tools earlier, and this may also have had a positive impact by installing a newer msxml 6.0 version. 我还早些时候安装了SQL Server 2014 Client工具,并且通过安装更新​​的msxml 6.0版本也可能产生积极影响。

My error messsage was: 我的错误消息是:

[A]xx.xxxx.ClassUserDS cannot be cast to [B]xx.xxxx.ClassUserDS. 无法将[A] xx.xxxx.ClassUserDS强制转换为[B] xx.xxxx.ClassUserDS。 Type A originates from 'yyyyyy, Version=3.0.5617.31787, Culture=neutral, PublicKeyToken=657d68e01eb7c911' in the context 'Default' at location 'C:\\Users\\xxxxx\\Appdata\\Local\\assembly\\dl3\\QQ3VBMNC.EO1\\VYVECOB7.H5J\\2b6c89d2\\51158eea_9892d001\\yyyyyy.DLL'. 类型A源自'yyyyyy,版本= 3.0.5617.31787,文化=中性,PublicKeyToken = 657d68e01eb7c911'在上下文'默认'中的位置'C:\\ Users \\ xxxxx \\ Appdata \\ Local \\ assembly \\ dl3 \\ QQ3VBMNC.EO1 \\ VYVECOB7 .H5J \\ 2b6c89d2 \\ 51158eea_9892d001 \\ yyyyyy.DLL'。 Type B orginates from 'yyyyyy, Version=3.0.5617.31787' in the context 'LoadNeither' at location 'C:\\Users\\xxxxx\\Appdata\\Local\\Microsoft\\InfoPath\\FormCache4\\30083E69.D18\\cd264661b1055c58$b04f2786908cb791\\yyyyyy.dll 类型B从'yyyyyy,Version = 3.0.5617.31787'出发,位于位置'C:\\ Users \\ xxxxx \\ Appdata \\ Local \\ Microsoft \\ InfoPath \\ FormCache4 \\ 30083E69.D18 \\ cd264661b1055c58 $ b04f2786908cb791 \\ yyyyyyy.dll

I tried looking in regedit HKCU\\Software\\Microsoft\\Fusion\\ that didn't help. 我尝试查找没有帮助的regedit HKCU \\ Software \\ Microsoft \\ Fusion \\。

I tried resetting the office cache, that didn't help. 我尝试重置办公室缓存,但没有帮助。

C:\Program Files (x86)\Microsoft Office\Office15\INFOPATH.EXE /cache clearall

or 64bit office 2013:
C:\Program Files\Microsoft Office\Office15\INFOPATH.EXE /cache clearall

or 64bit office 2010
C:\Program Files\Microsoft Office\Office14\INFOPATH.EXE /cache clearall

I tried resetting the fusion (GAC) cache, I had no idea how to do that (other than running ".NET Framework 1.1 Configuration" from the start menu to have a look around.) 我尝试重置融合(GAC)缓存,但我不知道该怎么做(除了从开始菜单运行“ .NET Framework 1.1配置”以了解情况)。

This error happened when I renamed an aspx page in order to hide it. 当我重命名aspx页面以隐藏它时,发生了此错误。

In my case I've renamed a file named tutorials.aspx to tutorials-hidden.aspx. 就我而言,我已将名为tutorials.aspx的文件重命名为tutorials-hidden.aspx。 Publish was successful but when I loaded the URL there was error 500. Fixed by adding tutorials.aspx file then deleting it from the project. 发布成功,但是当我加载URL时出现错误500。已通过添加tutorials.aspx文件然后从项目中将其删除来解决。 Possibly there was some definitions left in the csproj file. 可能在csproj文件中保留了一些定义。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 防止在工作目录中加载dll,InvalidCastException类型A不能强制转换为类型B - Preventing loading dll in working directory, InvalidCastException Type A cannot be cast to Type B 加载类型库/ DLL时出错。 (来自HRESULT的异常:0x80029C4A - Error loading type library/DLL. (Exception from HRESULT: 0x80029C4A 抛出“无法从源类型转换为目标类型”错误; 尝试将数据从嵌入式dll资源传递到字段时 - “Cannot Cast from source type to destination type” eror thrown ; when attempting to pass data from embedded dll resource to a field 无法从源类型转换为目标类型 - Cannot cast from source type to destination type 将自定义类型发送到 DLL - send a custom type to DLL 错误 CS0433“Type 'X' already exists in both A.dll and B.dll”从何而来? - Where does error CS0433 "Type 'X' already exists in both A.dll and B.dll " come from? C#Type A无法转换为B类(InvalidCastException)...上下文地狱? - C# Type A cannot be casted to Type B ( InvalidCastException)… Context hell? 从dll访问用户控件类型? - Access user control type from a dll? 将类型X从组件A转换为组件B中的X - Cast Type X from Assembly A to Type X in Assembly B 如何在.NET中将类型A的对象转换为B类? - How to cast an object originated from Type A to Type B in .NET?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM