Search code examples
c#monotypeloadexception

Could not load type from assembly (the executable)


This works fine in Windows, but when trying to run in Mono I get the following error:

Unhandled Exception:
System.TypeLoadException: Could not load type 'WLBot.LobbyBot.LobbyBot[]' from assembly 'WLBot, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
  at System.Collections.Generic.Dictionary`2[WLCommon.Matches.MatchSetupDetails,WLBot.LobbyBot.LobbyBot].InitArrays (Int32 size) [0x00000] in <filename unknown>:0 
  at System.Collections.Generic.Dictionary`2[WLCommon.Matches.MatchSetupDetails,WLBot.LobbyBot.LobbyBot].Init (Int32 capacity, IEqualityComparer`1 hcp) [0x00000] in <filename unknown>:0 
  at System.Collections.Generic.Dictionary`2[WLCommon.Matches.MatchSetupDetails,WLBot.LobbyBot.LobbyBot]..ctor () [0x00000] in <filename unknown>:0 
  at WLBot.Client.WLBotClient..ctor (System.String url, System.String botid, System.String secret) [0x00000] in <filename unknown>:0 
  at WLBot.Program.Main (System.String[] args) [0x00000] in <filename unknown>:0 
[ERROR] FATAL UNHANDLED EXCEPTION: System.TypeLoadException: Could not load type 'WLBot.LobbyBot.LobbyBot[]' from assembly 'WLBot, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
  at System.Collections.Generic.Dictionary`2[WLCommon.Matches.MatchSetupDetails,WLBot.LobbyBot.LobbyBot].InitArrays (Int32 size) [0x00000] in <filename unknown>:0 
  at System.Collections.Generic.Dictionary`2[WLCommon.Matches.MatchSetupDetails,WLBot.LobbyBot.LobbyBot].Init (Int32 capacity, IEqualityComparer`1 hcp) [0x00000] in <filename unknown>:0 
  at System.Collections.Generic.Dictionary`2[WLCommon.Matches.MatchSetupDetails,WLBot.LobbyBot.LobbyBot]..ctor () [0x00000] in <filename unknown>:0 
  at WLBot.Client.WLBotClient..ctor (System.String url, System.String botid, System.String secret) [0x00000] in <filename unknown>:0 
  at WLBot.Program.Main (System.String[] args) [0x00000] in <filename unknown>:0

This is a bit infuriating as the class is actually compiled into the exe, not separate like in a dll. All of the answers I've seen have been about trying to load types from libraries.

Even if I re-create the class in the project the same thing happens. I'm very confused as to why this is happening. How can I fix this problem?


Solution

  • Not an answer for the OP but for future googlers, I had this problem for binaries compiled on Windows and copied to the Raspberry Pi running Raspbian (jessie).

    Similarly, running on Windows was fine.

    The affected version of Mono (built from tarball) was 4.6.0.125/753c323.

    The fix was to upgrade to 4.6.1.5/ef43c15.