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,如需转载请自行联系原作者
目录
相关文章
|
5月前
|
Java 测试技术 数据库
hql投影查询之—— [Ljava.lang.Object; cannot be cast to cn.bdqn.guanMingSys.entity.Notice
hql投影查询之—— [Ljava.lang.Object; cannot be cast to cn.bdqn.guanMingSys.entity.Notice
|
3天前
|
Python
通过 type 和 object 之间的关联,进一步分析类型对象
通过 type 和 object 之间的关联,进一步分析类型对象
13 3
|
2月前
|
Docker 容器
成功解决:Caused by: ParsingException[Failed to parse object: expecting token of type [START_OBJECT] but
这篇文章讨论了在使用Docker启动Elasticsearch容器时遇到的一个具体问题:由于配置文件`elasticsearch.yml`解析出错导致容器启动失败。文章提供了详细的排查过程,包括查看容器的日志信息、检查并修正配置文件中的错误(特别是空格问题),并最终成功重新启动了容器。
|
2月前
|
JSON 数据格式 Python
【python】解决json.dump(字典)时报错Object of type ‘float32‘ is not JSON serializable
在使用json.dump时遇到的“Object of type ‘float32’ is not JSON serializable”错误的方法,通过自定义一个JSON编码器类来处理NumPy类型的数据。
69 1
|
12月前
|
安全 Java 编译器
解决Java中的“Unchecked cast: java.lang.Object to java.util.List”问题
解决Java中的“Unchecked cast: java.lang.Object to java.util.List”问题
593 0
|
3月前
|
JSON 前端开发 数据格式
【Python】已解决:TypeError: Object of type JpegImageFile is not JSON serializable
【Python】已解决:TypeError: Object of type JpegImageFile is not JSON serializable
58 0
|
5月前
|
JavaScript
Vue报错 Invalid default value for prop “list“: Props with type Object/Array must use a factory
Vue报错 Invalid default value for prop “list“: Props with type Object/Array must use a factory
283 0
|
5月前
R语言ggsurvplot绘制生存曲线报错 : object of type ‘symbol‘ is not subsettab
R语言ggsurvplot绘制生存曲线报错 : object of type ‘symbol‘ is not subsettab
|
5月前
FeignClient【问题】Cannot deserialize value of type``from Object value (token `JsonToken.START_OBJECT`)
FeignClient【问题】Cannot deserialize value of type``from Object value (token `JsonToken.START_OBJECT`)
685 0
|
5月前
|
JavaScript
[Vue warn]: Method “components“ has type “object“ in the component definition. Did you reference the
[Vue warn]: Method “components“ has type “object“ in the component definition. Did you reference the