Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / CLR / May 2006

Tip: Looking for answers? Try searching our database.

InvalidCastException

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Lars - 29 May 2006 13:39 GMT
Hi,

I get a InvalidCastException:
-  ex {"Unable to cast object of type 'SecSoaService.NFFIServiceParameters'
to type 'SecSoaService.NFFIServiceParameters'."} System.Exception
{System.InvalidCastException}

The Object beeing casted originates from a Serialize / Deserialize
roundtrip. I have tried with both binary and soap serializer with no luck.

This is NOT ASP 2.0, but pure c#. I have seen similiar problem in blogs, but
all of these relates to ASP 2.0.

To avoid version mismatch I have located all copies of the dll on all local
hard drives and deleted them.

Lars.
Jon Skeet [C# MVP] - 29 May 2006 19:02 GMT
> I get a InvalidCastException:
> -  ex {"Unable to cast object of type 'SecSoaService.NFFIServiceParameters'
> to type 'SecSoaService.NFFIServiceParameters'."} System.Exception
> {System.InvalidCastException}

Does that type exist in multiple assemblies? If so, that's probably the
issue.

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Lars - 29 May 2006 20:38 GMT
Hi,

No, the type is not defined in another assembly, nor is there any other cached assemblies lying around.  

This is the code that fails:

The type SecSoaService.NFFIServiceParameters inherits from the abstract class ServiceParameters.
public ServiceParameters EditWebServiceParameters(ServiceParameters parameters)
{
   SecSoaService.NFFIServiceParameters param = null;
   try
   {
       param = (SecSoaService.NFFIServiceParameters)parameters; //exception is thrown.
   }
   catch (Exception ex)
   {
       System.Diagnostics.Trace.WriteLine(ex.Message);
   }

// test  
   try    
   {
       param = (SecSoaService.NFFIServiceParameters)(new SecSoaService.NFFIServiceParameters()); //no exception.
   }
   catch (Exception ex)
   {
       System.Diagnostics.Trace.WriteLine(ex.Message);
   }
   ...
}

From the watch window i extract the following:
parameters.GetType().Module.FullyQualifiedName  = "c:\\temp\\IFM\\Tool\\modules\\services\\secsoa\\SecSoaService.dll" string
and the
parameters.GetType().AssemblyQualifiedName  = "SecSoaService.NFFIServiceParameters, SecSoaService, Version=1.0.0.0, Culture=neutral, PublicKeyToken=e9c77c3cc6a7a0ac"

And the param variable gets the following values after beeing assigned:
param.GetType().Module.FullyQualifiedName  =         "C:/temp/IFM/Tool/modules/services/secsoa\\SecSoaService.dll" string

param.GetType().AssemblyQualifiedName         = "SecSoaService.NFFIServiceParameters, SecSoaService, Version=1.0.0.0, Culture=neutral, PublicKeyToken=e9c77c3cc6a7a0ac"

As you can see both types have the same Assembly Qualified name and the same Module FullyQualifiedName.

So as far as i can see these two types are identical!
The only thing that is different is the format of the FullyQualifiedName path.  

regards,
Lars



>> I get a InvalidCastException:
>> -  ex {"Unable to cast object of type 'SecSoaService.NFFIServiceParameters'
[quoted text clipped - 3 lines]
> Does that type exist in multiple assemblies? If so, that's probably the
> issue.
Jon Skeet [C# MVP] - 31 May 2006 07:55 GMT
> No, the type is not defined in another assembly, nor is there any other cached assemblies lying around.  

It looks like they're loaded into different Assembly instances though,
given the fully qualified name differences. (Even if everything was the
same, being in different Assembly instances would be a problem.)

Are either of these assemblies loaded explicitly using Assembly.Load?

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Lars - 31 May 2006 11:14 GMT
You nailed the problem :)

I changed from LoadFile to LoadFrom to enforce same context.

Thanks alot,
Lars

>> No, the type is not defined in another assembly, nor is there any other
>> cached assemblies lying around.
[quoted text clipped - 4 lines]
>
> Are either of these assemblies loaded explicitly using Assembly.Load?

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.