{"action":"created","issue":{"url":"https://api.github.com/repos/Azure/azure-iot-sdk-csharp/issues/407","repository_url":"https://api.github.com/repos/Azure/azure-iot-sdk-csharp","labels_url":"https://api.github.com/repos/Azure/azure-iot-sdk-csharp/issues/407/labels{/name}","comments_url":"https://api.github.com/repos/Azure/azure-iot-sdk-csharp/issues/407/comments","events_url":"https://api.github.com/repos/Azure/azure-iot-sdk-csharp/issues/407/events","html_url":"https://github.com/Azure/azure-iot-sdk-csharp/issues/407","id":306041419,"number":407,"title":"Exception throwed when calling RegisterAsync of ProvisioningDeviceClient in UWP environment","user":{"login":"henry1111","id":34282275,"avatar_url":"https://avatars3.githubusercontent.com/u/34282275?v=4","gravatar_id":"","url":"https://api.github.com/users/henry1111","html_url":"https://github.com/henry1111","followers_url":"https://api.github.com/users/henry1111/followers","following_url":"https://api.github.com/users/henry1111/following{/other_user}","gists_url":"https://api.github.com/users/henry1111/gists{/gist_id}","starred_url":"https://api.github.com/users/henry1111/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/henry1111/subscriptions","organizations_url":"https://api.github.com/users/henry1111/orgs","repos_url":"https://api.github.com/users/henry1111/repos","events_url":"https://api.github.com/users/henry1111/events{/privacy}","received_events_url":"https://api.github.com/users/henry1111/received_events","type":"User","site_admin":false},"labels":[{"id":461746546,"url":"https://api.github.com/repos/Azure/azure-iot-sdk-csharp/labels/bug","name":"bug","color":"1d76db","default":true}],"state":"open","locked":false,"assignee":{"login":"CIPop","id":8635911,"avatar_url":"https://avatars2.githubusercontent.com/u/8635911?v=4","gravatar_id":"","url":"https://api.github.com/users/CIPop","html_url":"https://github.com/CIPop","followers_url":"https://api.github.com/users/CIPop/followers","following_url":"https://api.github.com/users/CIPop/following{/other_user}","gists_url":"https://api.github.com/users/CIPop/gists{/gist_id}","starred_url":"https://api.github.com/users/CIPop/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CIPop/subscriptions","organizations_url":"https://api.github.com/users/CIPop/orgs","repos_url":"https://api.github.com/users/CIPop/repos","events_url":"https://api.github.com/users/CIPop/events{/privacy}","received_events_url":"https://api.github.com/users/CIPop/received_events","type":"User","site_admin":false},"assignees":[{"login":"CIPop","id":8635911,"avatar_url":"https://avatars2.githubusercontent.com/u/8635911?v=4","gravatar_id":"","url":"https://api.github.com/users/CIPop","html_url":"https://github.com/CIPop","followers_url":"https://api.github.com/users/CIPop/followers","following_url":"https://api.github.com/users/CIPop/following{/other_user}","gists_url":"https://api.github.com/users/CIPop/gists{/gist_id}","starred_url":"https://api.github.com/users/CIPop/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CIPop/subscriptions","organizations_url":"https://api.github.com/users/CIPop/orgs","repos_url":"https://api.github.com/users/CIPop/repos","events_url":"https://api.github.com/users/CIPop/events{/privacy}","received_events_url":"https://api.github.com/users/CIPop/received_events","type":"User","site_admin":false}],"milestone":null,"comments":0,"created_at":"2018-03-16T18:56:26Z","updated_at":"2018-03-16T23:26:22Z","closed_at":null,"author_association":"NONE","body":"OS Windows 10 IOT Core, OS version 10.0.16299.248, x64\r\nApplication's .NET Target Framework :  \r\n  NetCore UWP\r\n \r\nDEVICETYPE:  Raspberry PI3, Upboard \r\nSDK version used:\r\n    Azure.Devices.Client v1.7.0\r\n    Azure.Devices.Provisioning.Client  v.1.1.0\r\n\r\n# Description of the issue:\r\nusing x509 certificate for security, the following line throw exceptions regardless HTTP, MQTT or AMQP transport are used.\r\n\r\nDeviceRegistrationResult result = await provClient.RegisterAsync();\r\n\r\nFor HTTP, a little interesting.   it complains certificate not found in the personal(\\my) store.  The certificate was imported in LocalMachine\\My store.   when I try to add the certificate to CurrentUser\\My, it returns with AccessDenied.  This is strange.  Even if I can successfully add the certificate personal store, it will be still a different user other than the app running on, as I am logged in Administrator account, and App is running in DefaultAccount.\r\n\r\n\r\nUsing http,\r\n\r\nClient certificate was not found in the personal (\\\"MY\\\") certificate store. In UWP, client certificates are only supported if they have been added to that certificate store.\r\n\r\n   at System.Net.Http.HttpClientHandler.<ApplyClientCertificateSettings>d__107.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n  at System.Net.Http.HttpClientHandler.<ConfigureRequest>d__104.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Net.Http.HttpClientHandler.<SendAsync>d__111.MoveNext()\r\n\r\n\r\nUsing MQTT\r\nOne or more errors occurred. (The credentials supplied to the package were not recognized)\r\n\r\n\r\n  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at Microsoft.Azure.Devices.Provisioning.Client.Transport.ProvisioningChannelHandlerAdapter.<ChannelActive>d__16.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at Microsoft.Azure.Devices.Provisioning.Client.Transport.ProvisioningTransportHandlerMqtt.<ProvisionOverTcpUsingX509CertificateAsync>d__14.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at Microsoft.Azure.Devices.Provisioning.Client.Transport.ProvisioningTransportHandlerMqtt.<RegisterAsync>d__12.MoveNext()\r\n\r\nusing AMQP\r\n\r\nMethod not found: 'Void Microsoft.Azure.Amqp.Transport.TlsTransportSettings.set_Certificate(System.Security.Cryptography.X509Certificates.X509Certificate2)'.\r\n\r\n   at Microsoft.Azure.Devices.Provisioning.Client.Transport.AmqpClientConnection.<OpenAsync>d__22.MoveNext()\r\n   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder.Start[TStateMachine](TStateMachine& stateMachine)\r\n   at Microsoft.Azure.Devices.Provisioning.Client.Transport.AmqpClientConnection.OpenAsync(TimeSpan timeout, Boolean useWebSocket, X509Certificate2 clientCert)\r\n   at Microsoft.Azure.Devices.Provisioning.Client.Transport.AmqpAuthStrategyX509.OpenConnectionAsync(AmqpClientConnection connection, TimeSpan timeout, Boolean useWebSocket)\r\n   at Microsoft.Azure.Devices.Provisioning.Client.Transport.ProvisioningTransportHandlerAmqp.<RegisterAsync>d__7.MoveNext()\r\n\r\n\r\n# Code sample exhibiting the issue:\r\n\r\n public sealed class StartupTask : IBackgroundTask\r\n    {\r\n        private BackgroundTaskDeferral _deferral;\r\n        private const string GlobalDeviceEndpoint = \"global.azure-devices-provisioning.net\";\r\n        private static string s_idScope = \"0ne00008EC9\";\r\n        public async void Run(IBackgroundTaskInstance taskInstance)\r\n        {\r\n            // \r\n            // TODO: Insert code to perform background work\r\n            //\r\n            // If you start any asynchronous methods here, prevent the task\r\n            // from closing prematurely by using BackgroundTaskDeferral as\r\n            // described in http://aka.ms/backgroundtaskdeferral\r\n            //\r\n\r\n            _deferral = taskInstance.GetDeferral();\r\n            await ProvisionTaskAsync();\r\n\r\n\r\n\r\n        }\r\n\r\n        private  async Task ProvisionTaskAsync()\r\n        {\r\n            try\r\n            {\r\n                X509Store store = new X509Store(StoreLocation.LocalMachine);\r\n                store.Open(OpenFlags.ReadOnly);\r\n                X509Certificate2 deviceCert = null;\r\n                foreach (var cert in store.Certificates)\r\n                {\r\n                    if (cert.HasPrivateKey == true)\r\n                    {\r\n                        deviceCert = cert;\r\n                        break;\r\n                    }\r\n                }\r\n\r\n                using (var security = new SecurityProviderX509Certificate(deviceCert))\r\n                using (var transport = new ProvisioningTransportHandlerHttp())\r\n                //using (var transport = new ProvisioningTransportHandlerAmqp(TransportFallbackType.TcpOnly))\r\n                //using (var transport = new ProvisioningTransportHandlerMqtt(TransportFallbackType.TcpOnly))\r\n                {\r\n                    ProvisioningDeviceClient provClient =\r\n                        ProvisioningDeviceClient.Create(GlobalDeviceEndpoint, s_idScope, security, transport);\r\n\r\n                    Debug.WriteLine($\"RegistrationID = {security.GetRegistrationID()}\");\r\n                    Debug.Write(\"ProvisioningClient RegisterAsync . . . \");\r\n                    DeviceRegistrationResult result = await provClient.RegisterAsync();\r\n\r\n                    Debug.WriteLine($\"{result.Status}\");\r\n                    Debug.WriteLine($\"ProvisioningClient AssignedHub: {result.AssignedHub}; DeviceID: {result.DeviceId}\");\r\n\r\n                    if (result.Status != ProvisioningRegistrationStatusType.Assigned) return;\r\n\r\n                    IAuthenticationMethod auth = new DeviceAuthenticationWithX509Certificate(result.DeviceId, deviceCert);\r\n                    using (DeviceClient iotClient = DeviceClient.Create(result.AssignedHub, auth))\r\n                    {\r\n                        Debug.WriteLine(\"DeviceClient OpenAsync.\");\r\n                        await iotClient.OpenAsync();\r\n                        Debug.WriteLine(\"DeviceClient SendEventAsync.\");\r\n                        await iotClient.SendEventAsync(new Message(Encoding.UTF8.GetBytes(\"TestMessage\")));\r\n                        Debug.WriteLine(\"DeviceClient CloseAsync.\");\r\n                        await iotClient.CloseAsync();\r\n                    }\r\n                }\r\n\r\n            }\r\n            catch( Exception ex)\r\n            {\r\n\r\n            }\r\n        }\r\n    }\r\n"},"comment":{"url":"https://api.github.com/repos/Azure/azure-iot-sdk-csharp/issues/comments/373871016","html_url":"https://github.com/Azure/azure-iot-sdk-csharp/issues/407#issuecomment-373871016","issue_url":"https://api.github.com/repos/Azure/azure-iot-sdk-csharp/issues/407","id":373871016,"user":{"login":"CIPop","id":8635911,"avatar_url":"https://avatars2.githubusercontent.com/u/8635911?v=4","gravatar_id":"","url":"https://api.github.com/users/CIPop","html_url":"https://github.com/CIPop","followers_url":"https://api.github.com/users/CIPop/followers","following_url":"https://api.github.com/users/CIPop/following{/other_user}","gists_url":"https://api.github.com/users/CIPop/gists{/gist_id}","starred_url":"https://api.github.com/users/CIPop/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CIPop/subscriptions","organizations_url":"https://api.github.com/users/CIPop/orgs","repos_url":"https://api.github.com/users/CIPop/repos","events_url":"https://api.github.com/users/CIPop/events{/privacy}","received_events_url":"https://api.github.com/users/CIPop/received_events","type":"User","site_admin":false},"created_at":"2018-03-16T23:26:22Z","updated_at":"2018-03-16T23:26:22Z","author_association":"CONTRIBUTOR","body":"Thanks @henry1111 for the detailed report! I've added this to the Xamarin stabilization effort."}}
{"actor":{"display_login":"CIPop"}}