473,382 Members | 1,252 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Compact Framework - can't cast across DLLs??

Hopefully someone can explain to me why this doesn't work:

- I have an interface ("IFoo"), the source of which lives in "Assembly A"
- A class ("Foo") which implements this interface lives in "Assembly B",
which obviously has a reference to "A"
- In "Assembly C", which has references to both "A" and "B", I'm trying to
cast an instance of the class to the interface, like so:

private void SomeFunction (object o)
{
IFoo f = (IFoo) o; //looking in the debugger, I can see that "o" is an
instance of "Foo"
}

(Tthere are actually 2 classes which implement the interface, and when the
time comes to do the cast, I don't know which class it is - hence my using
an interface :)

When this runs, I get an invalid cast exception. Any idea why?? In the
assembly info files, I have the version numbers fixed, so they don't change
on every build. Also, these are Compact Framework assemblies.

Any input is appreciated!!

Derrick
Nov 16 '05 #1
1 1318
Derrick <de***********@hotmail.com> wrote:
Hopefully someone can explain to me why this doesn't work:

- I have an interface ("IFoo"), the source of which lives in "Assembly A"
- A class ("Foo") which implements this interface lives in "Assembly B",
which obviously has a reference to "A"
- In "Assembly C", which has references to both "A" and "B", I'm trying to
cast an instance of the class to the interface, like so:

private void SomeFunction (object o)
{
IFoo f = (IFoo) o; //looking in the debugger, I can see that "o" is an
instance of "Foo"
}

(Tthere are actually 2 classes which implement the interface, and when the
time comes to do the cast, I don't know which class it is - hence my using
an interface :)

When this runs, I get an invalid cast exception. Any idea why?? In the
assembly info files, I have the version numbers fixed, so they don't change
on every build. Also, these are Compact Framework assemblies.


Are you sure IFoo isn't defined in other assemblies? That's usually the
problem with this kind of thing - see
http://www.pobox.com/~skeet/csharp/plugin.html

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Asad Khan | last post by:
Hi, I have Visual Studio 2002 Enterprise Architecture Edition. I was wondering if anyone has any information on how I can develop applications for .Net Compact Framework using this IDE. I've heard...
1
by: Gary Varga | last post by:
I have an application which runs on both CE.NET and the full framework. To allow for a shared code base the following describes the assembly structure: 1) There is an executable binary for each...
1
by: Asad Khan | last post by:
Hi, I have Visual Studio 2002 Enterprise Architecture Edition. I was wondering if anyone has any information on how I can develop applications for .Net Compact Framework using this IDE. I've heard...
0
by: Kleanthis | last post by:
I have a problem, when deploying multilingual applications using cab files on Compact Framework 2.0. It seems that something is going wrong with compact framework 2.0 Below I have a description...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.