简体   繁体   English

C#Mono:尝试使用DLL引用时出现TypeLoadException

[英]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. 我是Mono / .NET的新手,所以我不确定我是否正在添加我的引用。 I'm trying to implement Fleck WebSockets. 我正在尝试实现Fleck WebSockets。 I downloaded the source, opened the solution in MonoDevelop, and built it. 我下载了源代码,在MonoDevelop中打开了解决方案并构建了它。 I took the resulting "Fleck.dll" and "Fleck.dll.mdb" and placed them in my project's folder. 我将生成的“Fleck.dll”和“Fleck.dll.mdb”放在我项目的文件夹中。 Then, in MonoDevelop, I went to the reference editor in my solution and selected that Fleck.dll as a .NET Assembly reference. 然后,在MonoDevelop中,我转到解决方案中的引用编辑器,然后选择Fleck.dll作为.NET Assembly引用。

It seems to work correctly, MonoDevelop finds everything in that assembly. 它似乎工作正常,MonoDevelop找到该程序集中的所有内容。 If I type "Fleck." 如果我输入“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. 然后会自动弹出该DLL的所有成员,但是如果我编写一些尝试使用它的代码,则会收到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? 我究竟做错了什么?

It works fine for me. 这对我来说可以。 I am using Mono 2.10.8 on Ubuntu. 我在Ubuntu上使用Mono 2.10.8。 What I did was: 我做的是:

  1. Cloned Fleck from the repository you have pointed. 克隆的Fleck来自您指向的存储库。
  2. Ran Nuget to download needed packages for the tests (this was actually not necessary as they are already in the repository). Ran Nuget下载测试所需的软件包(实际上这不是必需的,因为它们已经存在于存储库中)。
  3. Compiled Fleck, its tests and test console application contained in solution. 编译的Fleck,其测试和测试控制台应用程序包含在解决方案中。
  4. Application ran successfully. 应用程序运行成功。
  5. NUnit reported that all tests ran successfully too. NUnit报告说所有测试也成功运行。

So I bet it should work fine. 所以我打赌它应该工作正常。 What is your version of Mono? 你的Mono版本是什么?

Oh, I also explicitly set the framework version for all mentioned projects to 4.0 (which was essential for proper compilation). 哦,我还明确地将所有提到的项目的框架版本设置为4.0(这对于正确的编译是必不可少的)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM