Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ArgumentNullException in mscorlib when attempting to enumerate with First() #252

Open
lyjia opened this issue Apr 12, 2016 · 2 comments
Open

Comments

@lyjia
Copy link

lyjia commented Apr 12, 2016

Hello everyone,

I'm brand new to rethinkdb, rethinkdb-net, and LINQ, so please forgive me in advance if this is a simple error on my part or misposted in any way.

With rethinkdb 2.3.0-windows-beta (MSC 190023506) and rethinkdb-net 0.12.1, I am experiencing an ArgumentNullException when attempting to enumerate a rethinkdb query with First(). I believe I have configured the database correctly as I am able to Query.DbList() -- the app will crash if its database is missing -- so I am not really sure what is going on. I also believe the model to be defined correctly, as I have copied the provided example with only a minimum of changes.

The line that crashes is supposed to be a fairly mundane account lookup. The app is a new project so I can not say I have seen rethinkdb-net work prior, other than the example I gave. The lines are (assuming the rest of this code works):

string accountName = parts[0];
var table = Models.Account.Table;
var res = conn.Run(table.Filter(r => r.username == accountName));
Models.Account acct = res.First(); #throws System.AggregateException: One or more errors occurred. ---> System.ArgumentNullException: Value cannot be null.

If I attempt to explore the model with Intermediate Window, whatever result is obscured:

conn.Run(Models.Account.Table)
{RethinkDb.SynchronousApiExtensions.AsyncEnumerableSynchronizer<Alpha.Server.Models.Account>}
    Results View: Expanding the Results View will enumerate the IEnumerable

Expanding this view using debug tooltips reveals... the same exception, buried inside.

Theres a bunch of references to DataContractDatumConverterFactory near the top of the stack trace, though I am not sure what to make of the entire trace. Am I experiencing a bug?

The entire stack trace is as follows:

