Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Unable to create CosmosClient instance when using version 3.3.0 - dotnetcore 2.2 console app #891

Closed
patrickdoodyIRL opened this issue Oct 10, 2019 · 7 comments · Fixed by #895
Assignees
Labels
bug Something isn't working

Comments

@patrickdoodyIRL
Copy link

Describe the bug
When creating an instance of Microsoft.Azure.Cosmos.CosmosClient in a dotnetcore 2.2 console application an exception is thrown from the CosmosClient constructor. This is only an issue with Microsoft.Azure.Cosmos version 3.3.0, version 3.2.0 works as expected.

            using (CosmosClient client = new CosmosClient(endpoint, authKey))
            {
            }

Stack Trace shows an FormatException being thrown from the DocumentClient.Initialize method when configuring some http headers.

Stack Trace
Unhandled Exception: System.FormatException: The format of value '18.7.0: Tue Aug 20 16:57:14 PDT 2019; root:xnu-4903.271.2~2/RELEASE_X86_64/X64 3.3.0/3.3.0-.NET Core 4.6.27817.03 89710' is invalid.
at System.Net.Http.Headers.HttpHeaderParser.ParseValue(String value, Object storeValue, Int32& index)
at System.Net.Http.Headers.HttpHeaders.ParseAndAddValue(HeaderDescriptor descriptor, HeaderStoreItemInfo info, String value)
at System.Net.Http.Headers.HttpHeaders.Add(HeaderDescriptor descriptor, String value)
at Microsoft.Azure.Cosmos.DocumentClient.Initialize(Uri serviceEndpoint, ConnectionPolicy connectionPolicy, Nullable1 desiredConsistencyLevel, HttpMessageHandler handler, ISessionContainer sessionContainer, Nullable1 enableCpuMonitor, IStoreClientFactory storeClientFactory)
at Microsoft.Azure.Cosmos.DocumentClient..ctor(Uri serviceEndpoint, String authKeyOrResourceToken, EventHandler1 sendingRequestEventArgs, ConnectionPolicy connectionPolicy, Nullable1 desiredConsistencyLevel, JsonSerializerSettings serializerSettings, ApiType apitype, EventHandler1 receivedResponseEventArgs, HttpMessageHandler handler, ISessionContainer sessionContainer, Nullable1 enableCpuMonitor, Func`2 transportClientHandlerFactory, IStoreClientFactory storeClientFactory)
at Microsoft.Azure.Cosmos.CosmosClient..ctor(String accountEndpoint, String authKeyOrResourceToken, CosmosClientOptions clientOptions)

To Reproduce
Create a new dotnetcore 2.2 console application. Add a reference to a Microsoft.Azure.Cosmos v3.3.0. Attempt to create an instance of the CosmosClient class using a valid endpoint and api key.

Expected behavior
The CosmosClient instance is created.

Actual behavior
An exception is thrown and the CosmosClient instance is not created.

Environment summary
Visual Studio Community 2019 for Mac
Version 8.3 (build 1805)
Installation UUID: 49761e24-5ec7-4b3d-a0c5-4b1f27352f35
GTK+ 2.24.23 (Raleigh theme)
Xamarin.Mac 5.16.1.24 (d16-3 / 08809f5b)

Package version: 604000198

Mono Framework MDK
Runtime:
Mono 6.4.0.198 (2019-06/fe64a4765e6) (64-bit)
Package version: 604000198

NuGet
Version: 5.3.0.6192

.NET Core SDK
SDK: /usr/local/share/dotnet/sdk/3.0.100/Sdks
SDK Versions:
3.0.100
2.2.401
2.1.701
2.1.700
2.1.505
2.1.504
2.1.402
2.1.4
MSBuild SDKs: /Library/Frameworks/Mono.framework/Versions/6.4.0/lib/mono/msbuild/Current/bin/Sdks

.NET Core Runtime
Runtime: /usr/local/share/dotnet/dotnet
Runtime Versions:
3.0.0
2.2.6
2.1.13
2.1.12
2.1.11
2.1.9
2.1.8
2.1.4
2.0.5

Xamarin.Profiler
Version: 1.6.12.26
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

Updater
Version: 11

Apple Developer Tools
Xcode 10.3 (14492.2)
Build 10G8

Xamarin.Mac
Version: 6.2.0.42 (Visual Studio Community)
Hash: 5e8a208b
Branch: d16-3
Build date: 2019-09-17 14:19:30-0400

Xamarin.iOS
Version: 13.2.0.42 (Visual Studio Community)
Hash: 5e8a208b
Branch: d16-3
Build date: 2019-09-17 14:19:30-0400

Xamarin.Android
Version: 10.0.0.43 (Visual Studio Community)
Commit: xamarin-android/d16-3/8af1ca8
Android SDK: /Users/patrickdoody/Library/Developer/Xamarin/android-sdk-macosx
Supported Android versions:
7.0 (API level 24)
7.1 (API level 25)
8.0 (API level 26)
8.1 (API level 27)

SDK Tools Version: 26.1.1
SDK Platform Tools Version: 29.0.2
SDK Build Tools Version: 29.0.2

Build Information:
Mono: mono/mono@7af64d1ebe9
Java.Interop: xamarin/java.interop/d16-3@5836f58
LibZipSharp: grendello/LibZipSharp/d16-3@71f4a94
LibZip: nih-at/libzip@b95cf3f
ProGuard: xamarin/proguard@905836d
SQLite: xamarin/sqlite@8212a2d
Xamarin.Android Tools: xamarin/xamarin-android-tools/d16-3@cb41333

Microsoft Mobile OpenJDK
Java SDK: /Users/patrickdoody/Library/Developer/Xamarin/jdk/microsoft_dist_openjdk_1.8.0.25
1.8.0-25
Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

Android SDK Manager
Version: 1.4.0.65
Hash: c33b107
Branch: remotes/origin/d16-3
Build date: 2019-09-19 20:42:44 UTC

Android Device Manager
Version: 1.2.0.115
Hash: 724ea69
Branch: remotes/origin/d16-3
Build date: 2019-09-19 20:43:06 UTC

Xamarin Inspector
Version: 1.4.3
Hash: db27525
Branch: 1.4-release
Build date: Mon, 09 Jul 2018 21:20:18 GMT
Client compatibility: 1

Xamarin Designer
Version: 16.3.0.230
Hash: bbe518670
Branch: remotes/origin/d16-3-xcode11
Build date: 2019-09-17 18:39:30 UTC

Build Information
Release ID: 803001805
Git revision: df50511ccb08d4d84a53939f1d7fc0b40cbb0ee1
Build date: 2019-09-20 16:10:55+00
Build branch: release-8.3
Xamarin extensions: da8d448cd65f2cc87c5e6dc7e2c2ca7b96d20c72

Operating System
Mac OS X 10.14.6
Darwin 18.7.0 Darwin Kernel Version 18.7.0
Tue Aug 20 16:57:14 PDT 2019
root:xnu-4903.271.2~2/RELEASE_X86_64 x86_64

Enabled user installed extensions
Xamarin.Forms HotReload extension 1.4.0
.NET Core support for Mono.Debugging 8.0.5

Additional context
Add any other context about the problem here (for example, complete stack traces or logs).

@j82w j82w added the bug Something isn't working label Oct 10, 2019
@j82w
Copy link
Contributor

j82w commented Oct 10, 2019

@patrickdoodyIRL thank you for the detailed report. This looks like a bug caused by the additional user agent information that was recently added. My current theory is Mac and other non-Windows platform have special characters that need to be escaped and are not currently getting escaped. Windows does not have these special characters which is why we didn't see this. I'll hopefully have a PR out today with the fix.

@j82w j82w self-assigned this Oct 10, 2019
@j82w
Copy link
Contributor

j82w commented Oct 10, 2019

I have a repo and working on a fix now.

@j82w
Copy link
Contributor

j82w commented Oct 11, 2019

@patrickdoodyIRL 3.3.1 is released. Please let me know if you still have an issue.

@ctrlaltdan
Copy link

@j82w Sorry to reopen this ticket but using build 3.3.2 I get the following exception (which looks very similar to the above).

System.FormatException: The format of value '17:02:44 UTC 2019/X64 3.3.0/3.3.0-.NET Core 3.0.0 42733' is invalid.
  at System.Net.Http.Headers.HttpHeaderParser.ParseValue(String value, Object storeValue, Int32& index)
  at System.Net.Http.Headers.HttpHeaders.ParseAndAddValue(HeaderDescriptor descriptor, HeaderStoreItemInfo info, String value)
  at System.Net.Http.Headers.HttpHeaders.Add(String name, String value)
  at Microsoft.Azure.Documents.HttpClientExtension.AddUserAgentHeader(HttpClient httpClient, UserAgentContainer userAgent)
  at Microsoft.Azure.Cosmos.DocumentClient.Initialize(Uri serviceEndpoint, ConnectionPolicy connectionPolicy, Nullable`1 desiredConsistencyLevel, HttpMessageHandler handler, ISessionContainer sessionContainer, Nullable`1 enableCpuMonitor, IStoreClientFactory storeClientFactory)

Hosted in docker, using Ubuntu 16.04 machines with netcoreapp3.0/netstandard2.1.

@j82w
Copy link
Contributor

j82w commented Oct 22, 2019

@ctrlaltdan are you sure you updated to 3.3.2? Can you try deleting the bin and obj folders and making sure you aren't using a cached version. The user agent string in the error message says it's version 3.3.0

@ctrlaltdan
Copy link

🤦‍♂️ my bad! Everything works fine. Just for the record - it was also an issue on Ubuntu :D

@j82w
Copy link
Contributor

j82w commented Oct 23, 2019

Yeah, that's why the change log specifies non-windows.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants