-
Type: Bug
-
Resolution: Duplicate
-
Priority: Unknown
-
None
-
Affects Version/s: 2.29.0
-
Component/s: None
-
None
-
Dotnet Drivers
Summary
The following filter fails in an FindOneAndUpdateAsync() call (LinqV3):
var update = Update .PullFilter(d => d.CustomAttributes, a => a.Id == attributeId) await Collection.FindOneAndUpdateAsync(filter,...); // CustomAttributes: ImmutableArray<AttributeConfiguration> { get; init; } // Id: Guid
Exception:
MongoDB.Driver.Linq.ExpressionNotSupportedException
Expression not supported: Convert(d.CustomAttributes, IEnumerable`1).
at MongoDB.Driver.Linq.Linq3Implementation.Translators.ExpressionToFilterTranslators.ToFilterFieldTranslators.ConvertExpressionToFilterFieldTranslator.Translate(TranslationContext context, UnaryExpression expression)
at MongoDB.Driver.Linq.Linq3Implementation.Translators.ExpressionToFilterTranslators.ToFilterFieldTranslators.ExpressionToFilterFieldTranslator.Translate(TranslationContext context, Expression expression)
at MongoDB.Driver.Linq.Linq3Implementation.LinqProviderAdapterV3.TranslateExpressionToField[TDocument](LambdaExpression expression, IBsonSerializer`1 documentSerializer, IBsonSerializerRegistry serializerRegistry)
at MongoDB.Driver.ExpressionFieldDefinition`1.Render(RenderArgs`1 args)
at MongoDB.Driver.PullUpdateDefinition`2.Render(RenderArgs`1 args)
at MongoDB.Driver.CombinedUpdateDefinition`1.Render(RenderArgs`1 args)
at MongoDB.Driver.MongoCollectionImpl`1.CreateFindOneAndUpdateOperation[TProjection](FilterDefinition`1 filter, UpdateDefinition`1 update, FindOneAndUpdateOptions`2 options)
at MongoDB.Driver.MongoCollectionImpl`1.FindOneAndUpdateAsync[TProjection](IClientSessionHandle session, FilterDefinition`1 filter, UpdateDefinition`1 update, FindOneAndUpdateOptions`2 options, CancellationToken cancellationToken)
at Heavendata.Core.Persistence.CustomizableEntities.EntityConfigurationRepositoryBase`1.DeleteAttribute(Guid attributeId)
How to Reproduce
I tried to isolate the issue and while it's not exactly the same error message,...
[Fact] public void Driver_should_create_field_definition_from_property_of_type_ImmutableArray() { Expression<Func<TestModel, IEnumerable<string>>> expression = m => m.Arr; var fieldDefinition = new ExpressionFieldDefinition<TestModel>(expression); var serializerRegistry = BsonSerializer.SerializerRegistry; var documentSerializer = serializerRegistry.GetSerializer<TestModel>(); // This line will throw an exception fieldDefinition.Render(new(documentSerializer, serializerRegistry)); } public record TestModel(ImmutableArray<string> Arr);
Fails with:
System.ArgumentException
GenericArguments[0], 'System.Collections.Immutable.ImmutableArray`1[System.String]', on 'MongoDB.Bson.Serialization.Serializers.EnumerableInterfaceImplementerSerializer`2[TValue,TItem]' violates the constraint of type 'TValue'.
Additional Background
The test above works if you replace ImmutableArray with ImmutableList, or List.
Changing ImmutableArray<string> to ImmutableArray<MyClass> doesn't change anything.
- is related to
-
CSHARP-5335 New serializers for ImmutableArray and other immutable collections
- Closed