A不能转换为B异常 [英] A cannot be cast to B exception

查看:177
本文介绍了A不能转换为B异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的项目中有一段代码,在某些情况下可以在IIS工作进程(在HttpHandler内部)以及单独的Windows服务中运行。有一个引用的程序集(DataVisualisation.dll),我写的是网站组件和Windows服务使用,网站和服务都有自己的DLL副本。

I have a piece of code in my project which, in certain situations can be run in an IIS worker process (inside a HttpHandler) and also by a separate Windows service. There is a referenced assembly (DataVisualisation.dll) which I wrote which is used by both the website components and the Windows service, and both the website and the service have their own copy of the DLL.



[A] DataVisualisation.ReportingTimePeriod不能转换为[B] DataVisualisation.ReportingTimePeriod。类型A源于位置C:\ [project] \Actions\DataVisualisation.dll上下文LoadNeither中的DataVisualisation,Version = 1.0.0.0,Culture = neutral,PublicKeyToken = null。类型B源自位置'c:\ [project] \ LCFW\lcscheduler\bin\Debug\\的上下文默认中的DataVisualisation,Version = 1.0.0.0,Culture = neutral,PublicKeyToken = null \\ dataVisualisation.dll'。

提供此代码的代码很简单:

The code which provides this is simply:

ReportingTimePeriod rp = (ReportingTimePeriod)resultFromAnotherFunction;

在网站上运行时有趣,但不是Windows服务。我不能想出来,我不知道提供什么信息来帮助任何人弄清楚。我会期望网站和服务使用自己的DataVisualisation.dll的副本,因此是相对自我包容。不知何故,不同的进程似乎知道其他DLL虽然。

Which interestingly works when running in the website, but not in the Windows Service. I can't figure that out, and I'm not sure what information to provide to help anyone else figure it out. I would have expected the website and service to be using their own individual copies of DataVisualisation.dll, and therefore be relatively self contained. Somehow, the different processes seem to know about the other DLL though.

强命名将是我的第一个调用端口,可能安装在GAC中的DLL,但不幸的是DataVisualisation .dll引用了我没有控制权的几个DLL,它们没有强名称/签名。

Strong naming would be my first port of call, potentially installing the DLL in the GAC, but unfortunately DataVisualisation.dll references a couple of DLLs I have no control over, which aren't strongly named/signed.

还有其他选择吗?我接近使用Reflection来看看我需要的属性是否存在,并访问他们的方式,但我宁愿不这样做,如果我可以避免它。

Are there any other options? I'm close to using Reflection to see if the properties I need exist and accessing them that way, but I'd rather not do that if I can avoid it.

推荐答案

我认为你的问题是你在每个项目中都有DataVisualization代码重复?

I think your problem is that you have the DataVisualisation code duplicated in each project?

ie SolutionA位于C:\ SolutionA中,其中包含Website和DataVisualisation文件夹及其下的代码。并且SolutionB位于C:\ SolutionB中,其中包含Service和DataVisualisation文件夹以及位于其下的代码。即使DataVisualization代码在2解决方案是相同的,实际的项目guid将是不同的...

i.e. SolutionA is located in C:\SolutionA with Website and DataVisualisation folders and code under it. and SolutionB is located in C:\SolutionB with Service and DataVisualisation folders and code located under it. and even though the DataVisualisation code is identical in the 2 Solutions, the actual project guid will be different...

我可以想到的唯一的另一件事是,你的参考在服务中可能是旧版本的DataVisualisation类。而是确保两个解决方案引用同一个项目(文件夹)。

The only other thing I can think of is that your reference in the service might be of an old version of the DataVisualisation class. Rather make sure both solutions reference the same project(folder).

这篇关于A不能转换为B异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