在某些计算机上调用set_DeleteBehavior后,EF7会抛出ArgumentException

时间:2015-11-05 11:05:34

标签: entity-framework entity-framework-core

在Windows 10上本地运行可以正常运行,在Windows Server 2012 R2上运行它会引发以下异常。

代码完全相同,部署完成后我没有将本地文件复制到服务器进行验证。

我在Github的消息来源中四处寻找,希望找到答案,但到目前为止一直无法找到任何线索。最近在服务器上发生的事情只是.NET 4.6的安装,但应用程序始终是为.NET 4.6构建的,现在才开始抛出此异常。在.NET安装之后重新启动(只是为了确定)也已完成。

public class Client
{
    public Guid ClientId { get; set; }
    public string Name { get; set; }
    public string Queue { get; set; }        
}

public class StatusUpdate
{
    public Guid StatusUpdateId { get; set; }
    public DateTime UtcDateTime { get; set; }
    public string Type { get; set; }
    public Guid ClientId { get; set; }    
    public Client Client { get; set; }    
}

public class AccessLevel
{
    public Guid ClientId { get; set; }
    public int AccessLevelId { get; set; }
    public string Name { get; set; }
    public DateTime LastUpdatedUtc { get; set; }
    public Client Client { get; set; }
}

public class UserClientLink
{
    public Guid UserId { get; set; }
    public Guid ClientId { get; set; }
    public User User { get; set; }
    public Client Client { get; set; }
}

    protected override void OnModelCreating(ModelBuilder modelBuilder)
{

    modelBuilder.Entity<AccessLevel>().HasKey(a => new {a.ClientId, a.AccessLevelId});
    //Set to -99 since value might range from -5 to max int. Enables inserts with the default sentinel value.
    modelBuilder.Entity<AccessLevel>().Property(p => p.AccessLevelId).Metadata.SentinelValue = -99;

    modelBuilder.Entity<UserClientLink>().HasKey(ucl => new {ucl.ClientId, ucl.UserId});
}

Context.StatusUpdates.Add(statusUpdate);

供参考,完整的扫描痕迹。

