Casting error in ASP.NET

I have a class declared in the App_Code folder. The class contains a public generic method that returns the Portfolio type.

When I try to call this method to initialize an object of type Portfolio in one of the ASCX controls, I get the message "The value of type Jaguar.Portfolio cannot be converted to a Jaguar.Portfolio message."

This is the "Website" project. I tried using CType and DirectCast and I still get the same compilation error when I try to build a site.

I am using the line of code below in the ascx code file

Dim pObjSvc As Jaguar.Portfolio = ClassName.GetPortfolio
0


source to share


4 answers


Do you have a web page or custom control also called a portfolio? You may have a namespace conflict where it gets confused about which Portfolio to use. If so, you will need to change the class / module name or control code or code behind class and everything should be set.



+2


source


There seems to be someone else with the same problem:

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

I have an ASP.Net application that uses assemblies from several other solutions. When testing applications on my machine, I have all referenced assemblies using nmake. The latest assemblies are put into a shared directory that my ASP.NET application references.

Sometimes I get the following error: a value of type "MyNamespace.MyClassName" cannot be converted to "MyNamespace.MyClassName" (there are many for different classes) when performing a build debug. I tried the following, no luck:

Create ASP.Net application Rebuild ASP.Net application Close VS and create ASP.Net application Close VS.Net how to rebuild asp.Net application IISreset and build / rebuild application

The only thing that seems to work is if I run nmake to build all my referenced assemblies , then I can build an ASP.Net application.

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



Unfortunately, the author of the question did not find a definitive answer. But it may have a hint that might be helpful in finding a solution.

UPDATE: I'm not sure if this is even possible on the ASP.NET website, but perhaps you accidentally added a link to (temporary) information about the project itself? This explains the error. Try deleting the contents of the bin and obj folder as well.

+1


source


Just a hint for debugging:

Try renaming the Portfolio class and recompile. Maybe there is some old assembly somewhere or some other code in the .vb of your files that contains a class with the same name?

0


source


I have seen situations like this where an aspx page with the same name as the business object class was created. Do you have some aspx page with a code portfolio class?

0


source







All Articles