无法将类型为'Foo.Bar'的对象强制转换为'Foo.Bar'。 [英] Unable to cast object of type 'Foo.Bar' to type 'Foo.Bar'.

查看:57
本文介绍了无法将类型为'Foo.Bar'的对象强制转换为'Foo.Bar'。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有人遇到此错误消息?


无法将类型为''Foo.Bar''的对象输入''Foo.Bar''。


我正在尝试将一个Foo.Bar类型的对象转换为一个散列

表到Foo.Bar类型的变量。


Foo.Bar data =(For.Bar)输入["数据];


谢谢,


mypetrock

Has anyone run into this error message?

Unable to cast object of type ''Foo.Bar'' to type ''Foo.Bar''.

I''m trying to cast an object of type Foo.Bar that I got out of a hash
table into a variable of type Foo.Bar.

Foo.Bar data = (For.Bar)input["Data"];

Thanks,

mypetrock

推荐答案

mypetrock schrieb:
mypetrock schrieb:

Foo。条形数据=(For.Bar)输入[数据];
Foo.Bar data = (For.Bar)input["Data"];



''Cos Foo.Bar不是For.Bar。


开个玩笑


如果您编码会发生什么情况


if(输入["数据]]是Foo.Bar)

{

System.Diagnostics.Writeline(应该是可投递的);

}

其他

{

System.Diagnostics.Writeline(typeof(Foo.Bar).FullN ame);

System.Diagnostics.Writeline((input [" Data"])。GetType()。FullName); < br $>
}




''Cos Foo.Bar is not For.Bar.

Just kidding

What happens if you code

if(input["Data"] is Foo.Bar)
{
System.Diagnostics.Writeline("Should be castable");
}
else
{
System.Diagnostics.Writeline(typeof(Foo.Bar).FullN ame);
System.Diagnostics.Writeline((input["Data"]).GetType().FullName);
}

?


" mypetrock" < my ******* @ yahoo.comwrote:
"mypetrock" <my*******@yahoo.comwrote:

有没有人遇到过这条错误消息?


无法将''Foo.Bar'类型的对象强制转换为''Foo.Bar''。


我正在尝试转换类型为Foo.Bar的对象我从一个散列的
表中得到了一个Foo.Bar类型的变量。


Foo.Bar data =(For.Bar)输入[" ;数据"];
Has anyone run into this error message?

Unable to cast object of type ''Foo.Bar'' to type ''Foo.Bar''.

I''m trying to cast an object of type Foo.Bar that I got out of a hash
table into a variable of type Foo.Bar.

Foo.Bar data = (For.Bar)input["Data"];



你可能在不同的程序集中有两个不同的Foo.Bar'。也许

你们两个都包含相同的源代码文件?


- Barry


-
http://barrkel.blogspot.com/




" Barry Kelly" < ba *********** @ gmail.com写信息

新闻:bd ******************* ************* @ 4ax.com ...

"Barry Kelly" <ba***********@gmail.comwrote in message
news:bd********************************@4ax.com...

" mypetrock" < my ******* @ yahoo.comwrote:
"mypetrock" <my*******@yahoo.comwrote:

>有没有人遇到此错误消息?

无法使用将''Foo.Bar'类型的对象强制转换为''Foo.Bar''。

我正在尝试构建一个Foo.Bar类型的对象,我从将表格转换为Foo.Bar类型的变量。

Foo.Bar data =(For.Bar)input [" Data];
>Has anyone run into this error message?

Unable to cast object of type ''Foo.Bar'' to type ''Foo.Bar''.

I''m trying to cast an object of type Foo.Bar that I got out of a hash
table into a variable of type Foo.Bar.

Foo.Bar data = (For.Bar)input["Data"];



您可能在不同的程序集中有两个不同的Foo.Bar'。也许

你们两个都包含相同的源代码文件?


You may have two different Foo.Bar''s in different assemblies. Perhaps
you have the same source code file included in both?



或者GAC中的并排程序集,或者多个程序集.LoadFrom?


David

Or side-by-side assemblies in the GAC, or multiple Assembly.LoadFrom?

David


这篇关于无法将类型为'Foo.Bar'的对象强制转换为'Foo.Bar'。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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