简体   繁体   English

Unity C#应用程序KeyNotFoundException

[英]Unity C# application KeyNotFoundException

I am using unity to try and connect to a MySQL database. 我正在使用unity尝试连接到MySQL数据库。 The database runs fine, the code runs fine (in Visual studio 2010). 数据库运行正常,代码运行正常(在Visual Studio 2010中)。 However when the following is ran inside Unity: 但是当在Unity内部运行以下内容时:

// Connect to database
private static void openSqlConnection() {
    string connectionString = "Server=localhost;Database=league;Uid=android;Pwd=secret;";
    connection = new MySqlConnection(connectionString);
    try{
        connection.Open();
        Debug.Log("Connected to database.");
    }
    catch(MySql.Data.MySqlClient.MySqlException ex){
        Debug.Log(ex.Number);
        Debug.Log(ex.Message);
    }
}

This code will throw the following error: 此代码将引发以下错误:

KeyNotFoundException: The given key was not present in the dictionary.
System.Collections.Generic.Dictionary`2[System.String,System.Object].get_Item (System.String key) (at /Applications/buildAgent/work/c514da0c8183631c/mcs/class/corlib/System.Collections.Generic/Dictionary.cs:150)
MySql.Data.MySqlClient.MySqlConnectionStringBuilder.get_ExceptionInterceptors ()

This is a build for PC (ran in the editor) and to my knowledge this code runs in visual studio with the exact same MySQL DLL. 这是PC的一个版本(在编辑器中运行),据我所知,这个代码在visual studio中使用完全相同的MySQL DLL运行。 Why does it throw this odd exception? 为什么会抛出这个奇怪的例外? I would really like an easy way to connect to my SQL Database from inside unity. 我真的很想从一个统一的内部连接到我的SQL数据库。

The dll i use is: 我使用的DLL是:

MySQL\Connector NET 6.7.4\Assemblies\v2.0\MySql.Data.dll

And the try catch block seems to be useless here. 而try catch块似乎在这里毫无用处。

Unity uses Mono to run .NET code, not the standard .NET framework. Unity使用Mono来运行.NET代码,而不是标准的.NET框架。

It expects a different connection string format, which is documented here: http://mono-project.com/MySQL 它需要一种不同的连接字符串格式,在此处记录: http//mono-project.com/MySQL

Using the dll provided with this question: http://answers.unity3d.com/questions/216372/problem-with-mysql-connection.html Somehow it magically fixes it. 使用这个问题提供的DLL: http//answers.unity3d.com/questions/216372/problem-with-mysql-connection.html不知何故,它神奇地修复了它。 I have however no clue which DLL this guy used, or where to get the updated version of it. 但是我不知道这个人使用了哪个DLL,或者在哪里获得它的更新版本。 Any ideas? 有任何想法吗?

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

相关问题 KeyNotFoundException:字典中不存在给定的键(C#Unity ANDROID APP) - KeyNotFoundException: The given key was not present in the dictionary (C# Unity ANDROID APP) C#AutoMapperMappingException KeyNotFoundException - C# AutoMapperMappingException KeyNotFoundException C#中字典中的KeyNotFoundException - KeyNotFoundException in dictionary in C# C#中的KeyNotFoundException - KeyNotFoundException in C# MySql Query / C#上的KeyNotFoundException - KeyNotFoundException on MySql Query / C# System.Collections.Generic.KeyNotFoundException: '字典中不存在给定的键。' C# 窗口应用程序 - System.Collections.Generic.KeyNotFoundException: 'The given key was not present in the dictionary.' C# windows application C#:KeyNotFoundException:字典中不存在给定的键 - C#: KeyNotFoundException: The given key was not present in the dictionary 当键存在时,C#字典会抛出KeyNotFoundException - C# Dictionary throws KeyNotFoundException when key exists Xamarin.Forms - KeyNotFoundException: 字典中不存在给定的键 C# - Xamarin.Forms - KeyNotFoundException: The given key was not present in the dictionary C# C#嵌套字典-字典中的字典返回错误(KeyNotFoundException) - c# nested dictionary - dictionary in a dictionary return error (KeyNotFoundException)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM