Unable to cast object of type X to type X的解决方法

 在做控件的时候经常会遇到一个很烦人的问题,就是在测试工程中加入自己的控件,然后编辑属性的总是提示"Unable to cast object of type Xto type X"。看到这个问题,真是叫人哭笑不得啊。两个类名完全一样,何谓“无法转换” 。
      既然出了问题,就得解决,一步一步跟吧。设好环境,调试控件的设计时行为,运行的结果竟然是完全没有问题。没有问题却成了最大的问题,无从下手了,上网查查吧,还好,发现很多人也都碰到这个问题。在微软的论坛里有一个解决的方法:
This particular problem apparently arises because of several factors:
The IDE caches versions of assemblies in the following folder: 

"x\Documents and Settings\user\Local Settings\Application Data\Microsoft\VisualStudio\8.0\ProjectAssemblies" 

And at least in my case doesn't detect the particular assembly containing the type has a new version and it doesn't update the cache.

If you attach to a running instance of VS2005 and check what Modules are loaded (you may need to add the Modules window command from the Debug category in Tools > Customize...) you'll probably see two versions of your assembly are loaded, or even the same version of the assembly loaded twice: in both cases you'll see the same error message.

So first step, delete all folders in ProjectAssemblies. Next, make sure the IDE can only find ONE copy of your assembly, which is easier if you only have one copy of the DLL in your disk, and only one reference to it (or exactly the same reference from all projects) in your solution.

自己动手实践一下,删掉了cache的汇集,重新运行VS2005,问题解决了。  





本文转自纶巾客博客园博客,原文链接:http://www.cnblogs.com/guanjinke/archive/2006/12/04/581116.html,如需转载请自行联系原作者
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值