DWilliams
DWilliams

Reputation: 451

C# Mono: TypeLoadException when trying to use a DLL reference

I'm new to Mono/.NET so I'm not quite sure if I'm adding my reference right or not. I'm trying to implement Fleck WebSockets. I downloaded the source, opened the solution in MonoDevelop, and built it. I took the resulting "Fleck.dll" and "Fleck.dll.mdb" and placed them in my project's folder. Then, in MonoDevelop, I went to the reference editor in my solution and selected that Fleck.dll as a .NET Assembly reference.

It seems to work correctly, MonoDevelop finds everything in that assembly. If I type "Fleck." then the autocomplete pops up with all the members of that DLL, but if I write a bit of code trying to use it, I get a TypeLoadException. It compiles and runs but throws that exception immediately.

I'm using the code from an example I found so I don't think that's an issue. Here's my full exception output:

Could not load signature of Fleck.SocketWrapper:Accept due to: 
Could not load signature of Fleck.ISocket:Accept due to: 

Unhandled Exception: System.TypeLoadException: Could not load type 'Fleck.SocketWrapper' from assembly 'Fleck, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'.
at Fleck.WebSocketServer..ctor (System.String location) [0x00000] in <filename unknown>:0 
at TestServer.MainClass.Main (System.String[] args) [0x00000] in /home/danny/Projects/TestServer/Main.cs:10 
[ERROR] FATAL UNHANDLED EXCEPTION: System.TypeLoadException: Could not load type 'Fleck.SocketWrapper' from assembly 'Fleck, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'.
at Fleck.WebSocketServer..ctor (System.String location) [0x00000] in <filename unknown>:0 
at TestServer.MainClass.Main (System.String[] args) [0x00000] in /home/danny/Projects/TestServer/Main.cs:10 

What am I doing wrong?

Upvotes: 1

Views: 3868

Answers (1)

konrad.kruczynski
konrad.kruczynski

Reputation: 47551

It works fine for me. I am using Mono 2.10.8 on Ubuntu. What I did was:

  1. Cloned Fleck from the repository you have pointed.
  2. Ran Nuget to download needed packages for the tests (this was actually not necessary as they are already in the repository).
  3. Compiled Fleck, its tests and test console application contained in solution.
  4. Application ran successfully.
  5. NUnit reported that all tests ran successfully too.

So I bet it should work fine. What is your version of Mono?

Oh, I also explicitly set the framework version for all mentioned projects to 4.0 (which was essential for proper compilation).

Upvotes: 3

Related Questions