winforms 指定的自定义属性的二进制格式无效,XAF更新模型,CustomAttributeException

elcex8rz  于 2023-11-21  发布在  其他
关注(0)|答案(1)|浏览(113)

当我尝试更新我的Model.DesignedDiffs.xafml时,我得到了下面的错误日志。在阅读this post about the exception之后,我想知道是否我有一些Map函数定义不正确
例如,我的代码使用

public static List<T> SqlQueryOfT<T>(string query, string connectionString, Func<DbDataReader, T> map, params SqlParameter[] parameters)
{
    var entities = new List<T>();
    using var cn = new Microsoft.Data.SqlClient.SqlConnection(connectionString);
    using var command = new Microsoft.Data.SqlClient.SqlCommand();
    command.Connection = cn;
    command.CommandText = query;
    command.CommandType = CommandType.Text;
    foreach (var param in parameters)
        command.Parameters.Add(param);
    cn.Open();
    using var result = command.ExecuteReader();
    if (result.HasRows)
    {
        while (result.Read())
        {
            var r = map(result);
            entities.Add(r);
        }
    }
    cn.Close();
    return entities;
}

字符串
这个错误可能是因为我用一个不正确的Map调用这个函数吗?我经常调用这种函数,所以我想知道如何识别哪个Map是问题所在。
我确实安装了Develop. App.Design.NetCorePackage.2022扩展,尽管帮助中没有提到.2022

Model.DesignedDiffs.log包含:

