invalid typecast that drives me mad…

So I was writing some code for a project – and it happened again: An error which makes no sense even after two hours of starring at it and triple-checking everything… and a call to a colleague…. The error stays and nobody understands why there even is one…

Let me tell you the complete story:

I was writing the Plugin-Interface for multeem and I had to pass several already instantiated classes to the plugin. So I added a property to the PluginInterface and implemented it this way:

As you can see…there’s the local IRC_Server_ which is of type multeem.IRC.IRCServer. Because I don’t want any other libraries in the PluginInterface definition I defined the IRC_Server in the PluginInterface as an object to make it as generic as possible.

When the plugin is initiated the already instantiated IRCServer is passed through to the plugin’s IRC_Server object…

and there it is…the typecast error…

To say it again: IRC_Server_ is of type multeem.IRC.IRCServer and value is of type System.Object and contains a multeem.IRC.IRCServer


Something is going wrong…and I don’t have any clue what it might be… do you?

If you want to take a look at the whole sourcecode…fire up your Subversion Client and checkout your own work-copy from

  1. #1 by (Alexander Groß) on August 21, 2005 - 22:08

    I’ve downloaded the source and was able to reproduce the (wrong?) behavior.

    What makes it even stranger is that it will work if you reproduce the assignment in the setter using the VS.NET immediate command window.

    The problem results of the fact that IRCServer.dll is located in the program folder (bin\Debug) and in the plugins folder (bin\Debug\Plugins). If you delete IRCServer.dll from the plugins directory it will work. Seems like .NET is confused by a type that’s defined in two assemblies that are loaded at the time of the cast/assignment.



Comments are closed.