diff --git a/Unity/Assets/Editor/Helper/MongoHelper.cs b/Unity/Assets/Editor/Helper/MongoHelper.cs index f13fdc024d36ead1d750fa7d8625c7d982e09679..aff9a60dcfc37cb25031d7bf55dc13a7d2f4330f 100644 --- a/Unity/Assets/Editor/Helper/MongoHelper.cs +++ b/Unity/Assets/Editor/Helper/MongoHelper.cs @@ -4,6 +4,7 @@ using MongoDB.Bson; using MongoDB.Bson.IO; using MongoDB.Bson.Serialization; using MongoDB.Bson.Serialization.Serializers; +using System.Collections.Generic; namespace ETModel { @@ -69,5 +70,20 @@ namespace ETModel { return FromBson(ToBson(t)); } + + + public static void AvoidAOT() + { + ArraySerializer aint = new ArraySerializer(); + ArraySerializer astring = new ArraySerializer(); + ArraySerializer along = new ArraySerializer(); + + EnumerableInterfaceImplementerSerializer> e = + new EnumerableInterfaceImplementerSerializer>(); + + EnumerableInterfaceImplementerSerializer, int> elistint = + new EnumerableInterfaceImplementerSerializer, int>(); + } + } } \ No newline at end of file diff --git a/Unity/Assets/Plugins/MongoDB/MongoDB.Bson/Serialization/BsonClassMap.cs b/Unity/Assets/Plugins/MongoDB/MongoDB.Bson/Serialization/BsonClassMap.cs index 3e3f43116df296c2bb2f26cae52fdf3685feb6e6..45108b4a9c91f8fba06d19ca8bc41fba59f2b269 100644 --- a/Unity/Assets/Plugins/MongoDB/MongoDB.Bson/Serialization/BsonClassMap.cs +++ b/Unity/Assets/Plugins/MongoDB/MongoDB.Bson/Serialization/BsonClassMap.cs @@ -19,6 +19,7 @@ using System.Collections.ObjectModel; using System.Linq; using System.Linq.Expressions; using System.Reflection; +using System.Reflection.Emit; using System.Runtime.CompilerServices; #if NET45 using System.Runtime.Serialization; @@ -1277,10 +1278,25 @@ namespace MongoDB.Bson.Serialization ConstructorInfo defaultConstructor = classTypeInfo.GetConstructors(bindingFlags) .Where(c => c.GetParameters().Length == 0) .SingleOrDefault(); -#if ENABLE_IL2CPP - _creator = () => defaultConstructor.Invoke(null); -#else - if (defaultConstructor != null) + #if ENABLE_IL2CPP + + if (defaultConstructor != null) + { + _creator = () => defaultConstructor.Invoke(null); + + } + else if(__getUninitializedObjectMethodInfo != null) + { + + _creator = () => __getUninitializedObjectMethodInfo.Invoke(null, new object[] { this._classType }); + } + else + { + var message = $"Type '{_classType.GetType().Name}' does not have a default constructor."; + throw new BsonSerializationException(message); + } + #else + if (defaultConstructor != null) { // lambdaExpression = () => (object) new TClass() body = Expression.New(defaultConstructor); @@ -1298,7 +1314,7 @@ namespace MongoDB.Bson.Serialization var lambdaExpression = Expression.Lambda>(body); _creator = lambdaExpression.Compile(); -#endif + #endif } return _creator; }