Type:       CustomAttributeFormatException
Message:    Binary format of the specified custom attribute was invalid.
Data:       0 entries
Stack trace:

   at System.Reflection.CustomAttributeEncodedArgument.ParseAttributeArguments(IntPtr pCa, Int32 cCa, CustomAttributeCtorParameter[]& CustomAttributeCtorParameters, CustomAttributeNamedParameter[]& CustomAttributeTypedArgument, RuntimeAssembly assembly)
   at System.Reflection.RuntimeCustomAttributeData..ctor(RuntimeModule scope, MetadataToken caCtorToken, ConstArray& blob)
   at System.Reflection.RuntimeCustomAttributeData.GetCustomAttributes(RuntimeModule module, Int32 tkTarget)
   at System.Reflection.RuntimeCustomAttributeData.GetCustomAttributesInternal(RuntimeType target)
   at System.Reflection.NullabilityInfoContext.GetNullableContext(MemberInfo memberInfo)
   at System.Reflection.NullabilityInfoContext.GetNullabilityInfo(MemberInfo memberInfo, Type type, NullableAttributeStateParser parser, Int32& index)
   at System.Reflection.NullabilityInfoContext.Create(PropertyInfo propertyInfo)
   at Microsoft.EntityFrameworkCore.Metadata.Conventions.NonNullableConventionBase.IsNonNullableReferenceType(IConventionModelBuilder modelBuilder, MemberInfo memberInfo)
   at Microsoft.EntityFrameworkCore.Metadata.Conventions.NonNullableNavigationConvention.IsNonNullable(IConventionModelBuilder modelBuilder, IConventionNavigation navigation)
   at Microsoft.EntityFrameworkCore.Metadata.Conventions.NonNullableNavigationConvention.ProcessNavigation(IConventionNavigationBuilder navigationBuilder)
   at Microsoft.EntityFrameworkCore.Metadata.Conventions.NonNullableNavigationConvention.ProcessNavigationAdded(IConventionNavigationBuilder navigationBuilder, IConventionContext`1 context)
   at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConventionDispatcher.ImmediateConventionScope.OnNavigationAdded(IConventionNavigationBuilder navigationBuilder)
   at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConventionDispatcher.OnNavigationAddedNode.Run(ConventionDispatcher dispatcher)
   at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConventionDispatcher.DelayedConventionScope.Run(ConventionDispatcher dispatcher)
   at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConventionDispatcher.ConventionBatch.Run()
   at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConventionDispatcher.ConventionBatch.Dispose()
   at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConventionDispatcher.ImmediateConventionScope.OnModelInitialized(IConventionModelBuilder modelBuilder)
   at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConventionDispatcher.OnModelInitialized(IConventionModelBuilder modelBuilder)
   at Microsoft.EntityFrameworkCore.Metadata.Internal.Model..ctor(ConventionSet conventions, ModelDependencies modelDependencies, ModelConfiguration modelConfiguration)
   at Microsoft.EntityFrameworkCore.ModelBuilder..ctor(ConventionSet conventions, ModelDependencies modelDependencies, ModelConfiguration modelConfiguration)
   at Microsoft.EntityFrameworkCore.ModelConfigurationBuilder.CreateModelBuilder(ModelDependencies modelDependencies)
   at Microsoft.EntityFrameworkCore.Infrastructure.ModelSource.CreateModel(DbContext context, IConventionSetBuilder conventionSetBuilder, ModelDependencies modelDependencies)
   at Microsoft.EntityFrameworkCore.Infrastructure.ModelSource.GetModel(DbContext context, ModelCreationDependencies modelCreationDependencies, Boolean designTime)
   at Microsoft.EntityFrameworkCore.Internal.DbContextServices.CreateModel(Boolean designTime)
   at Microsoft.EntityFrameworkCore.Internal.DbContextServices.get_Model()
   at Microsoft.EntityFrameworkCore.Infrastructure.EntityFrameworkServicesBuilder.<>c.<TryAddCoreServices>b__8_4(IServiceProvider p)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitFactory(FactoryCallSite factoryCallSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitCache(ServiceCallSite callSite, RuntimeResolverContext context, ServiceProviderEngineScope serviceProviderEngine, RuntimeResolverLock lockType)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScopeCache(ServiceCallSite callSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitCache(ServiceCallSite callSite, RuntimeResolverContext context, ServiceProviderEngineScope serviceProviderEngine, RuntimeResolverLock lockType)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScopeCache(ServiceCallSite callSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitCache(ServiceCallSite callSite, RuntimeResolverContext context, ServiceProviderEngineScope serviceProviderEngine, RuntimeResolverLock lockType)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScopeCache(ServiceCallSite callSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitCache(ServiceCallSite callSite, RuntimeResolverContext context, ServiceProviderEngineScope serviceProviderEngine, RuntimeResolverLock lockType)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScopeCache(ServiceCallSite callSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitCache(ServiceCallSite callSite, RuntimeResolverContext context, ServiceProviderEngineScope serviceProviderEngine, RuntimeResolverLock lockType)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScopeCache(ServiceCallSite callSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitCache(ServiceCallSite callSite, RuntimeResolverContext context, ServiceProviderEngineScope serviceProviderEngine, RuntimeResolverLock lockType)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScopeCache(ServiceCallSite callSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.Resolve(ServiceCallSite callSite, ServiceProviderEngineScope scope)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.DynamicServiceProviderEngine.<>c__DisplayClass2_0.<RealizeService>b__0(ServiceProviderEngineScope scope)
   at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type serviceType, ServiceProviderEngineScope serviceProviderEngineScope)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope.GetService(Type serviceType)
   at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
   at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider)
   at Microsoft.EntityFrameworkCore.DbContext.get_DbContextDependencies()
   at Microsoft.EntityFrameworkCore.DbContext.get_ContextServices()
   at Microsoft.EntityFrameworkCore.DbContext.get_Model()
   at DevExpress.ExpressApp.EFCore.EFCoreTypeInfoSource.CollectEntityTypes()
   at DevExpress.ExpressApp.EFCore.EFCoreTypeInfoSource.GetEntityTypes()
   at DevExpress.ExpressApp.EFCore.EFCoreExportedTypeHelper.CollectTypes()
   at DevExpress.ExpressApp.EFCore.EFCoreExportedTypeHelper.get_CollectedTypes()
   at DevExpress.ExpressApp.EFCore.EFCoreExportedTypeHelper.IsExportedTypeCore(Type type)
   at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
   at DevExpress.ExpressApp.CachedExportedTypeHelper.IsExportedType(Type type)
   at DevExpress.ExpressApp.ExportedTypeHelpers.IsExportedType(Type type)
   at DevExpress.ExpressApp.ModuleBase.IsExportedType(Type type)
   at DevExpress.ExpressApp.ModuleHelper.<>c__DisplayClass2_0.<CollectRequiredExportedTypes>b__0(ITypeInfo t)
   at DevExpress.ExpressApp.DC.TypeInfo.DevExpress.ExpressApp.DC.ITypeInfo.GetRequiredTypes(Predicate`1 filter)
   at DevExpress.ExpressApp.ModuleHelper.CollectRequiredExportedTypes(IEnumerable`1 exportedTypes, Predicate`1 isExportedType)
   at DevExpress.ExpressApp.ModuleBase.GetExportedTypes()
   at DevExpress.ExpressApp.ApplicationModulesManager.<>c.<CollectDomainComponents>b__23_1(ModuleBase m)
   at DevExpress.ExpressApp.ApplicationModulesManager.CollectMany(ModuleList modules, Func`2 method)
   at DevExpress.ExpressApp.ApplicationModulesManager.<CollectDomainComponents>b__23_0()
   at DevExpress.ExpressApp.TypesCache.GetTypes(String group, Func`1 producer)
   at DevExpress.ExpressApp.ApplicationModulesManager.CollectDomainComponents()
   at DevExpress.ExpressApp.ApplicationModulesManager.LoadCore(ITypesInfo typesInfo)
   at DevExpress.ExpressApp.ApplicationModulesManager.Load(ITypesInfo typesInfo, Boolean loadTypesInfo)
   at DevExpress.ExpressApp.Utils.DesignerModelFactory.CreateModulesManager(ModuleBase module, String assembliesPath, List`1 additionalModules, ISecurityStrategyBase securityInstance, Action initializeTypeInfoSources)
   at DevExpress.ExpressApp.Utils.DesignerModelFactory.CreateModulesManager(ModuleBase module, String assembliesPath, Action initializeTypeInfoSources)
   at DevExpress.ExpressApp.Design.ModelEditor.ModelLoader.LoadModel(ITypeDiscoveryService typeDiscoveryService, String targetDiffFileName, IDisposable& obj, ILogger logger)
   at DevExpress.ExpressApp.Design.ModelEditor.ModelEditorFormController.CreateModelEditorController()
   at DevExpress.ExpressApp.Design.ModelEditor.ModelEditorFormController.Init()
   at DevExpress.ExpressApp.Design.ModelEditorServer.ServerHost.CreateNewModelEditor(String fileName, ModelEditorInfo meInfo, String projectUniqueName, Dictionary`2 settings, String frameworkVersion)
   at DevExpress.ExpressApp.Design.ModelEditorServer.ServerHost.<>c__DisplayClass66_0.<OpenModelEditor>b__1()
   at DevExpress.ExpressApp.Design.ModelEditorServer.UiRunner.<>c__DisplayClass3_0.<RunOnUIThreadCore>b__0(Object _)
    InnerException is null


