Field with type 'FilterFields' does not match any field metadata.*

Any suggestions how to solve below error that occurred after upgrade from 7.0.0. to 7.0.1?

Server Error in ‘/’ Application.

Field with type ‘FilterFields’ does not match any field metadata.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: Litium.FieldFramework.FieldFrameworkException: Field with type ‘FilterFields’ does not match any field metadata.

Source Error:

Line 75: _eventBroker.Subscribe<WebsiteCreated>(x => _webSiteIds.Add(x.SystemId)); Line 76: _eventBroker.Subscribe<WebsiteDeleted>(x => _webSiteIds.Remove(x.SystemId)); Line 77: foreach (var webSite in _websiteService.GetAll()) Line 78: { Line 79: _webSiteIds.Add(webSite.SystemId);

Litium version: 7.0.1

Do you have the Litium.Accelerator.FieldTypes dll in the bin-folder for the web-project?
Are the project referencing the same version of Litium-assemblies? If they not match by version number you probably missing bindingRedirects in web.config (see bindingRedirects on https://docs.litium.com/documentation/upgrading-to-litium-7).

It was the project reference that had gone missing but now there are other errors.
Line 40: BeginContext("~/Litium/App/Views/App/Headers.cshtml", 1, 5, false);
Line 41:
Line 42: Write(model);
Line 43:
Line 44: EndContext("~/Litium/App/Views/App/Headers.cshtml", 1, 5, false);

The SqlParameter is already contained by another SqlParameterCollection.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentException: The SqlParameter is already contained by another SqlParameterCollection.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[ArgumentException: The SqlParameter is already contained by another SqlParameterCollection.] System.Data.SqlClient.SqlParameterCollection.Validate(Int32 index, Object value) +477 System.Data.SqlClient.SqlParameterCollection.Add(Object value) +44 Microsoft.EntityFrameworkCore.Storage.Internal.DynamicRelationalParameter.AddDbParameter(DbCommand command, Object value) +229 Microsoft.EntityFrameworkCore.Storage.Internal.RelationalParameterBase.AddDbParameter(DbCommand command, IReadOnlyDictionary2 parameterValues) +149
Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommand.CreateCommand(IRelationalConnection connection, IReadOnlyDictionary2 parameterValues) +399 Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommand.Execute(IRelationalConnection connection, DbCommandMethod executeMethod, IReadOnlyDictionary2 parameterValues) +116
Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommand.ExecuteReader(IRelationalConnection connection, IReadOnlyDictionary2 parameterValues) +65 Microsoft.EntityFrameworkCore.Query.Internal.Enumerator.BufferlessMoveNext(DbContext _, Boolean buffer) +582 Microsoft.EntityFrameworkCore.Query.Internal.Enumerator.MoveNext() +160 Microsoft.EntityFrameworkCore.Query.Internal.QueryBuffer.IncludeCollection(Int32 includeId, INavigation navigation, INavigation inverseNavigation, IEntityType targetEntityType, IClrCollectionAccessor clrCollectionAccessor, IClrPropertySetter inverseClrPropertySetter, Boolean tracking, TEntity entity, Func1 relatedEntitiesFactory, Func3 joinPredicate) +240 lambda_method(Closure , QueryContext , ChannelToCountryLinkEntity , Object[] ) +883 Microsoft.EntityFrameworkCore.Query.Internal.IncludeCompiler._Include(QueryContext queryContext, TEntity entity, Object[] included, Action3 fixup) +31
lambda_method(Closure , QueryContext , ChannelToCountryLinkEntity ) +296
Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.Internal.TypedProjectionShaper3.Shape(QueryContext queryContext, ValueBuffer& valueBuffer) +141 Microsoft.EntityFrameworkCore.Query.Internal.Enumerator.BufferlessMoveNext(DbContext _, Boolean buffer) +475 Microsoft.EntityFrameworkCore.Storage.ExecutionStrategy.ExecuteImplementation(Func3 operation, Func3 verifySucceeded, TState state) +694 Microsoft.EntityFrameworkCore.Query.Internal.Enumerator.MoveNext() +160 Microsoft.EntityFrameworkCore.Query.Internal.QueryBuffer.IncludeCollection(Int32 includeId, INavigation navigation, INavigation inverseNavigation, IEntityType targetEntityType, IClrCollectionAccessor clrCollectionAccessor, IClrPropertySetter inverseClrPropertySetter, Boolean tracking, TEntity entity, Func1 relatedEntitiesFactory, Func3 joinPredicate) +240 lambda_method(Closure , QueryContext , ChannelEntity , Object[] ) +2508 Microsoft.EntityFrameworkCore.Query.Internal.IncludeCompiler._Include(QueryContext queryContext, TEntity entity, Object[] included, Action3 fixup) +31
lambda_method(Closure , ChannelEntity ) +346
System.Linq.WhereSelectEnumerableIterator2.MoveNext() +238 Microsoft.EntityFrameworkCore.Query.Internal.EnumeratorExceptionInterceptor.MoveNext() +264 System.Collections.Generic.List1…ctor(IEnumerable1 collection) +436 System.Linq.Enumerable.ToList(IEnumerable1 source) +69
Litium.Application.Caching.<>c__DisplayClass4_03.<LoadByPrimaryKey>b__0(LitiumDbContext db) +789 Litium.Application.Data.DbContextExtension.ExecuteInDbContext(IServiceProvider serviceProvider, Func2 loaderFunc) +98
Litium.Application.Caching.EntityCache2.Get(IEnumerable1 key) +999
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() +31
Litium.Application.Runtime.ExceptionEnlightenment.PrepareForRethrow(Exception exception) +49
Litium.Application.Caching.LoadableCacheItem.get_Value() +97
System.Linq.WhereSelectArrayIterator2.MoveNext() +145 System.Linq.WhereEnumerableIterator1.MoveNext() +124
System.Linq.d__172.MoveNext() +173 System.Linq.WhereEnumerableIterator1.MoveNext() +124
System.Linq.Buffer1..ctor(IEnumerable1 source) +281
System.Linq.d__1.MoveNext() +116
System.Linq.Enumerable.FirstOrDefault(IEnumerable1 source) +243 Litium.Application.Web.Routing.RoutingServiceImpl.TryGet(DomainNameRouteLookupInfo lookupInfo, DomainNameRouteInfo& routeInfo) +523 Litium.Web.Routing.ChannelResolverImpl.TryGet(RouteRequestLookupInfo& routeRequestLookupInfo) +1013 Litium.Web.Routing.PageRoute.GetRouteData(HttpContextBase httpContext) +285 System.Web.Routing.RouteCollection.GetRouteData(HttpContextBase httpContext) +258 System.Web.Routing.UrlRoutingModule.PostResolveRequestCache(HttpContextBase context) +68 System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +223 System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step) +213 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +91

I haven’t seen this error before, can you provide code to reproduce the error?

The error comes from Entity Framework Core tracked by Litium bug.

As a workaround before we have a new package ready you can add a file with the following code in your solution (I was using the Litium.Accelerator.Mvc\App_Start folder).

using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Data.SqlClient;
using System.Reflection;
using JetBrains.Annotations;
using Litium.Runtime.DependencyInjection;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.EntityFrameworkCore.Storage.Internal;

namespace Litium.Application.Data.EfCoreOverrides
{
    [Service(ServiceType = typeof(IRelationalCommandBuilderFactory), Lifetime = DependencyLifetime.Singleton)]
    internal class ClonableRelationalCommandBuilderFactory : RelationalCommandBuilderFactory
    {
        public ClonableRelationalCommandBuilderFactory(
            IDiagnosticsLogger<DbLoggerCategory.Database.Command> logger,
            IRelationalTypeMappingSource typeMappingSource)
            : base(logger, typeMappingSource)
        {
        }

        protected override IRelationalCommandBuilder CreateCore(
            [NotNull] IDiagnosticsLogger<DbLoggerCategory.Database.Command> logger,
            [NotNull] IRelationalTypeMappingSource relationalTypeMappingSource)
        {
            return new ClonableRelationalCommandBuilder(logger, relationalTypeMappingSource);
        }
    }

    internal class ClonableRelationalCommandBuilder : RelationalCommandBuilder
    {
        public ClonableRelationalCommandBuilder(
            IDiagnosticsLogger<DbLoggerCategory.Database.Command> logger,
            IRelationalTypeMappingSource typeMappingSource) : base(logger, typeMappingSource)
        {
             ParameterBuilder = new ClonableRelationalParameterBuilder(typeMappingSource);
        }

        public override IRelationalParameterBuilder ParameterBuilder { get; }
    }

    internal class ClonableRelationalParameterBuilder : RelationalParameterBuilder
    {
        private static readonly FieldInfo _parameterFieldInfo = typeof(RelationalParameterBuilder)
            .GetField("_parameters", BindingFlags.Instance | BindingFlags.NonPublic);

        private readonly Lazy<List<IRelationalParameter>> _parameterAccessor;

        public ClonableRelationalParameterBuilder(IRelationalTypeMappingSource typeMappingSource) : base(typeMappingSource)
        {
            _parameterAccessor = new Lazy<List<IRelationalParameter>>(() => (List<IRelationalParameter>)_parameterFieldInfo.GetValue(this));
        }

        protected override RelationalParameterBuilder Create()
        {
            return new ClonableRelationalParameterBuilder(TypeMappingSource);
        }

        public override void AddParameter(string invariantName, string name)
        {
            _parameterAccessor.Value.Add(new ClonableDynamicRelationalParameter(invariantName, name, TypeMappingSource));
        }

        public override void AddRawParameter(string invariantName, DbParameter dbParameter)
        {
            _parameterAccessor.Value.Add(new ClonableRawRelationalParameter(invariantName, dbParameter));
        }
    }

    internal class ClonableDynamicRelationalParameter : DynamicRelationalParameter
    {
        private static readonly FieldInfo _parentFieldInfo = typeof(SqlParameter)
            .GetField("_parent", BindingFlags.Instance | BindingFlags.NonPublic);

        public ClonableDynamicRelationalParameter(string invariantName, string name, IRelationalTypeMappingSource typeMappingSource)
            : base(invariantName, name, typeMappingSource)
        {
        }

        public override void AddDbParameter(DbCommand command, object value)
        {
            if (value is SqlParameter
                && !(_parentFieldInfo.GetValue(value) is null))
            {
                base.AddDbParameter(command, (DbParameter)((ICloneable)value).Clone());
                return;
            }

            base.AddDbParameter(command, value);
        }
    }

    internal class ClonableRawRelationalParameter : RawRelationalParameter
    {
        private static readonly FieldInfo _parentFieldInfo = typeof(SqlParameter)
            .GetField("_parent", BindingFlags.Instance | BindingFlags.NonPublic);

        public ClonableRawRelationalParameter(string invariantName, DbParameter parameter) : base(invariantName, parameter)
        {
        }

        public override void AddDbParameter(DbCommand command, object value)
        {
            if (value is SqlParameter
                && !(_parentFieldInfo.GetValue(value) is null))
            {
                base.AddDbParameter(command, (DbParameter)((ICloneable)value).Clone());
                return;
            }

            base.AddDbParameter(command, value);
        }
    }
}

Now an update Litium-version is out, see Release - Litium 7.0.2 with Accelerator 7.0.2

1 Like

@patric.forsgard Not sure I follow but we have the error below after upgrading to 7.0.2. Anything else we have to do?

If you upgraded the accelerator you could have deleted the web.config in the litium folder.

Yeah, someone had missed committing it due to a too restrictive gitignore file.