InvalidProgramException using EnsureIndex on .NET 3.5 (beta-3)
I am seeing an exception as a result of compiling expressions (inside Reflection.cs #103)
This is happening on a new db which I am calling EnsureIndex on.
InvalidProgramException: Invalid IL code in (wrapper dynamic-method) System.Runtime.CompilerServices.ExecutionScope:lambda_method (System.Runtime.CompilerServices.ExecutionScope,object,object): IL_001b: call 0x00000007
Callstack:
System.Delegate.CreateDelegate (System.Type type, System.Object firstArgument, System.Reflection.MethodInfo method, Boolean throwOnBindFailure) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System/Delegate.cs:268)
System.Delegate.CreateDelegate (System.Type type, System.Object firstArgument, System.Reflection.MethodInfo method) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System/Delegate.cs:276)
System.Reflection.Emit.DynamicMethod.CreateDelegate (System.Type delegateType, System.Object target) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection.Emit/DynamicMethod.cs:192)
System.Linq.Expressions.EmitContext.CreateDelegate (System.Runtime.CompilerServices.ExecutionScope scope)
System.Linq.Expressions.CompilationContext.CreateDelegate (Int32 unit, System.Runtime.CompilerServices.ExecutionScope scope)
System.Linq.Expressions.CompilationContext.CreateDelegate ()
System.Linq.Expressions.LambdaExpression.Compile ()
System.Linq.Expressions.Expression1[LiteDB.GenericSetter].Compile ()
LiteDB.Reflection.CreateGenericSetter (System.Type type, System.Reflection.MemberInfo memberInfo) (at Assets/LiteDB-3.0.0.0-beta/LiteDB/Mapper/Reflection/Reflection.cs:106)
LiteDB.BsonMapper.BuildEntityMapper (System.Type type) (at Assets/LiteDB-3.0.0.0-beta/LiteDB/Mapper/BsonMapper.cs:333)
LiteDB.BsonMapper.GetEntityMapper (System.Type type) (at Assets/LiteDB-3.0.0.0-beta/LiteDB/Mapper/BsonMapper.cs:279)
LiteDB.QueryVisitor1[DBLiteTest+Record].GetField (System.Linq.Expressions.Expression expr, System.String prefix) (at Assets/LiteDB-3.0.0.0-beta/LiteDB/Mapper/Linq/QueryVisitor.cs:305)
LiteDB.LiteCollection1[DBLiteTest+Record].EnsureIndex[String] (System.Linq.Expressions.Expression1 property, Boolean unique) (at Assets/LiteDB-3.0.0.0-beta/LiteDB/Database/Collections/Index.cs:32)
DBLiteTest.CreateDB_Click () (at Assets/Scripts/DBLiteTest.cs:112)
My code is largely example based ############################################################################
class Record
{
public int Id { get; set; }
public string Name { get; set; }
public string TextField { get; set; }
public int[] NumCollection { get; set; }
}
var db = new LiteDB.LiteDatabase(newName);
if (db == null)
{
Debug.LogError("Failed to create");
return;
}
var recs = db.GetCollection<Record>("records");
var rec = new Record
{
Name = "John Doe",
TextField = "extra stuff" ,
NumCollection = new int[] { 1, 2, 3 }
};
Debug.LogWarning("now ensure index");
recs.EnsureIndex(x => x.Name);
Debug.LogWarning("ensured index");
// Insert (Id will be auto-incremented)
recs.Insert(rec);
Debug.LogWarning("Insert complete");
############################################################################
As I said, this is with a .NET 3.5 compile. Also, on post #354 I noticed mbdavid, you weren't sure if you were going to keep this version going. Any more thoughts on this?
Are you using Unit3d?
I am using Unity3D yes, thought there would be enough clues ! :)
Ok, thansk, I will check this.... I have no dev enviorment to run in unit3d. But, as I know, early versions (v1/v2) works fine..
We think we had an earlier version (v2 perhaps) where properties worked - and hence it seemed to all work, and we think perhaps including variables -which you added in a more recent version is breaking it ? Prompt response by the way :)
i have unity3D v3, v4 and v5.
check your project settings and change the .net compiler to include the .net 3.5 subset as well.
which version of unity3D are you using? On Jan 12, 2017 1:09 PM, "mcintyrg" [email protected] wrote:
We think we had an earlier version (v2 perhaps) where properties worked - and hence it seemed to all work, and we think perhaps including variables -which you added in a more recent version is breaking it ?
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/mbdavid/LiteDB/issues/426#issuecomment-272136821, or mute the thread https://github.com/notifications/unsubscribe-auth/AVQ2C5BTZ9VNZwEzBD2JeYhR4vy_q46xks5rRgnmgaJpZM4Lhm57 .
Unity 5. The only options are a .NET 2.0 Subset or '.NET 2.0'. I build with the latter of the two which is a close as I can configure unity to a .NET 3.5 (I think it's only partial support)
I suggest then you should rebuild liteDb under the .net 2.0 subset system and it should resolve your issues. remember to clear gac and then open and close unity. On Jan 12, 2017 3:32 PM, "mcintyrg" [email protected] wrote:
Unity 5. The only options are a .NET 2.0 Subset or '.NET 2.0'. I build with the latter of the two which is a close as I can configure unity to a .NET 3.5 (I think it's only partial support)
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/mbdavid/LiteDB/issues/426#issuecomment-272163783, or mute the thread https://github.com/notifications/unsubscribe-auth/AVQ2C8de2jQGhoCkhf5KVKa_QVaupyBYks5rRit1gaJpZM4Lhm57 .
I fail to see how a smaller subset would make it work since we are stripping more .NET functionality for a build using a subset. Saying that I did try this and still have the same issue
you need to recompile litedb dll using .net 2.0 On Jan 12, 2017 4:20 PM, "mcintyrg" [email protected] wrote:
I fail to see how a smaller subset would make it work since we are stripping more code for a build using a subset. Saying that I did try this and still have the same issue
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/mbdavid/LiteDB/issues/426#issuecomment-272174617, or mute the thread https://github.com/notifications/unsubscribe-auth/AVQ2CyYxD_eQ9UwSA4rcgpGv4-U3nM3oks5rRjalgaJpZM4Lhm57 .
I have just realised that I failed to mention I am including source directly rather than DLL's
some of the language features used are not supported in .net 2 for v3 of litedb... you must decide to either use dll and recompile or use v2 of litedb On Jan 12, 2017 4:44 PM, "mcintyrg" [email protected] wrote:
I have just realised that I failed to mention I am including source directly rather than DLL's
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/mbdavid/LiteDB/issues/426#issuecomment-272180613, or mute the thread https://github.com/notifications/unsubscribe-auth/AVQ2CyF_gAyUU2cGUwdIGV0wZNHmMkofks5rRjw6gaJpZM4Lhm57 .
Thanks for the suggestion. I have tried utilising DLL's built against both Unity's full 3.5 base class target & the subset, and I even tried a full .Netframework 3.5 target and sadly I still run into the same issue. :(
I can start from what I think is the latest v2 release which worked and then see if I can patch v3 to work. Any help you guys can offer would be appreciated. If I can get a patched v3 working then perhaps I can send this over for review
I have managed to compile LiteDB 2.0.4 under ,NET 3.5 and have this work in unity 5.4 so far (i.e. no IL errors)
Hi @mcintyrg, LiteDB v3 must work in Unit3D, thats why i'm still using .net35. I will change CreateGenericSetter to works I nedded. I have no unit3d installed, so I will made this change and ask you test, ok?
I will close this issue to ref with #380 (some bug)
V2 works (Android and Windows) but not V3. There is a more problematic issue (for me) with Unity on IOS as System.Reflection.Emit isn't supported (it's a different issue which I can raise separately if you wish - but essentially CreateDelegate in V2 results in using this call.) It's not due to lack of support in the mono implementation (or the IL2CPP - which is what we use) but rather it's not allowed on IOS
Unity 5.6 will likely work with expressions without changes since that supports .NET 4.6, though it's only in beta at the moment- However I think that expression still result in usage of System.Reflection.Emit (protobuf have had similar issues -see there project on github (unity support) )
I am seeing what I can do as an alternative but I am also more than happy to test something for you too
Hi @mcintyrg, are you using net35 version in iOS? I ask because v3 I made 2 targets: one for .net35 and one netstandard (to work with all other platforms). In v2 I had a lot of targets and are so hard to test and keep.
Now I remove expressions from net35 target and back to Emit. Expressions are best solution, are very fast but also do not work as exceptect in net35.
I create a branch unity3d removing all Emit code (it's quite simple, just a single class). If works, I will consider create another target/dll only for unity3d
@mbdavid : Great news. You can use the same LiteDB DLL across all those platforms (Windows, Android, IOS) in unity3d so what you are planning sounds great. Look forward to testing (we really wanted to use this over SQLite :) it's much better )
@mbdavid : I realise this alternate branch is perhaps extra work you can only do in your spare time etc, but any estimates on when it might be ready to test?