[更新]
这个问题似乎与条件反射有关。
在减少DBContext中的类数量之后,
错误代码:

System.Reflection.CustomAttributeFormatException: 'FontStyle' property specified was not found.
 ---> System.Reflection.CustomAttributeFormatException: 'FontStyle' property specified was not found.
   at System.Reflection.CustomAttribute.AddCustomAttributes(ListBuilder`1& attributes, RuntimeModule decoratedModule, Int32 decoratedMetadataToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, ListBuilder`1 derivedAttributes)
   --- End of inner exception stack trace ---
   at System.Reflection.CustomAttribute.AddCustomAttributes(ListBuilder`1& attributes, RuntimeModule decoratedModule, Int32 decoratedMetadataToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, ListBuilder`1 derivedAttributes)
   at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType)
   at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeType type, RuntimeType caType, Boolean inherit)
   at System.RuntimeType.GetCustomAttributes(Boolean inherit)
   at DevExpress.ExpressApp.DC.BaseTypeInfoSource.<>c.<GetOwnAttributes>b__5_0(Type key)
   at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
   at DevExpress.ExpressApp.DC.BaseTypeInfoSource.GetOwnAttributes(Type type)
   at DevExpress.ExpressApp.DC.BaseTypeInfoSource.InitAttributes(TypeInfo typeInfo)
   at DevExpress.ExpressApp.DC.TypeInfo.EnsureAttributesCore()
   at DevExpress.ExpressApp.DC.BaseInfo.EnsureAttributes()
   at DevExpress.ExpressApp.DC.BaseInfo.FindAttributes[AttributeType](Boolean recursive)+MoveNext()
   at System.Linq.Enumerable.TryGetFirst[TSource](IEnumerable`1 source, Boolean& found)
   at DevExpress.ExpressApp.DC.BaseTypeInfoSource.CalcTypeVisibility(TypeInfo typeInfo)
   at DevExpress.ExpressApp.DC.NonPersistentTypeInfoSource.InitTypeInfo(TypeInfo info)
   at DevExpress.ExpressApp.DC.NonPersistentTypeInfoSource.RegisterEntity(Type type)
   at DevExpress.ExpressApp.DC.TypesInfo.RegisterEntity(Type entityType)
   at DevExpress.ExpressApp.DC.TypesInfo.RegisterEntities(IEnumerable`1 types)
   at DevExpress.ExpressApp.ApplicationModulesManager.LoadDomainComponents(ITypesInfo typesInfo)
   at DevExpress.ExpressApp.ApplicationModulesManager.LoadTypesInfo(ITypesInfo typesInfo)
   at DevExpress.ExpressApp.ApplicationModulesManager.Load(ITypesInfo typesInfo, Boolean loadTypesInfo)
   at DevExpress.ExpressApp.Utils.DesignerModelFactory.CreateModulesManager(ModuleBase module, String assembliesPath, List`1 additionalModules, ISecurityStrategyBase securityInstance, Action initializeTypeInfoSources)
   at DevExpress.ExpressApp.Utils.DesignerModelFactory.CreateModulesManager(ModuleBase module, String assembliesPath, Action initializeTypeInfoSources)
   at DevExpress.ExpressApp.Design.ModelUpdater.UpdateModel(ProjectReference projectReference)
   at DevExpress.ExpressApp.Design.ModelUpdater.UpdateModel(ModelUpdater modelUpdater, ProjectReference projectReference, OutputWindowPane outputWindow)
Update failed


[更新]
非持久性业务对象的以下属性将导致FontStyle错误

[DomainComponent]
[Appearance("ToDoGreen", FontStyle = FontStyle.Regular, BackColor = "#D9EAD3", TargetItems = "*", Criteria = "true", Context = "ListView")]

taor4pac

taor4pac1#

我无法在新的XAF 23.1.6 Winforms EFCore项目中重现这个问题。
目前在我的开发项目中,我可以通过在业务类上不使用外观属性来设置字体样式来解决这个问题。
在我的代码中,当我更新模型时,以下内容将导致错误。

[DomainComponent]
[Appearance("IsPromisedApp", Criteria = "IsValid", FontStyle = System.Drawing.FontStyle.Regular)]

public class ApplicationUser : PermissionPolicyUser, IObjectSpaceLink, ISecurityUserWithLoginInfo
{
    public ApplicationUser() : base() { UserLogins = new ObservableCollection<ApplicationUserLoginInfo>(); }
    [Browsable(false)]
    [DevExpress.ExpressApp.DC.Aggregated]
    public virtual ObservableCollection<ApplicationUserLoginInfo> UserLogins { get; set; }

    public virtual bool IsValid { get; set; }
    System.Collections.Generic.IEnumerable<ISecurityUserLoginInfo> IOAuthSecurityUser.UserLogins => UserLogins.OfType<ISecurityUserLoginInfo>();

    ISecurityUserLoginInfo ISecurityUserWithLoginInfo.CreateUserLoginInfo(
        string loginProviderName,
        string providerUserKey)
    {
        ApplicationUserLoginInfo result = ((IObjectSpaceLink)this).ObjectSpace
            .CreateObject<ApplicationUserLoginInfo>();
        result.LoginProviderName = loginProviderName;
        result.ProviderUserKey = providerUserKey;
        result.User = this;
        return result;
    }
}

字符串
如果我从外观中省略字体样式,或者将外观属性移动到属性上,那么我可以更新模型而不会出错。

相关问题