OData.Client throws ArgumentException
- Dominant language
- C#
- Stars
- 2.9k
- Forks
- 576
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 96
Description
### Description
When using OData.Client nuget package (https://www.nuget.org/packages/Microsoft.OData.Client/) on MacCatalyst or iOS with MAUI, application throws `System.ArgumentException` while executing query on OData context. Other platforms (Android, Windows) behave as expected - return queried data.
Exception message tells that the key has been already added. In my case I was able to spot two keys, causing problem:
- OData-Version
- X-AspNet-Version
I tested this with local API and I can tell that HTTP call reaches WebAPI endpoint, so I guess the problem is in response processing.
Exception message: "An item with the same key has already been added. Key: X-AspNet-Version"
### Steps to Reproduce
Using provided example repo:
1. Run _testOdataMaui_ project on MacCatalyst or iOS.
2. Click "Click Me" button.
3. Exception will be displayed via Alert modal.
4. Mac Catalyst project also avaliable in _odataMacCatalystExample_ project
### Expected Behavior
OData client executes query without exception.
### Actual Behavior
OData Client throws exception on iOS and Mac Catalyst platforms.
```shell
Exception message: "An item with the same key has already been added. Key: X-AspNet-Version"
Exception StackTrace:
at System.Collections.Generic.Dictionary`2[[System.String, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.String, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].TryInsert(String key, String value, InsertionBehavior behavior)
at System.Collections.Generic.Dictionary`2[[System.String, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.String, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].Add(String key, String value)
at System.Linq.Enumerable.ToDictionary[KeyValuePair`2,String,String](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector, IEqualityComparer`1 comparer)
at System.Linq.Enumerable.ToDictionary[KeyValuePair`2,String,String](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector)
at Microsoft.OData.Client.HttpClientRequestMessage.ConvertHttpWebResponse(HttpResponseMessage response)
at Microsoft.OData.Client.HttpClientRequestMessage.b__42_0()
at Microsoft.OData.Client.HttpClientRequestMessage.UnwrapAggregateException[HttpWebResponseMessage](Func`1 action)
at Microsoft.OData.Client.HttpClientRequestMessage.GetResponse()
at Microsoft.OData.Client.ODataRequestMessageWrapper.GetResponse()
at Microsoft.OData.Client.DataServiceContext.GetResponseHelper(ODataRequestMessageWrapper request, IAsyncResult asyncResult, Boolean handleWebException)
at Microsoft.OData.Client.DataServiceContext.GetSynchronousResponse(ODataRequestMessageWrapper request, Boolean handleWebException)
at Microsoft.OData.Client.RequestInfo.GetSynchronousResponse(ODataRequestMessageWrapper request, Boolean handleWebException)
at Microsoft.OData.Client.QueryResult.ExecuteQuery()
at Microsoft.OData.Client.DataServiceRequest.Execute[PeopleModel](DataServiceContext context, QueryComponents queryComponents)
at Microsoft.OData.Client.DataServiceQuery`1[[testOdataMaui.PeopleModel, testOdataMaui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].Execute()
at testOdataMaui.MainPage.OnCounterClicked(Object sender, EventArgs e) in /Users/mat3o/Repos/testOdataMaui/MainPage.xaml.cs:line 18
```
### Environment
Version information
```
Visual Studio Community 2022 for Mac
Version 17.4.2 (build 17)
Installation UUID: c9028d46-6a98-4597-961a-40555b3452f1
Runtime
.NET 6.0.12 (64-bit)
Architecture: Arm64
Roslyn (Language Service)
6.4.0-6.22578.12+3c6ab8e1715e5b080fb7bb77070810ab71e09387
NuGet
Version: 6.3.1.1
.NET SDK (Arm64)
SDK: /usr/local/share/dotnet/sdk/7.0.102/Sdks
SDK Versions:
7.0.102
7.0.404
MSBuild SDKs: /Applications/Visual Studio.app/Contents/MonoBundle/MSBuild/Current/bin/Sdks
.NET SDK (x64)
SDK Version: 3.1.426
.NET Runtime (Arm64)
Runtime: /usr/local/share/dotnet/dotnet
Runtime Versions:
8.0.2
6.0.12
.NET Runtime (x64)
Runtime: /usr/local/share/dotnet/x64/dotnet
Runtime Version: 3.1.32
Xamarin.Profiler
Version: 1.8.0.19
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler
Updater
Version: 11
Xamarin.Android
Version: 13.1.0.1 (Visual Studio Community)
Commit: xamarin-android/d17-4/13ba222
Android SDK: /Users/user1/Library/Developer/Xamarin/android-sdk-macosx
Supported Android versions:
13.0 (API level 33)
SDK Command-line Tools Version: 7.0
SDK Platform Tools Version: 33.0.2
SDK Build Tools Version: 32.0.0
Build Information:
Mono: a96bde9
Java.Interop: xamarin/java.interop/d17-4@fcc33ce2
SQLite: xamarin/sqlite/3.39.3@23e1ae7
Xamarin.Android Tools: xamarin/xamarin-android-tools/main@0be567a
Microsoft Build of OpenJDK
Java SDK: /Library/Java/JavaVirtualMachines/microsoft-11.jdk
11.0.12
Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL
Eclipse Temurin JDK
Java SDK: /Library/Java/JavaVirtualMachines/temurin-8.jdk
1.8.0.302
Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL
Android SDK Manager
Version: 17.4.0.54
Hash: 6eabb9e
Branch: remotes/origin/d17-4
Build date: 2022-12-13 00:02:50 UTC
Android Device Manager
Version: 0.0.0.1206
Hash: 886af39
Branch: 886af39
Build date: 2022-12-13 00:02:50 UTC
Xamarin Designer
Version: 17.4.0.136
Hash: d49c9ff6d3
Branch: remotes/origin/d17-4
Build date: 2022-12-13 00:02:45 UTC
Apple Developer Tools
Xcode 14.2 (21534)
Build 14C18
Xamarin.Mac
Xamarin.Mac not installed. Can't find /Library/Frameworks/Xamarin.Mac.framework/Versions/Current/Version.
Xamarin.iOS
Version: 16.1.1.27 (Visual Studio Community)
Hash: 933c6c2c9
Branch: xcode14.1
Build date: 2022-11-22 02:00:37-0500
Build Information
Release ID: 1704020017
Git revision: 7ef5413f2eec3351ce648085f619fc29fd8cb647
Build date: 2022-12-13 00:00:15+00
Build branch: release-17.4
Build lane: release-17.4
Operating System
Mac OS X 13.1.0
Darwin 22.2.0 Darwin Kernel Version 22.2.0
Fri Nov 11 02:06:26 PST 2022
root:xnu-8792.61.2~4/RELEASE_ARM64_T8112 arm64
```
### Build Logs
### Example Project (If Possible)
https://github.com/Mat3oo/Maui_OdataClient_example
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.