0

Good morning, i tried to read a postgres database with my unity app. But when the user tries to enter his login, the following error occurs;

InvalidProgramException: Invalid IL code in Npgsql.NpgsqlCommand:get_Parameters (): IL_0000: ret

(wrapper remoting-invoke-with-check) Npgsql.NpgsqlCommand:get_Parameters () PersonManager.SelectPerson (System.String role, System.String email) (at Assets/Scripts/PersonManager.cs:23) Customer.SignIn (UnityEngine.GameObject obj) (at Assets/Scripts/Customer.cs:25) UnityEngine.Events.InvokableCall1[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[] args) (at /Users/builduser/buildslave/unity/build/Runtime/Export/UnityEvent.cs:306) UnityEngine.Events.InvokableCallList.Invoke (System.Object[] parameters) (at /Users/builduser/buildslave/unity/build/Runtime/Export/UnityEvent.cs:634) UnityEngine.Events.UnityEventBase.Invoke (System.Object[] parameters) (at /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 target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.EventFunction`1 functor) (at /Users/builduser/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/EventSystem/ExecuteEvents.cs:269) UnityEngine.EventSystems.EventSystem:Update()

I dont think the issue comes from my c# code, because when i try different methods from my terminal, it works !! meaning the code works fine without unity. So when i press on the login button , it calls the following method:

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);
        }
    }

As you can see, it only calls one method from another class , so this is the code;

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;

        }
}

In the project folder, i have a "plugin" folder in Assets containing Npgsql.dll and System.Data.dll that Unity loads in the beginning.

So i am stuck and don't really know where the problem is. Thanks in advance for a future answer

3
  • Are you going to release this app or is it used as in house app for a/your company? Commented Mar 13, 2017 at 13:34
  • it will be used for tests but i would like to understand where this bug comes from. It will not be released. Commented Mar 13, 2017 at 13:49
  • Ok. If you double click on that error from Unity error, it should take you to the line of code that is throwing that error. Please update your question with that line of code. Commented Mar 13, 2017 at 19:53

1 Answer 1

0

I think your'd better compile Npgsql under Unity3D yourself. Npgsql is open-sourced. The Npgsql.dll you got may contain incompatible contents because it was not built by Unity3D.

Sign up to request clarification or add additional context in comments.

6 Comments

Also found two issues about Unity3D.
Aren't netstandard packages supposed to be consumable by Xamarin by now?
No. Unity3D doesn't use Xamarin. It uses its own fork from a very old mono.
Ah, wasn't aware of that, thanks... In that case I'd try building Npgsql as suggested and seeing how that goes. If that works out, please let me know (I'm the Npgsql maintainer) and I'll see what we can do to make life easier for Unity3D devs.
Once issue that immediately comes to mind is that Npgsql 3.2 uses C# 7.0 features which are very unlikely to be supported by the old mono compiler. Try working with the latest 3.1.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.