gpt4 book ai didi

c# - 使用 EntityFramework 和 .NET Native 时出现 PlatformNotSupportedException

转载 作者:行者123 更新时间:2023-11-30 15:23:48 30 4
gpt4 key购买 nike

我有一个 UWP (Windows 10) 应用程序,它可以在 Debug模式下完美运行(禁用 .NET Native)。

当我在 Release模式下运行它时,(或者在 Debug模式下使用 .NET Native 编译时,我在 return context.Set().ToList(); 行收到错误。

    public IEnumerable<TMobileEntity> ReadAll()
{
using (var context = new DataContext(database.DatabasePath))
{
return context.Set<TMobileEntity>().ToList();
}
}

这里是异常的详细信息

{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.Func2.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<br/>
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
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}

最佳答案

这不是很有启发性,但您可以在此处查看异常来源:https://github.com/dotnet/corert/blob/master/src/System.Private.CoreLib/src/Internal/Reflection/Core/NonPortable/RuntimeType.cs#L262

在高层次上,EF 确实还没有准备好支持 UWP 和提前编译。我知道他们正在努力为 UWP 工具的下一次更新获得支持。

这个具体问题是 .NET Native 中当前的反射实现正在尝试使用 TypeInfo.IsAssignableFrom 并且在未实例化的泛型类型方面存在局限性。我认为计划是在下一个版本的 .NET Native 中纠正这个问题。

所以我认为您可能只需要删除 EF 中遇到此问题的任何内容。抱歉,我没有更好的消息。

关于c# - 使用 EntityFramework 和 .NET Native 时出现 PlatformNotSupportedException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33926168/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com