2008-12-26 80 views
0

我有一个在App_Code文件夹中声明的类。该类包含一个返回类型投资组合的公共共享方法。

当我尝试调用此方法在ASCX控件之一中初始化类型为Portfolio的对象时,我收到“Jaguar.Portfolio类型的值无法转换为Jaguar.Portfolio”消息。

这是一个“网站”项目。我尝试过使用CType和DirectCast,当我尝试构建网站时,仍然收到相同的编译错误。

我正在使用的代码下面列出背后的ascx控件
在ASP.NET中投射错误

 
Dim pObjSvc As Jaguar.Portfolio = ClassName.GetPortfolio

回答

2

的文件,你有一个网页或用户控制也被称为投资组合的代码行?您可能会遇到名称空间冲突,它会在要使用哪个Portfolio对象之间混淆。如果是这种情况,您需要更改类/模块的名称或控件或页面的代码,并且应该全部设置。

+0

我不认为我这样做,否则它不会显示编译错误消息,它会在作业的两侧显示相同的“类型” – Developer 2008-12-26 15:38:53

+0

当您期待时,它可能不会显示编译错误。快速文件搜索会告诉。 – StingyJack 2008-12-26 15:43:00

0

只是一个调试提示:

尝试重命名投资组合类并重新编译。也许在某个地方有一个旧程序集或.vb文件中包含一个具有相同名称的类的其他代码?

1

似乎有被别人同样的问题在那里:

ASP Net - value of type "MyNamespace.MyClassName" cannot be converted to "MyNamespace.MyClassName"

I have a ASP.Net application that uses assemblies from several other solutions. When testing the applications on my machine I build all the referenced assemblies using nmake. The latest assemblies get placed in a common directory that is referenced by my ASP.NET app.

Occasionally I receive the following error: value of type "MyNamespace.MyClassName" cannot be converted to "MyNamespace.MyClassName" (there are a lot of these for different classes) when doing a debug build. I have tried the following with no luck:

Build the ASP.Net application Rebuild the ASP.Net application Close VS and build the ASP.Net application Close VS.Net as rebuild the asp.Net application IISreset and build/rebuild the application

It seems the only thing that works is if I run nmake to build all my referenced assemblies, I can then build the ASP.Net application.

Any ideas as to what causes this? Is there an easier way to fix it?

可悲的是,这个问题笔者确实不找到一个明确的答案。但也许它包含一个提示,可能有助于找到解决方案。

更新:我不确定这是甚至可能在ASP.NET网站,但也许你不小心添加了一个项目本身(临时)组装的引用?这将解释错误。也尝试删除bin和obj文件夹的内容。

0

当一个aspx页面与业务对象类同名创建时,我看到类似于这种情况。你是否还有一些aspx页面,还有一个代码隐藏类的Portfolio?