Strange expection with invalid Cast
Hello there,
I've wrote a programm. While the program is started plugins are loaded.
That worked well. Now I added a new plugin and recompiled all.
Yet I got a exception during the loading of a older plugin.
The exception tells me that:
Code:
System.InvalidCastException wurde nicht behandelt.
Message="[A]com.markus_heid.bftradingstrategies.livescoreparser.LiveScoreParser kann nicht in [B]com.markus_heid.bftradingstrategies.livescoreparser.LiveScoreParser umgewandelt werden. Der Typ \"A\" stammt von \"LiveScoreParser, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null\" im Kontext \"Default\" am Speicherort \"C:\\Users\\Markus\\Documents\\Visual Studio 2008\\Projects\\BFTradingStrategies\\BFTSGUI\\bin\\Debug\\LiveScoreParser.dll\".. Der Typ \"B\" stammt von \"LiveScoreParser, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null\" im Kontext \"LoadFrom\" am Speicherort \"C:\\Users\\Markus\\Documents\\Visual Studio 2008\\Projects\\BFTradingStrategies\\BFTSGUI\\bin\\Debug\\Plugins\\BackThe4\\LiveScoreParser.dll\".."
Source="LayThe4"
StackTrace:
bei com.markus_heid.bftradingstrategies.LayThe4.PluginLay4.Initialize(Object[] parameters) in C:\Users\Markus\Documents\Visual Studio 2008\Projects\BFTradingStrategies\LayThe4\PluginLay4.cs:Zeile 76.
bei com.markus_heid.bftradingstrategies.BFTSGUI.frmMain.AddPlugin(String strFileName) in C:\Users\Markus\Documents\Visual Studio 2008\Projects\BFTradingStrategies\BFTSGUI\frmMain.cs:Zeile 186.
bei com.markus_heid.bftradingstrategies.BFTSGUI.frmMain.FindPlugins(String strPath) in C:\Users\Markus\Documents\Visual Studio 2008\Projects\BFTradingStrategies\BFTSGUI\frmMain.cs:Zeile 123.
bei com.markus_heid.bftradingstrategies.BFTSGUI.frmMain..ctor() in C:\Users\Markus\Documents\Visual Studio 2008\Projects\BFTradingStrategies\BFTSGUI\frmMain.cs:Zeile 214.
bei com.markus_heid.bftradingstrategies.BFTSGUI.Program.Main() in C:\Users\Markus\Documents\Visual Studio 2008\Projects\BFTradingStrategies\BFTSGUI\Program.cs:Zeile 18.
bei System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
bei System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
bei Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
bei System.Threading.ThreadHelper.ThreadStart_Context(Object state)
bei System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
bei System.Threading.ThreadHelper.ThreadStart()
InnerException:
The strange thing about it, is that I haven't changed a line of code of the LiveScoreParser.
Does anyone here know what went wrong?
I'm using VS.Studio 2008 Express on Vista Home with .NET Framework 3.5. All in german.
Thanks in advance
markus
Re: Strange expection with invalid Cast
Well...it is an InvalidCastException, pretty self explanatory. Why don't you just step through the code and see where the invalid cast is occurring?
Re: Strange expection with invalid Cast
You may also want to check the TryCast() method.
Re: Strange expection with invalid Cast
Because the classes came from different assemblies. Althought they have same name and are in same namespace and the assembly file name is same, assembly where class A is defined is in another folder, then the assembly where class B is defined (code base differs). Thus CLR consideres the classed to not be same and the exception is thrown. Pay special attention to the Message of the exception.