value of type "xxx" cannot be converted to "xxx"

B

Bert Leu

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?

Thanks a lot.
 
P

PlatinumBay

Bert,

These errors indicate that Visual Studio is loading two versions of the
assemblies into memory at once. There are several things that may cause this
to happen. Here are a few things to try in order to resolve the issue.

Make sure none of the referenced assemblies have CopyLocal set to true. If
CopyLocal is true and the assembly (with the same version) is in the GAC, VS
will often load one copy from the local folder and a second one from the GAC
and get confused. What happens is that the TypeConverter attribute on the
property/object is used to convert the object to an InstanceDescriptor so
that the appropriate constructor can be used to serialize the object.
However, when CopyLocal is set to true on an assembly and the same version
of the assembly exists in the GAC, 2 copies of the assembly get loaded into
memory. VS uses the copy loaded from the GAC to create the type converter
and therefore when the object (which was instantiated by VS using the local
copy) is passed to the type converter, the object appears to be of the wrong
type because the System.Type information differs - presumably because they
come from different assemblies and the underlying runtime type handle
differs. To avoid this problem, do not set CopyLocal to True on assemblies
which are in the GAC.

Make sure when upgrading a project's assemblies from one version to another
that there are no form designers open. When the form designer is open VS
will keep a reference to any assemblies it uses in memory, even when they
are removed from the project references.

After changing the project references from one version to another close
Visual Studio and re-open it. This will make sure that no references to the
older assemblies are held in memory.

If there is more than one project in your solution, be sure to check the
references in all of the projects.

(modified from
http://devcenter.infragistics.com/Support/KnowledgeBaseArticle.aspx?ArticleID=3202)

Hope this helps,


Steve
 
J

Jesse Houwing

* Bert Leu wrote, On 5-6-2007 14:15:
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?


One common cause of this is that you're using an App_Code directory in a
WebApplication project. Rename the folder to Common or just Code and it
should work fine again.

Another is that there is a duplicate assemblie that's locked somehow in
the Temporary ASP.NET Files directory. Purging that usually helps.

Jesse
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,733
Messages
2,569,440
Members
44,832
Latest member
GlennSmall

Latest Threads

Top