Reputation: 615
I have an UWP (Windows 10) app which runs perfectly on debug mode (.NET Native disabled).
When I am running it on release mode, (or in debug mode with .NET Native compilation on I receive error on return context.Set().ToList(); line.
public IEnumerable<TMobileEntity> ReadAll()
{
using (var context = new DataContext(database.DatabasePath))
{
return context.Set<TMobileEntity>().ToList();
}
}
here is an exception details
{System.TypeInitializationException: A type initializer threw an exception. To determine which type, inspect the InnerException's StackTrace property. ---> System.PlatformNotSupportedException: TypeHandles are not supported for types that return true for ContainsGenericParameters. at Internal.Reflection.Core.NonPortable.RuntimeType.get_TypeHandle() in f:\dd\ndp\fxcore\src\System.Private.CoreLib\Internal\Reflection\Core\NonPortable\RuntimeType.cs:line 262 at System.Reflection.Runtime.TypeInfos.RuntimeTypeInfo.IsAssignableFrom(TypeInfo typeInfo) in f:\dd\ndp\fxcore\src\System.Private.Reflection.Core\System\Reflection\Runtime\TypeInfos\RuntimeTypeInfo.cs:line 398 at Remotion.Linq.Parsing.Structure.IntermediateModel.SupportedMethodSpecifications.HasIndexSelectorParameter(MethodInfo methodInfo, Int32 parameterPosition) at Remotion.Linq.Parsing.Structure.IntermediateModel.SupportedMethodSpecifications.<>c__DisplayClass14.b__13(MethodInfo mi) at System.Func
2.Invoke(T arg) at System.Linq.Enumerable.<>c__DisplayClass0
1.b__1(TSource x) in f:\dd\ndp\fxcore\Open\src\System.Linq\src\System\Linq\Enumerable.cs:line 69 at System.Func2.Invoke(T arg) at System.Linq.Enumerable.WhereEnumerableIterator
1.MoveNext() in f:\dd\ndp\fxcore\Open\src\System.Linq\src\System\Linq\Enumerable.cs:line 199 at Remotion.Linq.Parsing.Structure.NodeTypeProviders.MethodInfoBasedNodeTypeRegistry.Register(IEnumerable1 methods, Type nodeType) at Remotion.Linq.Parsing.Structure.NodeTypeProviders.MethodInfoBasedNodeTypeRegistry.CreateFromRelinqAssembly() at Microsoft.Data.Entity.Query.QueryCompiler.CreateNodeTypeProvider() at Microsoft.Data.Entity.Query.QueryCompiler..cctor() at System.Runtime.CompilerServices.ClassConstructorRunner.Call[T](IntPtr pfn) at System.Runtime.CompilerServices.ClassConstructorRunner.EnsureClassConstructorRun(Void* returnValue, StaticClassConstructionContext* pContext) in f:\dd\ndp\fxcore\src\System.Private.CoreLib\System\Runtime\CompilerServices\ClassConstructorRunner.cs:line 69 Exception_EndOfInnerExceptionStack at System.Runtime.CompilerServices.ClassConstructorRunner.EnsureClassConstructorRun(Void* returnValue, StaticClassConstructionContext* pContext) in f:\dd\ndp\fxcore\src\System.Private.CoreLib\System\Runtime\CompilerServices\ClassConstructorRunner.cs:line 86 at Microsoft.Data.Entity.Query.QueryCompiler.Preprocess(Expression query, QueryContext queryContext) at Microsoft.Data.Entity.Query.QueryCompiler.Execute[TResult](Expression query) at Microsoft.Data.Entity.Query.Internal.EntityQueryProvider.Execute[TResult](Expression expression) at Remotion.Linq.QueryableBase
1.GetEnumerator() at Microsoft.Data.Entity.Internal.InternalDbSet1.System.Collections.Generic.IEnumerable<TEntity>.GetEnumerator() at System.Collections.Generic.List
1..ctor(IEnumerable1 collection) in f:\dd\ndp\fxcore\src\System.Collections\System\Collections\Generic\List.cs:line 88 at System.Linq.Enumerable.ToList[TSource](IEnumerable
1 source) at TIKSN.GroceryChecklist.ModernMobile.Data.RepositoryBase1.ReadAll() in E:\Visual Studio Online\tiksn\Grocery Checklist\Develop\ModernMobile.Data.UWP\RepositoryBase.cs:line 42
1.GetResult() in f:\dd\ndp\fxcore\src\System.Private.Threading\System\Runtime\CompilerServices\TaskAwaiter.cs:line 320 at TIKSN.GroceryChecklist.ModernMobile.ViewModels.ChecklistPageViewModel.d__15.MoveNext() in E:\Visual Studio Online\tiksn\Grocery Checklist\Develop\ModernMobile.UWP\ViewModels\ChecklistPageViewModel.cs:line 82 at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() in f:\dd\ndp\fxcore\src\System.Private.CoreLib\System\Runtime\ExceptionServices\ExceptionDispatchInfo.cs:line 66 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) in f:\dd\ndp\fxcore\src\System.Private.Threading\System\Runtime\CompilerServices\TaskAwaiter.cs:line 186 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) in f:\dd\ndp\fxcore\src\System.Private.Threading\System\Runtime\CompilerServices\TaskAwaiter.cs:line 155 at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task) in f:\dd\ndp\fxcore\src\System.Private.Threading\System\Runtime\CompilerServices\TaskAwaiter.cs:line 127 at System.Runtime.CompilerServices.TaskAwaiter.GetResult() in f:\dd\ndp\fxcore\src\System.Private.Threading\System\Runtime\CompilerServices\TaskAwaiter.cs:line 112 at TIKSN.GroceryChecklist.ModernMobile.ViewModels.PageViewModelBase.d__46.MoveNext() in E:\Visual Studio Online\tiksn\Grocery Checklist\Develop\ModernMobile.UWP\ViewModels\PageViewModelBase.cs:line 102} System.Exception {System.TypeInitializationException}
at TIKSN.GroceryChecklist.MobileDataService.ChecklistItemsManagementService.<GetCurrentChecklistItems>d__5.MoveNext() in E:\Visual Studio Online\tiksn\Grocery Checklist\Develop\MobileDataService\ChecklistItemsManagementService.cs:line 62 at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() in f:\dd\ndp\fxcore\src\System.Private.CoreLib\System\Runtime\ExceptionServices\ExceptionDispatchInfo.cs:line 66 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) in f:\dd\ndp\fxcore\src\System.Private.Threading\System\Runtime\CompilerServices\TaskAwaiter.cs:line 186 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) in f:\dd\ndp\fxcore\src\System.Private.Threading\System\Runtime\CompilerServices\TaskAwaiter.cs:line 155 at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task) in f:\dd\ndp\fxcore\src\System.Private.Threading\System\Runtime\CompilerServices\TaskAwaiter.cs:line 127 at System.Runtime.CompilerServices.TaskAwaiter
Upvotes: 3
Views: 1413
Reputation: 1696
It's not super enlightening but you can check out the source of the exception here: https://github.com/dotnet/corert/blob/master/src/System.Private.CoreLib/src/Internal/Reflection/Core/NonPortable/RuntimeType.cs#L262
At a high level, EF really just isn't ready to support UWP and being ahead of time compiled. I know they're working hard to get this support for the next update of the UWP tools.
This specific issue is that the current implementation of reflection in .NET Native is trying to use TypeInfo.IsAssignableFrom and has limitations vis a vis uninstantiated generic types. I think the plan is to correct this for the next version of .NET Native.
So I think you're probably just going to have to remove whatever in EF is hitting this issue. Sorry I don't have better news.
Upvotes: 3
Reputation: 4156
Assuming you are using ef7
Open Properties/Default.rd.xml and add the following to the file
<!-- Add your application specific runtime directives here. -->
<Type Name="System.Collections.ArrayList" Dynamic="Required All" />
Upvotes: 1