System.ArgumentException: The value provided for argument 'value' must be a valid value of enum type 'Microsoft.Data.Entity.Metadata.DeleteBehavior'.
   at Microsoft.Data.Entity.Utilities.Check.IsDefined[T](T value, String parameterName)
   at Microsoft.Data.Entity.Metadata.ForeignKey.set_DeleteBehavior(Nullable`1 value)
   at Microsoft.Data.Entity.Metadata.Internal.InternalEntityTypeBuilder.CreateForeignKey(InternalEntityTypeBuilder principalEntityTypeBuilder, String navigationToPrincipal, IReadOnlyList`1 dependentProperties, IReadOnlyList`1 principalProperties, Nullable`1 isUnique, Nullable`1 isRequired, Nullable`1 deleteBehavior)
   at Microsoft.Data.Entity.Metadata.Internal.InternalEntityTypeBuilder.Relationship(InternalEntityTypeBuilder principalEntityTypeBuilder, InternalEntityTypeBuilder dependentEntityTypeBuilder, String navigationToPrincipalName, String navigationToDependentName, IReadOnlyList`1 dependentProperties, IReadOnlyList`1 principalProperties, ConfigurationSource configurationSource, Nullable`1 isUnique, Nullable`1 isRequired, Nullable`1 deleteBehavior, Boolean strictPrincipal, Func`2 onRelationshipAdding, Boolean runConventions)
   at Microsoft.Data.Entity.Metadata.Internal.InternalRelationshipBuilder.ReplaceForeignKey(InternalEntityTypeBuilder principalEntityTypeBuilder, InternalEntityTypeBuilder dependentEntityTypeBuilder, String navigationToPrincipalName, String navigationToDependentName, IReadOnlyList`1 dependentProperties, IReadOnlyList`1 principalProperties, Nullable`1 isUnique, Nullable`1 isRequired, Nullable`1 deleteBehavior, ForeignKeyAspect aspectsConfigured, ConfigurationSource configurationSource, Boolean runConventions)
   at Microsoft.Data.Entity.Metadata.Internal.InternalRelationshipBuilder.ReplaceForeignKey(ForeignKeyAspect aspectsConfigured, ConfigurationSource configurationSource, InternalEntityTypeBuilder principalEntityTypeBuilder, InternalEntityTypeBuilder dependentEntityTypeBuilder, IReadOnlyList`1 dependentProperties, IReadOnlyList`1 principalProperties, Nullable`1 isUnique, Nullable`1 isRequired, Nullable`1 deleteBehavior, Boolean runConventions)
   at Microsoft.Data.Entity.Metadata.Internal.InternalRelationshipBuilder.ForeignKey(IReadOnlyList`1 properties, ConfigurationSource configurationSource, Boolean runConventions)
   at Microsoft.Data.Entity.Metadata.Conventions.Internal.ForeignKeyPropertyDiscoveryConvention.Apply(InternalRelationshipBuilder relationshipBuilder)
   at Microsoft.Data.Entity.Metadata.Conventions.Internal.ConventionDispatcher.OnForeignKeyAdded(InternalRelationshipBuilder relationshipBuilder)
   at Microsoft.Data.Entity.Metadata.Internal.InternalEntityTypeBuilder.Relationship(InternalEntityTypeBuilder principalEntityTypeBuilder, InternalEntityTypeBuilder dependentEntityTypeBuilder, String navigationToPrincipalName, String navigationToDependentName, IReadOnlyList`1 dependentProperties, IReadOnlyList`1 principalProperties, ConfigurationSource configurationSource, Nullable`1 isUnique, Nullable`1 isRequired, Nullable`1 deleteBehavior, Boolean strictPrincipal, Func`2 onRelationshipAdding, Boolean runConventions)
   at Microsoft.Data.Entity.Metadata.Internal.InternalEntityTypeBuilder.Relationship(InternalEntityTypeBuilder principalEntityTypeBuilder, InternalEntityTypeBuilder dependentEntityTypeBuilder, String navigationToPrincipalName, String navigationToDependentName, ConfigurationSource configurationSource, Nullable`1 isUnique, Boolean strictPrincipal)
   at Microsoft.Data.Entity.Metadata.Internal.InternalEntityTypeBuilder.Relationship(InternalEntityTypeBuilder sourceBuilder, PropertyInfo navigationToTarget, PropertyInfo navigationToSource, ConfigurationSource configurationSource)
   at Microsoft.Data.Entity.Metadata.Conventions.Internal.RelationshipDiscoveryConvention.Apply(InternalEntityTypeBuilder entityTypeBuilder)
   at Microsoft.Data.Entity.Metadata.Conventions.Internal.ConventionDispatcher.OnEntityTypeAdded(InternalEntityTypeBuilder entityTypeBuilder)
   at Microsoft.Data.Entity.Metadata.Internal.MetadataDictionary`2.GetOrAdd(Func`1 getKey, Func`1 createKey, Func`2 createValue, Func`2 onNewKeyAdded, ConfigurationSource configurationSource)
   at Microsoft.Data.Entity.Metadata.Internal.InternalModelBuilder.Entity(Type type, ConfigurationSource configurationSource)
   at Microsoft.Data.Entity.ModelBuilder.Entity(Type type)
   at Microsoft.Data.Entity.Infrastructure.ModelSource.FindSets(ModelBuilder modelBuilder, DbContext context)
   at Microsoft.Data.Entity.Infrastructure.ModelSource.CreateModel(DbContext context, IConventionSetBuilder conventionSetBuilder, IModelValidator validator)
   at Microsoft.Data.Entity.Internal.ThreadSafeDictionaryCache`2.GetOrAdd(TKey key, Func`2 factory)
   at Microsoft.Data.Entity.Internal.DbContextServices.CreateModel()
   at Microsoft.Data.Entity.Internal.LazyRef`1.get_Value()
   at Microsoft.Data.Entity.Internal.DbContextServices.get_Model()
   at lambda_method(Closure , ServiceProvider )
   at Microsoft.Framework.DependencyInjection.ServiceProviderExtensions.GetService[T](IServiceProvider provider)
   at lambda_method(Closure , ServiceProvider )
   at Microsoft.Framework.DependencyInjection.ServiceProviderExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
   at Microsoft.Framework.DependencyInjection.ServiceProviderExtensions.GetRequiredService[T](IServiceProvider provider)
   at Microsoft.Data.Entity.DbContext.EntryWithoutDetectChanges[TEntity](TEntity entity)
   at Microsoft.Data.Entity.DbContext.SetEntityState[TEntity](TEntity entity, EntityState entityState, GraphBehavior behavior)
   at Microsoft.Data.Entity.DbContext.Add[TEntity](TEntity entity, GraphBehavior behavior)
   at Intreba.Enm.Server.Repository.ServerStorage.AddStatusUpdate(StatusUpdate statusUpdate, Boolean save) in C:\Development\Enterprise Net2 Manager\Intreba.Enm.Server.Repository\ServerStorage.cs:line 78
   at Intreba.Enm.Server.Repository.ServerStorage.AddStatusUpdate(StatusUpdate statusUpdate) in C:\Development\Enterprise Net2 Manager\Intreba.Enm.Server.Repository\ServerStorage.cs:line 73
   at Intreba.Enm.Server.Client.AliveHandler.Handle(Heartbeat message) in C:\Development\Enterprise Net2 Manager\Intreba.Enm.Server.Client\AliveHandler.cs:line 54
   at NServiceBus.Unicast.MessageHandlerRegistry.Invoke(Object handler, Object message, Dictionary`2 dictionary) in C:\BuildAgent\work\3206e2123f54fce4\src\NServiceBus.Core\Unicast\MessageHandlerRegistry.cs:line 124
   at NServiceBus.InvokeHandlersBehavior.Invoke(IncomingContext context, Action next) in C:\BuildAgent\work\3206e2123f54fce4\src\NServiceBus.Core\Unicast\Behaviors\InvokeHandlersBehavior.cs:line 23
   at NServiceBus.BehaviorChain`1.InvokeNext(T context) in C:\BuildAgent\work\3206e2123f54fce4\src\NServiceBus.Core\Pipeline\BehaviorChain.cs:line 107
   at NServiceBus.BehaviorChain`1.<>c__DisplayClass4_0.<InvokeNext>b__0() in C:\BuildAgent\work\3206e2123f54fce4\src\NServiceBus.Core\Pipeline\BehaviorChain.cs:line 95
   at NServiceBus.SetCurrentMessageBeingHandledBehavior.Invoke(IncomingContext context, Action next) in C:\BuildAgent\work\3206e2123f54fce4\src\NServiceBus.Core\Unicast\Behaviors\SetCurrentMessageBeingHandledBehavior.cs:line 17
   at NServiceBus.BehaviorChain`1.InvokeNext(T context) in C:\BuildAgent\work\3206e2123f54fce4\src\NServiceBus.Core\Pipeline\BehaviorChain.cs:line 107
   at NServiceBus.BehaviorChain`1.<>c__DisplayClass4_0.<InvokeNext>b__0() in C:\BuildAgent\work\3206e2123f54fce4\src\NServiceBus.Core\Pipeline\BehaviorChain.cs:line 95
   at NServiceBus.LoadHandlersBehavior.Invoke(IncomingContext context, Action next) in C:\BuildAgent\work\3206e2123f54fce4\src\NServiceBus.Core\Unicast\Behaviors\LoadHandlersBehavior.cs:line 45
   at NServiceBus.BehaviorChain`1.InvokeNext(T context) in C:\BuildAgent\work\3206e2123f54fce4\src\NServiceBus.Core\Pipeline\BehaviorChain.cs:line 107
   at NServiceBus.BehaviorChain`1.<>c__DisplayClass4_0.<InvokeNext>b__0() in C:\BuildAgent\work\3206e2123f54fce4\src\NServiceBus.Core\Pipeline\BehaviorChain.cs:line 95
   at NServiceBus.BehaviorChain`1.InvokeNext(T context) in C:\BuildAgent\work\3206e2123f54fce4\src\NServiceBus.Core\Pipeline\BehaviorChain.cs:line 107
   at NServiceBus.BehaviorChain`1.<>c__DisplayClass4_0.<InvokeNext>b__0() in C:\BuildAgent\work\3206e2123f54fce4\src\NServiceBus.Core\Pipeline\BehaviorChain.cs:line 95
   at NServiceBus.ExecuteLogicalMessagesBehavior.Invoke(IncomingContext context, Action next) in C:\BuildAgent\work\3206e2123f54fce4\src\NServiceBus.Core\Unicast\Messages\ExecuteLogicalMessagesBehavior.cs:line 24
   at NServiceBus.BehaviorChain`1.InvokeNext(T context) in C:\BuildAgent\work\3206e2123f54fce4\src\NServiceBus.Core\Pipeline\BehaviorChain.cs:line 107
   at NServiceBus.BehaviorChain`1.<>c__DisplayClass4_0.<InvokeNext>b__0() in C:\BuildAgent\work\3206e2123f54fce4\src\NServiceBus.Core\Pipeline\BehaviorChain.cs:line 95
   at NServiceBus.BehaviorChain`1.InvokeNext(T context) in C:\BuildAgent\work\3206e2123f54fce4\src\NServiceBus.Core\Pipeline\BehaviorChain.cs:line 107
   at NServiceBus.BehaviorChain`1.<>c__DisplayClass4_0.<InvokeNext>b__0() in C:\BuildAgent\work\3206e2123f54fce4\src\NServiceBus.Core\Pipeline\BehaviorChain.cs:line 95
   at NServiceBus.BehaviorChain`1.InvokeNext(T context) in C:\BuildAgent\work\3206e2123f54fce4\src\NServiceBus.Core\Pipeline\BehaviorChain.cs:line 107
   at NServiceBus.BehaviorChain`1.<>c__DisplayClass4_0.<InvokeNext>b__0() in C:\BuildAgent\work\3206e2123f54fce4\src\NServiceBus.Core\Pipeline\BehaviorChain.cs:line 95
   at NServiceBus.BehaviorChain`1.InvokeNext(T context) in C:\BuildAgent\work\3206e2123f54fce4\src\NServiceBus.Core\Pipeline\BehaviorChain.cs:line 107
   at NServiceBus.BehaviorChain`1.<>c__DisplayClass4_0.<InvokeNext>b__0() in C:\BuildAgent\work\3206e2123f54fce4\src\NServiceBus.Core\Pipeline\BehaviorChain.cs:line 95
   at NServiceBus.BehaviorChain`1.InvokeNext(T context) in C:\BuildAgent\work\3206e2123f54fce4\src\NServiceBus.Core\Pipeline\BehaviorChain.cs:line 107
   at NServiceBus.BehaviorChain`1.<>c__DisplayClass4_0.<InvokeNext>b__0() in C:\BuildAgent\work\3206e2123f54fce4\src\NServiceBus.Core\Pipeline\BehaviorChain.cs:line 95
   at NServiceBus.UnitOfWorkBehavior.Invoke(IncomingContext context, Action next) in C:\BuildAgent\work\3206e2123f54fce4\src\NServiceBus.Core\UnitOfWork\UnitOfWorkBehavior.cs:line 42
   at NServiceBus.BehaviorChain`1.InvokeNext(T context) in C:\BuildAgent\work\3206e2123f54fce4\src\NServiceBus.Core\Pipeline\BehaviorChain.cs:line 107
   at NServiceBus.BehaviorChain`1.<>c__DisplayClass4_0.<InvokeNext>b__0() in C:\BuildAgent\work\3206e2123f54fce4\src\NServiceBus.Core\Pipeline\BehaviorChain.cs:line 95
   at NServiceBus.Transports.RabbitMQ.OpenPublishChannelBehavior.Invoke(IncomingContext context, Action next) in c:\BuildAgent\work\ef98ad7376e3379a\src\NServiceBus.RabbitMQ\OpenPublishChannelBehavior.cs:line 19
   at NServiceBus.BehaviorChain`1.InvokeNext(T context) in C:\BuildAgent\work\3206e2123f54fce4\src\NServiceBus.Core\Pipeline\BehaviorChain.cs:line 107
   at NServiceBus.BehaviorChain`1.<>c__DisplayClass4_0.<InvokeNext>b__0() in C:\BuildAgent\work\3206e2123f54fce4\src\NServiceBus.Core\Pipeline\BehaviorChain.cs:line 95
   at NServiceBus.ChildContainerBehavior.Invoke(IncomingContext context, Action next) in C:\BuildAgent\work\3206e2123f54fce4\src\NServiceBus.Core\Unicast\Behaviors\ChildContainerBehavior.cs:line 17
   at NServiceBus.BehaviorChain`1.InvokeNext(T context) in C:\BuildAgent\work\3206e2123f54fce4\src\NServiceBus.Core\Pipeline\BehaviorChain.cs:line 107
   at NServiceBus.BehaviorChain`1.<>c__DisplayClass4_0.<InvokeNext>b__0() in C:\BuildAgent\work\3206e2123f54fce4\src\NServiceBus.Core\Pipeline\BehaviorChain.cs:line 95
   at NServiceBus.ProcessingStatisticsBehavior.Invoke(IncomingContext context, Action next) in C:\BuildAgent\work\3206e2123f54fce4\src\NServiceBus.Core\Monitoring\ProcessingStatisticsBehavior.cs:line 23
   at NServiceBus.BehaviorChain`1.InvokeNext(T context) in C:\BuildAgent\work\3206e2123f54fce4\src\NServiceBus.Core\Pipeline\BehaviorChain.cs:line 107
   at NServiceBus.BehaviorChain`1.Invoke() in C:\BuildAgent\work\3206e2123f54fce4\src\NServiceBus.Core\Pipeline\BehaviorChain.cs:line 52
   at NServiceBus.Pipeline.PipelineExecutor.Execute[T](BehaviorChain`1 pipelineAction, T context) in C:\BuildAgent\work\3206e2123f54fce4\src\NServiceBus.Core\Pipeline\PipelineExecutor.cs:line 129
   at NServiceBus.Unicast.Transport.TransportReceiver.OnTransportMessageReceived(TransportMessage msg) in C:\BuildAgent\work\3206e2123f54fce4\src\NServiceBus.Core\Unicast\Transport\TransportReceiver.cs:line 413
   at NServiceBus.Unicast.Transport.TransportReceiver.ProcessMessage(TransportMessage message) in C:\BuildAgent\work\3206e2123f54fce4\src\NServiceBus.Core\Unicast\Transport\TransportReceiver.cs:line 344
   at NServiceBus.Unicast.Transport.TransportReceiver.TryProcess(TransportMessage message) in C:\BuildAgent\work\3206e2123f54fce4\src\NServiceBus.Core\Unicast\Transport\TransportReceiver.cs:line 230
   at NServiceBus.Transports.RabbitMQ.RabbitMqDequeueStrategy.ConsumeMessages(Object state) in c:\BuildAgent\work\ef98ad7376e3379a\src\NServiceBus.RabbitMQ\RabbitMqDequeueStrategy.cs:line 193

1 个答案:

答案 0 :(得分:0)

我的解决方案是更新服务器并安装所有推荐和可选的Windows更新。