views:

254

answers:

4

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

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

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

I am using the line of code listed below in the code behind file of the ascx control

Dim pObjSvc As Jaguar.Portfolio = ClassName.GetPortfolio
+2  A: 

Do you have a webpage or a user control also called Portfolio? You may have a name space collision where it's confused between which Portfolio object to use. If this is the case, you'll need to change the name of the Class/Module or the control's or page's code behind class and you should be all set.

JamesEggers
I don't think I do, else it would not show me the compilation error message that would display the same "type" on both sides of the assignment
Nick
It may not show you compilation errors when you are expecting. A quick file search will tell.
StingyJack
Remember that in VB.Net you have a default namespace with your project. That sometimes results in a collision that you can't just spot if you have a class with the same name as the default namespace.
Joel Coehoorn
I double checked - there are no class name collisions
Nick
A: 

Just a debugging tip:

Try to rename the Portfolio class and recompile. Maybe there is an old assembly somewhere or some other code in .vb your files which contains a class with the same name?

splattne
This is the first thing I tried :-)
Nick
So, you get ""Value of type Jaguar.PortfolioRenamed cannot be converted to Jaguar.PortfolioRenamed"
splattne
I was able to get in touch with the author of the web service and looks like the service has been updated but the updated service was not "built" and tested.
Nick
Ah, that explains it all. I'm glad you found what caused the problem. Maybe you can update your answer too, some if someone else had that problem in the future...
splattne
+1  A: 

There seems to be someone else with the same problem out there:

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?

Sadly, the author of the question did non find a definitive answer. But perhaps it contains a hint which could be helpful to find the solution.

UPDATE: I'm not sure if that is even possible in a ASP.NET website, but maybe you accidentally added a reference to a (temporary) assemmbly of the project itself? That would explain the error. Try also to remove the contents of bin and obj folder.

splattne
A: 

I have seen situations similar to this when an aspx page was created with the same name as a business object class. Do you have some some aspx page with a code-behind class of Portfolio as well?

patridge