bchavez / RethinkDb.Driver

:headphones: A NoSQL C#/.NET RethinkDB database driver with 100% ReQL API coverage.
http://rethinkdb.com/api/java
Other
384 stars 134 forks source link

BadImageFormatException on insert #108

Closed nihiluis closed 7 years ago

nihiluis commented 7 years ago

I'm using Mono 4.6.1 on Arch Linux with RethinkDb.Driver.dll 2.3.15 from NuGet. When inserting a POCO a BadImageFormatException is thrown. Not sure what it means tbh.

Here is my code

public async void RegisterClient(Client client, string mail, string password) {
            Account account = new Account {
                Name = client.name,
                Mail = mail,
                Password = PasswordHash.HashPassword(password),
                Ip = client.address,
                RegisterDate = DateTime.Now,
                LastLoginDate = DateTime.Now,
                Online = true,
                HandMoney = 0,
                BankMoney = 0,
                PosX = Ptolemy.NewPlayerPosition.X,
                PosY = Ptolemy.NewPlayerPosition.Y,
                PosZ = Ptolemy.NewPlayerPosition.Z,
                Rot = Ptolemy.NewPlayerRotation.Z,
                ModelName = "ReporterCutscene",
                Model = 1,
            };
            await DatabaseManager.R.Table(ACCOUNT_TABLE_NAME).Insert(account).RunAsync<Account>(DatabaseManager.Connection);
        }

and my poco

public class Account {
        [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
        public string Id { get; set; }
        public string Name { get; set; }
        public string Mail { get; set; }
        public string Password { get; set; }

        public string Ip { get; set; }
        public DateTime? RegisterDate { get; set; }
        public DateTime? LastLoginDate { get; set; }

        public bool Online { get; set; }

        public int HandMoney { get; set; }
        public int BankMoney { get; set; }

        public float PosX { get; set; }
        public float PosY { get; set; }
        public float PosZ { get; set; }
        public float Rot { get; set; }
        public int Model { get; set; }
        public string ModelName { get; set; }
    }
System.BadImageFormatException: Could not resolve field token 0x0400000e
File name: 'RethinkDb.Driver'
  at RethinkDb.Driver.Net.SocketWrapper.SendQuery (System.Int64 token, System.String json, System.Boolean awaitResponse, System.Threading.CancellationToken cancelToken) [0x000e4] in <386b15d62b7d41e587de633927ebc39b>:0 
  at RethinkDb.Driver.Net.Connection.SendQuery (RethinkDb.Driver.Ast.Query query, System.Threading.CancellationToken cancelToken, System.Boolean awaitResponse) [0x00025] in <386b15d62b7d41e587de633927ebc39b>:0 
  at RethinkDb.Driver.Net.Connection+<RunQueryAsync>d__501[T].MoveNext () [0x0000a] in <386b15d62b7d41e587de633927ebc39b>:0 
--- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <dca3b561b8ad4f9fb10141d81b39ff45>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0004e] in <dca3b561b8ad4f9fb10141d81b39ff45>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in <dca3b561b8ad4f9fb10141d81b39ff45>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x0000b] in <dca3b561b8ad4f9fb10141d81b39ff45>:0 
  at System.Runtime.CompilerServices.TaskAwaiter`1[TResult].GetResult () [0x00000] in <dca3b561b8ad4f9fb10141d81b39ff45>:0 
  at PtolemyServer.Data.AccountManager+<RegisterClient>c__async0.MoveNext () [0x00152] in <aaf75a2afe77412cb03ee46449fddfb9>:0 
--- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <dca3b561b8ad4f9fb10141d81b39ff45>:0 
  at System.Runtime.CompilerServices.AsyncMethodBuilderCore.<ThrowAsync>m__1 (System.Object state) [0x00000] in <dca3b561b8ad4f9fb10141d81b39ff45>:0 
  at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context (System.Object state) [0x0000e] in <dca3b561b8ad4f9fb10141d81b39ff45>:0 
  at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x0008d] in <dca3b561b8ad4f9fb10141d81b39ff45>:0 
  at System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in <dca3b561b8ad4f9fb10141d81b39ff45>:0 
  at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem () [0x0002a] in <dca3b561b8ad4f9fb10141d81b39ff45>:0 
  at System.Threading.ThreadPoolWorkQueue.Dispatch () [0x00096] in <dca3b561b8ad4f9fb10141d81b39ff45>:0 
  at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback () [0x00000] in <dca3b561b8ad4f9fb10141d81b39ff45>:0 

Before submitting your issue, please review the following checklist:

bchavez commented 7 years ago

Hi @nihiluis ,

The exception message is a bit cryptic. I suspect Mono is expecting to see some kind of Object.field value somewhere and it's not finding it during runtime.

Not totally sure how to resolve this, but you might want to try:

Make doubly sure to remove all traces of the driver from NuGet package (obj/tmp compiler artifacts). The mono_build\* DLLs were built specifically with the mono compiler. The NuGet package DLLs were built from MSBuild / VS2015 compiler, so there might be some edge case incompatibility you've run into with Microsoft's compiler.

Let me know how that goes.

Thanks, Brian

:zzz: :zzz: "You don't want to... Wake, push through"

nihiluis commented 7 years ago

Thanks for your help, it works now.

Upgrading Mono was not successful and replacing the RethinkDb was not enough. However replacing the 3 other DLLs (Logging and JSON) worked.

bchavez commented 7 years ago

Agh, Good, glad you got it working. By any chance, did your NuGet download have the Newtonsoft v9 dependency or v10 dependency? Looks like Newtonsoft v10 was released today that could have possibly been the source of your issue.

nihiluis commented 7 years ago

No. The actual Newtonsoft dependency is from 06/22/15 (it's provided by the software im coding for, not sure why it's that old). It might just be be the opposite reason though (some old Newtonsoft version).