CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2000
    Location
    Germany, Franken
    Posts
    257

    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
    Last edited by Akademos; July 10th, 2009 at 04:30 PM.

  2. #2
    Join Date
    Jun 2008
    Posts
    2,477

    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?

  3. #3
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    Re: Strange expection with invalid Cast

    You may also want to check the TryCast() method.

  4. #4
    Join Date
    Mar 2004
    Location
    Prague, Czech Republic, EU
    Posts
    1,701

    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.
    • Make it run.
    • Make it right.
    • Make it fast.

    Don't hesitate to rate my post.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured