Could not load type from assembly (the executable)

2.5k views Asked by At

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?

2

There are 2 answers

0
fiat On BEST ANSWER

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.

4
rodrigogq On

This answer seems really interesting for you scenario: Mono-LibreOffice System.TypeLoadException

The answer quoted:

The .NET framework has a true just-in-time compiler. Mono doesn't, it has an AOT (Ahead Of Time) compiler. In other words, it aggressively compiles all the code in the assembly, not just what is about to be executed.

So instead of trying to understand the line of code (your constructor), try to think what else you might be calling. He used the var instead of declaring the variable types itself. This would prevent Mono advancing ahead of time in your process and let it decide the type when you execute.

Hope it helps you debug your code.