使用 Linq 时应用程序在单声道下崩溃
Application crashing under mono when using Linq
我正在使用 ServiceStack 和 EF6 (MySQL) 编程休息 api。代码在 windows 下运行没有问题,servicestack 本身在 linux (HyperfastCGI4 + Nginx) 下运行良好。
但是,如果我调用使用 EntityFramework 的服务,我会得到一个 NotSupportedException
和一个我不太了解的堆栈跟踪。
我错过了什么吗?
请求结果:
{
"ResponseStatus": {
"ErrorCode": "NotSupportedException",
"Message": "Operation is not supported.",
"StackTrace": "[Authenticate: 1/20/2016 4:34:10 PM]:
[REQUEST: {UserName:foo@bar.derp,Password:******}]
System.NotSupportedException: Operation is not supported.
at System.Reflection.MonoGenericClass.GetConstructors (BindingFlags bf) [0x00000] in <filename unknown>:0
at System.Reflection.TypeInfo.get_DeclaredConstructors () [0x00000] in <filename unknown>:0
at System.Data.Entity.Utilities.TypeExtensions.GetDeclaredConstructors (System.Type type) [0x00000] in <filename unknown>:0
at System.Data.Entity.Utilities.TypeExtensions.GetDeclaredConstructor (System.Type type, System.Type[] parameterTypes) [0x00000] in <filename unknown>:0
at System.Data.Entity.Core.Common.Internal.Materialization.CodeGenEmitter.CreateEntityWrapper (System.Linq.Expressions.Expression input, System.Linq.Expressions.Expression keyReader, System.Linq.Expressions.Expression entitySetReader, System.Type actualType, System.Type identityType, MergeOption mergeOption, Boolean isProxy) [0x00000] in <filename unknown>:0
at System.Data.Entity.Core.Common.Internal.Materialization.CodeGenEmitter.Emit_EnsureTypeAndWrap (System.Linq.Expressions.Expression input, System.Linq.Expressions.Expression keyReader, System.Linq.Expressions.Expression entitySetReader, System.Type requestedType, System.Type identityType, System.Type actualType, MergeOption mergeOption, Boolean isProxy) [0x00000] in <filename unknown>:0
at System.Data.Entity.Core.Common.Internal.Materialization.Translator+TranslatorVisitor.Emit_ConstructEntity (System.Data.Entity.Core.Metadata.Edm.EntityType oSpaceType, IEnumerable`1 propertyBindings, System.Linq.Expressions.Expression entityKeyReader, System.Linq.Expressions.Expression entitySetReader, TranslatorArg arg, System.Data.Entity.Core.Objects.Internal.EntityProxyTypeInfo proxyTypeInfo) [0x00000] in <filename unknown>:0
at System.Data.Entity.Core.Common.Internal.Materialization.Translator+TranslatorVisitor.Visit (System.Data.Entity.Core.Query.InternalTrees.EntityColumnMap columnMap, TranslatorArg arg) [0x00000] in <filename unknown>:0
at System.Data.Entity.Core.Query.InternalTrees.EntityColumnMap.Accept[TranslatorResult,TranslatorArg] (System.Data.Entity.Core.Query.InternalTrees.ColumnMapVisitorWithResults`2 visitor, TranslatorArg arg) [0x00000] in <filename unknown>:0
at System.Data.Entity.Core.Common.Internal.Materialization.Translator+TranslatorVisitor.ProcessCollectionColumnMap (System.Data.Entity.Core.Query.InternalTrees.CollectionColumnMap columnMap, TranslatorArg arg, System.Data.Entity.Core.Query.InternalTrees.ColumnMap discriminatorColumnMap, System.Object discriminatorValue) [0x00000] in <filename unknown>:0
at System.Data.Entity.Core.Common.Internal.Materialization.Translator+TranslatorVisitor.ProcessCollectionColumnMap (System.Data.Entity.Core.Query.InternalTrees.CollectionColumnMap columnMap, TranslatorArg arg) [0x00000] in <filename unknown>:0
at System.Data.Entity.Core.Common.Internal.Materialization.Translator+TranslatorVisitor.Visit (System.Data.Entity.Core.Query.InternalTrees.SimpleCollectionColumnMap columnMap, TranslatorArg arg) [0x00000] in <filename unknown>:0
at System.Data.Entity.Core.Query.InternalTrees.SimpleCollectionColumnMap.Accept[TranslatorResult,TranslatorArg] (System.Data.Entity.Core.Query.InternalTrees.ColumnMapVisitorWithResults`2 visitor, TranslatorArg arg) [0x00000] in <filename unknown>:0
at System.Data.Entity.Core.Common.Internal.Materialization.Translator.TranslateColumnMap[User] (System.Data.Entity.Core.Query.InternalTrees.ColumnMap columnMap, System.Data.Entity.Core.Metadata.Edm.MetadataWorkspace workspace, System.Data.Entity.Core.Objects.Internal.SpanIndex spanIndex, MergeOption mergeOption, Boolean streaming, Boolean valueLayer) [0x00000] in <filename unknown>:0
at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&)
at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0 ",
"Errors": []
}
}
编辑
我通过注释掉从数据库接收一些数据的 Linq 表达式摆脱了上面的错误:
var userRow = modelContext.User.FirstOrDefault(user => user.Mail == mail);
我在 entityframework 来源中找到了一个调用反射方法和 returns 一个 IQueryable
的方法,但是我不知道这是否与问题有关.至少它引导我朝着正确的方向前进。
这是实现:
/// <summary>
/// Creates an appropriate generic IQueryable using Reflection and the underlying ElementType of
/// the given ObjectQuery.
/// </summary>
private IQueryable CreateQuery(ObjectQuery objectQuery)
{
var internalQuery = CreateInternalQuery(objectQuery);
var genericDbQueryType = typeof(InternalDbQuery<>).MakeGenericType(internalQuery.ElementType);
var constructor = genericDbQueryType.GetConstructors(BindingFlags.Instance | BindingFlags.Public).Single();
return (IQueryable)constructor.Invoke(new object[] { internalQuery });
}
Linq 会导致单声道问题吗?如果是,是否有解决方法?
Re-targeting 在 3.5 中修复了问题
咕噜
另外 Update-Package -reinstall
会为您重新安装所有 nugets
我正在使用 ServiceStack 和 EF6 (MySQL) 编程休息 api。代码在 windows 下运行没有问题,servicestack 本身在 linux (HyperfastCGI4 + Nginx) 下运行良好。
但是,如果我调用使用 EntityFramework 的服务,我会得到一个 NotSupportedException
和一个我不太了解的堆栈跟踪。
我错过了什么吗?
请求结果:
{
"ResponseStatus": {
"ErrorCode": "NotSupportedException",
"Message": "Operation is not supported.",
"StackTrace": "[Authenticate: 1/20/2016 4:34:10 PM]:
[REQUEST: {UserName:foo@bar.derp,Password:******}]
System.NotSupportedException: Operation is not supported.
at System.Reflection.MonoGenericClass.GetConstructors (BindingFlags bf) [0x00000] in <filename unknown>:0
at System.Reflection.TypeInfo.get_DeclaredConstructors () [0x00000] in <filename unknown>:0
at System.Data.Entity.Utilities.TypeExtensions.GetDeclaredConstructors (System.Type type) [0x00000] in <filename unknown>:0
at System.Data.Entity.Utilities.TypeExtensions.GetDeclaredConstructor (System.Type type, System.Type[] parameterTypes) [0x00000] in <filename unknown>:0
at System.Data.Entity.Core.Common.Internal.Materialization.CodeGenEmitter.CreateEntityWrapper (System.Linq.Expressions.Expression input, System.Linq.Expressions.Expression keyReader, System.Linq.Expressions.Expression entitySetReader, System.Type actualType, System.Type identityType, MergeOption mergeOption, Boolean isProxy) [0x00000] in <filename unknown>:0
at System.Data.Entity.Core.Common.Internal.Materialization.CodeGenEmitter.Emit_EnsureTypeAndWrap (System.Linq.Expressions.Expression input, System.Linq.Expressions.Expression keyReader, System.Linq.Expressions.Expression entitySetReader, System.Type requestedType, System.Type identityType, System.Type actualType, MergeOption mergeOption, Boolean isProxy) [0x00000] in <filename unknown>:0
at System.Data.Entity.Core.Common.Internal.Materialization.Translator+TranslatorVisitor.Emit_ConstructEntity (System.Data.Entity.Core.Metadata.Edm.EntityType oSpaceType, IEnumerable`1 propertyBindings, System.Linq.Expressions.Expression entityKeyReader, System.Linq.Expressions.Expression entitySetReader, TranslatorArg arg, System.Data.Entity.Core.Objects.Internal.EntityProxyTypeInfo proxyTypeInfo) [0x00000] in <filename unknown>:0
at System.Data.Entity.Core.Common.Internal.Materialization.Translator+TranslatorVisitor.Visit (System.Data.Entity.Core.Query.InternalTrees.EntityColumnMap columnMap, TranslatorArg arg) [0x00000] in <filename unknown>:0
at System.Data.Entity.Core.Query.InternalTrees.EntityColumnMap.Accept[TranslatorResult,TranslatorArg] (System.Data.Entity.Core.Query.InternalTrees.ColumnMapVisitorWithResults`2 visitor, TranslatorArg arg) [0x00000] in <filename unknown>:0
at System.Data.Entity.Core.Common.Internal.Materialization.Translator+TranslatorVisitor.ProcessCollectionColumnMap (System.Data.Entity.Core.Query.InternalTrees.CollectionColumnMap columnMap, TranslatorArg arg, System.Data.Entity.Core.Query.InternalTrees.ColumnMap discriminatorColumnMap, System.Object discriminatorValue) [0x00000] in <filename unknown>:0
at System.Data.Entity.Core.Common.Internal.Materialization.Translator+TranslatorVisitor.ProcessCollectionColumnMap (System.Data.Entity.Core.Query.InternalTrees.CollectionColumnMap columnMap, TranslatorArg arg) [0x00000] in <filename unknown>:0
at System.Data.Entity.Core.Common.Internal.Materialization.Translator+TranslatorVisitor.Visit (System.Data.Entity.Core.Query.InternalTrees.SimpleCollectionColumnMap columnMap, TranslatorArg arg) [0x00000] in <filename unknown>:0
at System.Data.Entity.Core.Query.InternalTrees.SimpleCollectionColumnMap.Accept[TranslatorResult,TranslatorArg] (System.Data.Entity.Core.Query.InternalTrees.ColumnMapVisitorWithResults`2 visitor, TranslatorArg arg) [0x00000] in <filename unknown>:0
at System.Data.Entity.Core.Common.Internal.Materialization.Translator.TranslateColumnMap[User] (System.Data.Entity.Core.Query.InternalTrees.ColumnMap columnMap, System.Data.Entity.Core.Metadata.Edm.MetadataWorkspace workspace, System.Data.Entity.Core.Objects.Internal.SpanIndex spanIndex, MergeOption mergeOption, Boolean streaming, Boolean valueLayer) [0x00000] in <filename unknown>:0
at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&)
at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0 ",
"Errors": []
}
}
编辑
我通过注释掉从数据库接收一些数据的 Linq 表达式摆脱了上面的错误:
var userRow = modelContext.User.FirstOrDefault(user => user.Mail == mail);
我在 entityframework 来源中找到了一个调用反射方法和 returns 一个 IQueryable
的方法,但是我不知道这是否与问题有关.至少它引导我朝着正确的方向前进。
这是实现:
/// <summary>
/// Creates an appropriate generic IQueryable using Reflection and the underlying ElementType of
/// the given ObjectQuery.
/// </summary>
private IQueryable CreateQuery(ObjectQuery objectQuery)
{
var internalQuery = CreateInternalQuery(objectQuery);
var genericDbQueryType = typeof(InternalDbQuery<>).MakeGenericType(internalQuery.ElementType);
var constructor = genericDbQueryType.GetConstructors(BindingFlags.Instance | BindingFlags.Public).Single();
return (IQueryable)constructor.Invoke(new object[] { internalQuery });
}
Linq 会导致单声道问题吗?如果是,是否有解决方法?
Re-targeting 在 3.5 中修复了问题
咕噜
另外 Update-Package -reinstall
会为您重新安装所有 nugets