System.AggregateException: One or more errors occurred. ---> System.ArgumentNullException: Value cannot be null.
Parameter name: con
   at System.Reflection.Emit.ILGenerator.Emit(OpCode opcode, ConstructorInfo con)
   at RethinkDb.DatumConverters.DataContractDatumConverterFactory.DefineConvertDatum[T](TypeBuilder type, FieldInfo datumConverterFactoryField)
   at RethinkDb.DatumConverters.DataContractDatumConverterFactory.Create[T]()
   at System.Lazy`1.CreateValue()
   at System.Lazy`1.LazyInitValue()
   at RethinkDb.DatumConverters.DataContractDatumConverterFactory.TryGet[T](IDatumConverterFactory rootDatumConverterFactory, IDatumConverter`1& datumConverter)
   at RethinkDb.DatumConverters.AggregateDatumConverterFactory.TryGet[T](IDatumConverterFactory rootDatumConverterFactory, IDatumConverter`1& datumConverter)
   at RethinkDb.QueryConverter.TryGet[T](IDatumConverterFactory rootDatumConverterFactory, IDatumConverter`1& datumConverter)
   at RethinkDb.DatumConverters.DatumConverterFactoryExtensions.Get[T](IDatumConverterFactory datumConverterFactory, IDatumConverterFactory rootDatumConverterFactory)
   at RethinkDb.DatumConverters.DatumConverterFactoryExtensions.Get[T](IDatumConverterFactory datumConverterFactory)
   at RethinkDb.Connection.QueryEnumerator`1..ctor(Connection connection, IQueryConverter queryConverter, ISequenceQuery`1 queryObject)
   at RethinkDb.Connection.RunAsync[T](IQueryConverter queryConverter, ISequenceQuery`1 queryObject)
   at RethinkDb.ConnectionFactories.ReliableConnectionFactory.ReliableConnectionWrapper.<RunAsync>c__AnonStorey2`1.<>m__0()
   at RethinkDb.ConnectionFactories.ReliableConnectionFactory.RetryAsyncEnumeratorWrapper`1.<MoveNext>c__async0.MoveNext()
   --- End of inner exception stack trace ---
   at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
   at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
   at RethinkDb.TaskUtilities.ExecuteSynchronously[T](Func`1 taskDelegate)
   at RethinkDb.SynchronousApiExtensions.AsyncEnumeratorSynchronizer`1.MoveNext()
   at System.Linq.Enumerable.First[TSource](IEnumerable`1 source)
   at Daedalus.Server.ServerInstance.appServer_NewRequestReceived(AppSession session, StringRequestInfo requestInfo) in C:\Users\user\Dropbox\Projects\alpha2016\src\alpha\Server\ServerInstance.cs:line 100
   at SuperSocket.SocketBase.AppServerBase`2.ExecuteCommand(TAppSession session, TRequestInfo requestInfo)
---> (Inner Exception #0) System.ArgumentNullException: Value cannot be null.
Parameter name: con
   at System.Reflection.Emit.ILGenerator.Emit(OpCode opcode, ConstructorInfo con)
   at RethinkDb.DatumConverters.DataContractDatumConverterFactory.DefineConvertDatum[T](TypeBuilder type, FieldInfo datumConverterFactoryField)
   at RethinkDb.DatumConverters.DataContractDatumConverterFactory.Create[T]()
   at System.Lazy`1.CreateValue()
   at System.Lazy`1.LazyInitValue()
   at RethinkDb.DatumConverters.DataContractDatumConverterFactory.TryGet[T](IDatumConverterFactory rootDatumConverterFactory, IDatumConverter`1& datumConverter)
   at RethinkDb.DatumConverters.AggregateDatumConverterFactory.TryGet[T](IDatumConverterFactory rootDatumConverterFactory, IDatumConverter`1& datumConverter)
   at RethinkDb.QueryConverter.TryGet[T](IDatumConverterFactory rootDatumConverterFactory, IDatumConverter`1& datumConverter)
   at RethinkDb.DatumConverters.DatumConverterFactoryExtensions.Get[T](IDatumConverterFactory datumConverterFactory, IDatumConverterFactory rootDatumConverterFactory)
   at RethinkDb.DatumConverters.DatumConverterFactoryExtensions.Get[T](IDatumConverterFactory datumConverterFactory)
   at RethinkDb.Connection.QueryEnumerator`1..ctor(Connection connection, IQueryConverter queryConverter, ISequenceQuery`1 queryObject)
   at RethinkDb.Connection.RunAsync[T](IQueryConverter queryConverter, ISequenceQuery`1 queryObject)
   at RethinkDb.ConnectionFactories.ReliableConnectionFactory.ReliableConnectionWrapper.<RunAsync>c__AnonStorey2`1.<>m__0()
   at RethinkDb.ConnectionFactories.ReliableConnectionFactory.RetryAsyncEnumeratorWrapper`1.<MoveNext>c__async0.MoveNext()<---

Thank you for looking into this.

Tom

@mfenniak
Copy link
Owner

Hey Tom. I'm so sorry that I didn't reply to this issue a couple of months earlier; it flew by my inbox without me noticing until today.

The error that is occurring here must be something specific to your model class. The DataContractDatumConverterFactory attempts to emit a new datum converter class with IL generation so that it is very efficient, but, clearly is hitting an exception in the process. Is there any chance you can post the type you're encountering this on?

Looking closely at the stack trace and the code, it looks like what might be failing is that typeof(T).GetConstructor(new Type[0]) is null. That would indicate that your model class doesn't have a parameterless constructor, so, the datum converter doesn't know how to construct instances of the model class. That would make sense to be an error (albeit, ideally a clear and legible one!).

@lyjia
Copy link
Author

lyjia commented Jun 28, 2016

Hello mfenniak, thank you for replying to this.

I never did find a way around this (it's for a toy project) but the original Models.Accounts class (which inherits RethinkModel, declares some datamembers, and sets its table) was missing a parameterless constructor. Per your reponse, I added one, and the error seems to have morphed into something else (exception throws on the same line):

System.AggregateException: One or more errors occurred. ---> System.TypeLoadException: Access is denied: 'RethinkDb.DatumConverters.AbstractReferenceTypeDatumConverter`1[Daedalus.Server.Models.Account]'.
   at System.Reflection.Emit.TypeBuilder.TermCreateClass(RuntimeModule module, Int32 tk, ObjectHandleOnStack type)
   at System.Reflection.Emit.TypeBuilder.CreateTypeNoLock()
   at System.Reflection.Emit.TypeBuilder.CreateType()
   at RethinkDb.DatumConverters.DataContractDatumConverterFactory.Create[T]()
   at System.Lazy`1.CreateValue()
   at System.Lazy`1.LazyInitValue()
   at RethinkDb.DatumConverters.DataContractDatumConverterFactory.TryGet[T](IDatumConverterFactory rootDatumConverterFactory, IDatumConverter`1& datumConverter)
   at RethinkDb.DatumConverters.AggregateDatumConverterFactory.TryGet[T](IDatumConverterFactory rootDatumConverterFactory, IDatumConverter`1& datumConverter)
   at RethinkDb.QueryConverter.TryGet[T](IDatumConverterFactory rootDatumConverterFactory, IDatumConverter`1& datumConverter)
   at RethinkDb.DatumConverters.DatumConverterFactoryExtensions.Get[T](IDatumConverterFactory datumConverterFactory, IDatumConverterFactory rootDatumConverterFactory)
   at RethinkDb.DatumConverters.DatumConverterFactoryExtensions.Get[T](IDatumConverterFactory datumConverterFactory)
   at RethinkDb.Connection.QueryEnumerator`1..ctor(Connection connection, IQueryConverter queryConverter, ISequenceQuery`1 queryObject)
   at RethinkDb.Connection.RunAsync[T](IQueryConverter queryConverter, ISequenceQuery`1 queryObject)
   at RethinkDb.ConnectionFactories.ReliableConnectionFactory.ReliableConnectionWrapper.<RunAsync>c__AnonStorey2`1.<>m__0()
   at RethinkDb.ConnectionFactories.ReliableConnectionFactory.RetryAsyncEnumeratorWrapper`1.<MoveNext>c__async0.MoveNext()
   --- End of inner exception stack trace ---
   at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
   at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
   at RethinkDb.TaskUtilities.ExecuteSynchronously[T](Func`1 taskDelegate)
   at RethinkDb.SynchronousApiExtensions.AsyncEnumeratorSynchronizer`1.MoveNext()
   at System.Linq.Enumerable.First[TSource](IEnumerable`1 source)
   at Daedalus.Server.ServerInstance.appServer_NewRequestReceived(AppSession session, StringRequestInfo requestInfo) in C:\Users\tom\Dropbox\Projects\daedalus2016\src\Daedalus\Server\ServerInstance.cs:line 100
   at SuperSocket.SocketBase.AppServerBase`2.ExecuteCommand(TAppSession session, TRequestInfo requestInfo)
---> (Inner Exception #0) System.TypeLoadException: Access is denied: 'RethinkDb.DatumConverters.AbstractReferenceTypeDatumConverter`1[Daedalus.Server.Models.Account]'.
   at System.Reflection.Emit.TypeBuilder.TermCreateClass(RuntimeModule module, Int32 tk, ObjectHandleOnStack type)
   at System.Reflection.Emit.TypeBuilder.CreateTypeNoLock()
   at System.Reflection.Emit.TypeBuilder.CreateType()
   at RethinkDb.DatumConverters.DataContractDatumConverterFactory.Create[T]()
   at System.Lazy`1.CreateValue()
   at System.Lazy`1.LazyInitValue()
   at RethinkDb.DatumConverters.DataContractDatumConverterFactory.TryGet[T](IDatumConverterFactory rootDatumConverterFactory, IDatumConverter`1& datumConverter)
   at RethinkDb.DatumConverters.AggregateDatumConverterFactory.TryGet[T](IDatumConverterFactory rootDatumConverterFactory, IDatumConverter`1& datumConverter)
   at RethinkDb.QueryConverter.TryGet[T](IDatumConverterFactory rootDatumConverterFactory, IDatumConverter`1& datumConverter)
   at RethinkDb.DatumConverters.DatumConverterFactoryExtensions.Get[T](IDatumConverterFactory datumConverterFactory, IDatumConverterFactory rootDatumConverterFactory)
   at RethinkDb.DatumConverters.DatumConverterFactoryExtensions.Get[T](IDatumConverterFactory datumConverterFactory)
   at RethinkDb.Connection.QueryEnumerator`1..ctor(Connection connection, IQueryConverter queryConverter, ISequenceQuery`1 queryObject)
   at RethinkDb.Connection.RunAsync[T](IQueryConverter queryConverter, ISequenceQuery`1 queryObject)
   at RethinkDb.ConnectionFactories.ReliableConnectionFactory.ReliableConnectionWrapper.<RunAsync>c__AnonStorey2`1.<>m__0()
   at RethinkDb.ConnectionFactories.ReliableConnectionFactory.RetryAsyncEnumeratorWrapper`1.<MoveNext>c__async0.MoveNext()<---

So now it's a TypeLoadException with "Access Denied". I'm hoping this is something simple that I've missed. Also, I'm a little unclear on what you mean by type; do you mean the Models.Account class or something else? I thought that maybe it was having trouble accessing Models.Account, but RethinkDb is regular class so I can't really promote Models.Account to public. Could it be having trouble accessing the table?

I can post the Models.Account source if you like; it's fairly boring but perhaps incomplete... but I'm hoping this error is something simple :)

Thank you,

Tom

PS/edit- in the off-chance that either of these two factoids are useful: the rethinkdb data folder lives in a Dropbox folder and the two-line version header that rethinkdb starts up with is as follows:

Running rethinkdb 2.3.0-windows-beta (MSC 190023506)...
Running on 6.1.7601 (Windows 7, Server 2008 R2)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants