InvalidProgramException:无效的IL代码(postgres db和unity)

时间:2017-03-13 12:33:00

标签: c# postgresql unity3d unity5 npgsql

早上好, 我尝试用我的Unity应用程序阅读postgres数据库。但是当用户尝试输入他的登录时,会发生以下错误;

  

InvalidProgramException:中的IL代码无效   Npgsql.NpgsqlCommand:get_Parameters():IL_0000:ret

     

(包装器remoting-invoke-with-check)   Npgsql.NpgsqlCommand:get_Parameters()PersonManager.SelectPerson   (System.String角色,System.String电子邮件)(at   Assets / Scripts / 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.CachedInvokableCall 1 [UnityEngine.GameObject] .Invoke   (System.Object [] args)(at   /Users/builduser/buildslave/unity/build/Runtime/Export/UnityEvent.cs:306)   UnityEngine.Events.InvokableCallList.Invoke(System.Object []   参数)(at   /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()(at   /Users/builduser/buildslave/unity/build/Runtime/Export/UnityEvent_0.cs:53)   UnityEngine.UI.Button.Press()(at   /Users/builduser/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Button.cs:35)   UnityEngine.UI.Button.OnPointerClick   (UnityEngine.EventSystems.PointerEventData eventData)(at   /Users/builduser/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Button.cs:44)   UnityEngine.EventSystems.ExecuteEvents.Execute(IPointerClickHandler   handler,UnityEngine.EventSystems.BaseEventData eventData)(at   /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仿函数)(at   /Users/builduser/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/EventSystem/ExecuteEvents.cs:269)   UnityEngine.EventSystems.EventSystem:更新()

我不认为这个问题来自我的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中有一个“plugin”文件夹,其中包含Unity在开始时加载的Npgsql.dll和System.Data.dll。

所以我被卡住了,并不知道问题出在哪里。提前感谢您的回答

1 个答案:

答案 0 :(得分:0)

我认为你最好自己在Unity3D下编译Npgsql。 Npgsql是open-sourced。您获得的Npgsql.dll可能包含不兼容的内容,因为它不是由Unity3D构建的。