Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

InvalidOperationException due to a type mismatch in OData Client (potential race condition) #2541

Open
habbes opened this issue Oct 25, 2022 · 0 comments
Assignees
Labels

Comments

@habbes
Copy link
Contributor

habbes commented Oct 25, 2022

Short summary (3-5 sentences) describing the issue.

I encountered the following error in OData Client while debugging another issue (#2532). It occurred while running a sample program that executes two requests concurrently. The error is hard to reproduce, I had to run the program repeatedly to reproduce it. I didn't investigate it further, but it could be race condition.

Unhandled exception. System.AggregateException: One or more errors occurred. (The complex type 'System.Collections.Generic.IDictionary`2[System.String,System.Object]' has no settable properties.)
---> System.InvalidOperationException: The complex type 'System.Collections.Generic.IDictionary`2[System.String,System.Object]' has no settable properties.
   at Microsoft.OData.Client.ClientEdmModel.ValidateComplexType(Type type, EdmTypeCacheValue cachedEdmType)
   at Microsoft.OData.Client.ClientEdmModel.GetOrCreateEdmType(Type type)
   at Microsoft.OData.Client.ClientEdmModel.CreateEdmProperty(IEdmStructuredType declaringType, PropertyInfo propertyInfo)
   at Microsoft.OData.Client.ClientEdmModel.<>c__DisplayClass37_0.<GetOrCreateEdmTypeInternal>b__0(EdmEntityTypeWithDelayLoadedProperties entityType)
   at Microsoft.OData.Client.Providers.EdmEntityTypeWithDelayLoadedProperties.EnsurePropertyLoaded()
   at Microsoft.OData.Client.Providers.EdmEntityTypeWithDelayLoadedProperties.get_DeclaredProperties()
   at Microsoft.OData.Client.Metadata.ClientTypeAnnotation.DiscoverEdmProperties()+MoveNext()
   at System.Collections.Generic.LargeArrayBuilder`1.AddRange(IEnumerable`1 items)
   at System.Collections.Generic.EnumerableHelpers.ToArray[T](IEnumerable`1 source)
   at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
   at Microsoft.OData.Client.Metadata.ClientTypeAnnotation.EdmProperties()
   at Microsoft.OData.Client.Metadata.ClientTypeAnnotation.BuildPropertyCache()
   at Microsoft.OData.Client.Metadata.ClientTypeAnnotation.GetProperty(String propertyName, UndeclaredPropertyBehavior undeclaredPropertyBehavior)
   at Microsoft.OData.Client.Materialization.StructuralValueMaterializationPolicy.MaterializeDataValues(ClientTypeAnnotation actualType, IEnumerable`1 values, UndeclaredPropertyBehavior undeclaredPropertyBehavior)
   at Microsoft.OData.Client.Materialization.EntryValueMaterializationPolicy.MaterializeResolvedEntry(MaterializerEntry entry, Boolean includeLinks)
   at Microsoft.OData.Client.Materialization.EntryValueMaterializationPolicy.Materialize(MaterializerEntry entry, Type expectedEntryType, Boolean includeLinks)
   at Microsoft.OData.Client.Materialization.ODataEntityMaterializer.DirectMaterializePlan(ODataEntityMaterializer materializer, MaterializerEntry entry, Type expectedEntryType)
   at Microsoft.OData.Client.Materialization.ODataEntityMaterializerInvoker.DirectMaterializePlan(Object materializer, Object entry, Type expectedEntryType)
   at Microsoft.OData.Client.ProjectionPlan.Run(ODataEntityMaterializer materializer, ODataResource entry, Type expectedType)
   at Microsoft.OData.Client.Materialization.ODataEntityMaterializer.ReadImplementation()
   at Microsoft.OData.Client.MaterializeAtom.MoveNextInternal()
   at Microsoft.OData.Client.MaterializeAtom.MoveNext()
   at System.Linq.Enumerable.CastIterator[TResult](IEnumerable source)+MoveNext()
   at ODataClientExample.Program.GetPeople(DefaultContainer context) in C:\Users\clhabins\source\experiments\ODataClientDuplicateEdmTypeRaceCondition\ODataClientDuplicateEdmTypeRaceCondition\Program.cs:line 40
   at ODataClientExample.Program.ConcurrentMixedRequests() in C:\Users\clhabins\source\experiments\ODataClientDuplicateEdmTypeRaceCondition\ODataClientDuplicateEdmTypeRaceCondition\Program.cs:line 128
   --- End of inner exception stack trace ---
   at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
   at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
   at System.Threading.Tasks.Task.Wait()
   at ODataClientExample.Program.Main(String[] args) in C:\Users\clhabins\source\experiments\ODataClientDuplicateEdmTypeRaceCondition\ODataClientDuplicateEdmTypeRaceCondition\Program.cs:line 18

Affected assemblies

Microsoft.OData.Core 7.12.2

Reproduce steps

Run the sample program in this repo repeatedly: https://github.com/habbes/experiments/tree/master/ODataClientDuplicateEdmTypeRaceCondition,
In my case I had it running in a loop by entering the following command in a Powershell terminal:

For ($i=1; $i -le 1000; $i++)  { dotnet run -c Release; }

Expected result

No error should occur.

Actual result

The exception above occurs.

Additional detail

Optional, details of the root cause if known. Delete this section if you have no additional details to add.

@habbes habbes self-assigned this Oct 25, 2022
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant