Azure-iot-sdk-csharp: FileUploadE2ETests.FileUpload_X509_SmallFile_Http test failed intermittently for NetStandard

Created on 2 Dec 2017  路  6Comments  路  Source: Azure/azure-iot-sdk-csharp

Failed Microsoft.Azure.Devices.E2ETests.FileUploadE2ETests.FileUpload_X509_SmallFile_Http
Error Message:
Test method Microsoft.Azure.Devices.E2ETests.FileUploadE2ETests.FileUpload_X509_SmallFile_Http threw exception:
System.NullReferenceException: Object reference not set to an instance of an object.
Stack Trace:
at Microsoft.Azure.Devices.Client.IotHubConnectionString.Microsoft.Azure.Devices.Client.IAuthorizationProvider.GetPasswordAsync() in D:\jenkins\workspace\csharp-windows-wip\device\Microsoft.Azure.Devices.Client\IotHubConnectionString.Core.cs:line 22
at Microsoft.Azure.Devices.Client.Transport.HttpClientHelper.d__21.MoveNext() in D:\jenkins\workspace\csharp-windows-wip\device\Microsoft.Azure.Devices.Client\Transport\HttpClientHelper.cs:line 417
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Azure.Devices.Client.Transport.HttpClientHelper.d__17`2.MoveNext() in D:\jenkins\workspace\csharp-windows-wip\device\Microsoft.Azure.Devices.Client\Transport\HttpClientHelper.cs:line 320
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Azure.Devices.Client.Transport.HttpTransportHandler.d__11.MoveNext() in D:\jenkins\workspace\csharp-windows-wip\device\Microsoft.Azure.Devices.Client\Transport\HttpTransportHandler.cs:line 197
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Azure.Devices.E2ETests.FileUploadE2ETests.d__19.MoveNext() in D:\jenkins\workspace\csharp-windows-wip\e2e\Microsoft.Azure.Devices.E2ETests\FileUploadE2ETests.cs:line 160
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Azure.Devices.E2ETests.FileUploadE2ETests.d__15.MoveNext() in D:\jenkins\workspace\csharp-windows-wip\e2e\Microsoft.Azure.Devices.E2ETests\FileUploadE2ETests.cs:line 95
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)

bug

All 6 comments

This is failing on NetCore E2E runs only.

This bug makes the library unusable for x509 authentication with file upload and can be traced to device/Microsoft.Azure.Devices.Client/Transport/HttpClientHelper.cs line 73 (constructor) and 415 (ExecuteAsync).
When the constructor finds itself in a uwp, plc or netstandard1.3 (for core) it ignores whether you have a certificate - so when you get to ExecuteAsync you skip over using the certificate and try and create a password which, because there is no token refresher, throws the above exception.

I've altered the section in my own code to use an HttpClientHandlerin the #else block and managed to successfully upload a file, but I'm more than a bit new to the open source community so haven't made a change to the repository yet.
The change is as follows:
(from line 62 HttpClientHelper.cs)
HttpClientHandler handler = null;

if !WINDOWS_UWP && !PCL && !NETSTANDARD1_3

        if (clientCert != null)
        {
            handler = new WebRequestHandler();
            (handler as WebRequestHandler).ClientCertificates.Add(clientCert);
            this.usingX509ClientCert = true;
        }

else

        if (clientCert != null)
        {
            handler = new HttpClientHandler
            {
                ClientCertificateOptions = ClientCertificateOption.Manual,
            };
            (handler as HttpClientHandler).ClientCertificates.Add(clientCert);
            this.usingX509ClientCert = true;
        }

endif

        this.httpClientObj = handler != null ? new HttpClient(handler) : new HttpClient();

Thanks @labiraus for identifying the issue! Feel free to submit a PR with the change that also re-enables the test.

I'm more than a bit new to the open source community so haven't made a change to the repository yet.

If you'd like to make this change, start by Fork-ing this repo then cloning the fork on your machine. After you push the change to your fork, you will be able to create a Pull Request (using the GitHub website).

Closing as it is linked to issue #424

This issue still isn't resolved even though both this issue and the issue referenced (#424) are closed.

Any update on when this will be fixed?

Thanks @KasperHoldum: Looks like the test is still deactivated, pointing at this issue.

Was this page helpful?
0 / 5 - 0 ratings