类型:QUOT对象; X"能不能转换为类型&QUOT对象; X" [英] Object of type "X" cannot be converted to object of type "X"

查看:155
本文介绍了类型:QUOT对象; X"能不能转换为类型&QUOT对象; X"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(不能相信这尚未问过,但我找不到一个DUP)

在Visual Studio中有很多的项目,当我第一次开解,我有时会收到X型的警告对象不能转换为X型的对象。一般来说重建似乎把它赶走,但没有人知道这是什么引起,以及如何避免呢?

In Visual Studio with lots of projects, when I first open the solution, I sometimes get the warning Object of type "X" cannot be converted to object of type "X". Generally rebuilding seems to make it go away, but does anyone know what this is caused by, and how to avoid it?

更新我读地方,删除所有文件RESX和重建可以提供帮助。我不假思索地尝试这个。这不是一个好主意......

UPDATE I read somewhere that deleting all your resx files and rebuilding can help. I unthinkingly tried this. Not a good idea...

推荐答案

这真的取决于具体的情况(即模糊),但最有可能的原因是不同的程序集引用/版本。也许你有一些顶级的代码引用版本A一个dll,并引用它引用了类似的DLL版本B一库;那么:

This would really depend on the exact scenario (that is vague), but the most likely cause would be different assembly references / versions. Perhaps you have some "top level" code that references version "A" of a dll, and references a library which references version "B" of a similar dll; then:

SomeType foo = someObj.Foo;



将有 SOMETYPE (左)从A,用包含.foo SOMETYPE 从B。尽量确保所有项目都将使用所有你依赖的程序集的版本相同。

would have the SomeType (on the left) from "A", with .Foo the SomeType from "B". Try ensuring that all your projects are using the same version of all the assemblies you rely on.

另一种情况是在不同的命名空间相同的名称,但是这是一个有点一个明显的例子,我的犯罪嫌疑人的错误消息将使这个明摆着的吗?

Another scenario is the same name in different namespaces, but that is a bit of an obvious one, and I suspect the error message would make this obvious?

有一些其他场景中的类型与在相同的名称同一个命名空间(但不同的组件)与海誓山盟的冲突;这里外部别名可以提供帮助,但一个完整的PITA的工作。

There are some other scenarios where types with the same names in the same namespace (but different assemblies) conflict with eachother; here "extern aliases" can help, but are a complete PITA to work with.

这篇关于类型:QUOT对象; X"能不能转换为类型&QUOT对象; X"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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