【发布时间】:2017-08-03 11:25:02
【问题描述】:
早上好, 我试图用我的统一应用程序读取 postgres 数据库。但是当用户尝试输入他的登录名时,会出现以下错误;
InvalidProgramException:IL 代码无效 Npgsql.NpgsqlCommand:get_Parameters(): IL_0000: ret
(包装器远程调用与检查) Npgsql.NpgsqlCommand:get_Parameters () PersonManager.SelectPerson (System.String 角色,System.String 电子邮件)(在 资产/脚本/PersonManager.cs:23) Customer.SignIn (UnityEngine.GameObject obj) (在 Assets/Scripts/Customer.cs:25) UnityEngine.Events.InvokableCall
1[UnityEngine.GameObject].Invoke (System.Object[] args) (at /Users/builduser/buildslave/unity/build/Runtime/Export/UnityEvent.cs:188) UnityEngine.Events.CachedInvokableCall1[UnityEngine.GameObject].Invoke (System.Object[] 参数)(在 /Users/builduser/buildslave/unity/build/Runtime/Export/UnityEvent.cs:306) UnityEngine.Events.InvokableCallList.Invoke (System.Object[] 参数)(在 /Users/builduser/buildslave/unity/build/Runtime/Export/UnityEvent.cs:634) UnityEngine.Events.UnityEventBase.Invoke(System.Object[] 参数) (在 /Users/builduser/buildslave/unity/build/Runtime/Export/UnityEvent.cs:769) UnityEngine.Events.UnityEvent.Invoke () (在 /Users/builduser/buildslave/unity/build/Runtime/Export/UnityEvent_0.cs:53) UnityEngine.UI.Button.Press () (在 /Users/builduser/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Button.cs:35) UnityEngine.UI.Button.OnPointerClick (UnityEngine.EventSystems.PointerEventData eventData)(在 /Users/builduser/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Button.cs:44) UnityEngine.EventSystems.ExecuteEvents.Execute (IPointerClickHandler 处理程序,UnityEngine.EventSystems.BaseEventData eventData)(在 /Users/builduser/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/EventSystem/ExecuteEvents.cs:52) UnityEngine.EventSystems.ExecuteEvents.Execute[IPointerClickHandler] (UnityEngine.GameObject 目标,UnityEngine.EventSystems.BaseEventData eventData,UnityEngine.EventSystems.EventFunction`1 函子)(在 /Users/builduser/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/EventSystem/ExecuteEvents.cs:269) UnityEngine.EventSystems.EventSystem:Update()
我不认为问题出在我的 c# 代码上,因为当我从终端尝试不同的方法时,它可以工作!!意味着代码没有统一就可以正常工作。所以当我按下登录按钮时,它会调用以下方法:
public void SignIn(GameObject obj)
{
company = new Company ("localhost", "kitbox", "bluebeel");
Person person = company.PersonManager.SelectPerson("customer", obj.GetComponent<InputField> ().text);
if (person != null)
{
StateManager.Instance.person = person;
ScenesManager.OnChanges ("Intro");
}
else
{
GameObject.Find ("SignInEmailErrorPanel").GetComponent<Image> ().color = new Color(227, 78, 103, 1);
}
}
如你所见,它只调用另一个类的一个方法,所以这是代码;
public class Company{
[...]
private NpgsqlConnection Init(string host, string db, string user)
{
string connectionString;
connectionString = "Host=" + host + ";" + "Database=" +
db + ";" + "Username=" + user + ";";
NpgsqlConnection conn = new NpgsqlConnection (connectionString);
return conn;
}
public Company(string host, string db, string user)
{
try
{
this.connection = Init(host, db, user);
}
catch (Exception e)
{
throw e;
}
this.personManager = new PersonManager(this.connection);
}
[...]
}
public class PersonManager {
private NpgsqlConnection connection;
private NpgsqlCommand command;
public PersonManager(NpgsqlConnection conn)
{
this.connection = conn;
}
public Person SelectPerson(string role, string email)
{
Person person = null;
string select = SelectRole(role);
this.connection.Open();
this.command = new NpgsqlCommand(select, this.connection);
this.command.Parameters.Add(new NpgsqlParameter("email", NpgsqlDbType.Varchar)).Value = email;
NpgsqlDataReader reader = this.command.ExecuteReader();
while (reader.Read())
{
person = new Person(role, (string)reader["name"], (string)reader["address"], (string)reader["phone"], (string)reader["email"], (string)reader["password"]);
person.Id = (int)reader["id"];
}
reader.Close();
this.connection.Close();
return person;
}
}
在项目文件夹中,我在 Assets 中有一个“插件”文件夹,其中包含 Unity 在开始时加载的 Npgsql.dll 和 System.Data.dll。
所以我被卡住了,不知道问题出在哪里。提前感谢您的未来回答
【问题讨论】:
-
您是要发布此应用还是将其用作/贵公司的内部应用?
-
它将用于测试,但我想了解此错误的来源。它不会被释放。
-
好的。如果您从 Unity 错误中双击该错误,它应该会将您带到引发该错误的代码行。请使用该行代码更新您的问题。
标签: c# postgresql unity3d unity5 npgsql