The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 1,676 other followers

.NET/C# – InvalidCastException for two Objects of the same type (via: G+/Stack Overflow)

Posted by jpluimers on 2013/08/03

If you ever get something similar to

InvalidCastException: [A]Person cannot be cast to [B]Person.

then you are (or more precise: your process is) probably loading the same assembly twice, but from a different context.

.NET allows that, and for reason (side by side loading, appdomains, etc).

Delphi doesn’t (thanks Warren Postma for noticing). But a mistake you see quite often is that Delphi developers try to load the same Delphi type from both an EXE and a DLL wondering why they don’t match. If you want to spread your types in Delphi, then use BPLs (run-time packages) for that. BPLs are similar to .NET assemblies, but cannot be loaded in memory twice.

–jeroen

via c# – InvalidCastException for two Objects of the same type – Stack Overflow.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

 
%d bloggers like this: