{"action":"created","issue":{"url":"https://api.github.com/repos/Azure/azure-iot-sdks/issues/978","repository_url":"https://api.github.com/repos/Azure/azure-iot-sdks","labels_url":"https://api.github.com/repos/Azure/azure-iot-sdks/issues/978/labels{/name}","comments_url":"https://api.github.com/repos/Azure/azure-iot-sdks/issues/978/comments","events_url":"https://api.github.com/repos/Azure/azure-iot-sdks/issues/978/events","html_url":"https://github.com/Azure/azure-iot-sdks/issues/978","id":190941466,"number":978,"title":"Microsoft.Azure.Devices.Client in an Azure Function","user":{"login":"jantielens","id":9884103,"avatar_url":"https://avatars.githubusercontent.com/u/9884103?v=3","gravatar_id":"","url":"https://api.github.com/users/jantielens","html_url":"https://github.com/jantielens","followers_url":"https://api.github.com/users/jantielens/followers","following_url":"https://api.github.com/users/jantielens/following{/other_user}","gists_url":"https://api.github.com/users/jantielens/gists{/gist_id}","starred_url":"https://api.github.com/users/jantielens/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jantielens/subscriptions","organizations_url":"https://api.github.com/users/jantielens/orgs","repos_url":"https://api.github.com/users/jantielens/repos","events_url":"https://api.github.com/users/jantielens/events{/privacy}","received_events_url":"https://api.github.com/users/jantielens/received_events","type":"User","site_admin":false},"labels":[{"id":356336017,"url":"https://api.github.com/repos/Azure/azure-iot-sdks/labels/CSS","name":"CSS","color":"e99695","default":false},{"id":255806175,"url":"https://api.github.com/repos/Azure/azure-iot-sdks/labels/help%20wanted","name":"help wanted","color":"159818","default":true}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2016-11-22T09:00:48Z","updated_at":"2016-12-03T02:13:30Z","closed_at":null,"body":"I'm trying to connect to an IoT Hub from an Azure Function (that acts as cloud API for demo purposes). I've added the NuGet package in the project.json file. But when I execute the function, I get an exception:\r\n\r\n`Could not load file or assembly 'Validation, Version=2.0.0.0, Culture=neutral, PublicKeyToken=2fc06f0d701809a7' or one of its dependencies. The system cannot find the file specified.`\r\n\r\nI tried adding the Validation NuGet package manually to the project.json as well, but no change.\r\n\r\nAny ideas?\r\nThanks!\r\nJan"},"comment":{"url":"https://api.github.com/repos/Azure/azure-iot-sdks/issues/comments/264608603","html_url":"https://github.com/Azure/azure-iot-sdks/issues/978#issuecomment-264608603","issue_url":"https://api.github.com/repos/Azure/azure-iot-sdks/issues/978","id":264608603,"user":{"login":"anhashia","id":18488888,"avatar_url":"https://avatars.githubusercontent.com/u/18488888?v=3","gravatar_id":"","url":"https://api.github.com/users/anhashia","html_url":"https://github.com/anhashia","followers_url":"https://api.github.com/users/anhashia/followers","following_url":"https://api.github.com/users/anhashia/following{/other_user}","gists_url":"https://api.github.com/users/anhashia/gists{/gist_id}","starred_url":"https://api.github.com/users/anhashia/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/anhashia/subscriptions","organizations_url":"https://api.github.com/users/anhashia/orgs","repos_url":"https://api.github.com/users/anhashia/repos","events_url":"https://api.github.com/users/anhashia/events{/privacy}","received_events_url":"https://api.github.com/users/anhashia/received_events","type":"User","site_admin":false},"created_at":"2016-12-03T02:13:30Z","updated_at":"2016-12-03T02:13:30Z","body":"Hi @jantielens \r\nBelow is the root cause and workaround for your issue\r\n\r\n**Root Cause**\r\n`````\r\n2016-11-18T22:59:32.594 Error in sample System.AggregateException: One or more errors occurred. ---> System.IO.FileNotFoundException: Could not load file or assembly 'Validation, Version=2.0.0.0, Culture=neutral, PublicKeyToken=2fc06f0d701809a7' or one of its dependencies. The system cannot find the file specified.\r\n   at PCLCrypto.MacAlgorithmProvider.CreateHash(Byte[] keyMaterial)\r\n   at Microsoft.Azure.Devices.Client.SharedAccessSignatureBuilder.Sign(String requestString, String key)\r\n   at Microsoft.Azure.Devices.Client.SharedAccessSignatureBuilder.BuildSignature(String keyName, String key, String target, TimeSpan timeToLive)\r\n   at Microsoft.Azure.Devices.Client.SharedAccessSignatureBuilder.ToSignature()\r\n`````````\r\nLooks like PCLCrypto tries to load older version of validation assembly which doesn't exist in Azure Service Environment because it uses newer version Validation (>= 2.2.8) \r\nThe reason you don't see this issue in console application is because of **bindingredirect** https://msdn.microsoft.com/en-us/library/eftw1fys(v=vs.110).aspx element\r\n````\r\n<bindingRedirect oldVersion=\"0.0.0.0-2.2.0.0\" newVersion=\"2.2.0.0\" />\r\n````\r\nCurrently, it seems Azure function **doesn't** support `<bindingRedirect>` element and hence it doesn't work in Azure Function App Service environment.\r\n\r\nSo **workaround** would be to force PCLCrypto to use older version of **validation.dll**\r\nBelow is the workaround for the issue\r\n\r\n**Workaround**\r\nUse following in your **project.json**. This will install **latest** version of the available Azure IoT SDK assemblies but will install older version of validation.dll\r\n\r\n```````\r\n{\r\n\"frameworks\": {\r\n    \"net46\":{\r\n        \"dependencies\": {\r\n            \"Microsoft.Azure.Devices.Client\": \"1.1.1\",\r\n             \"Microsoft.Azure.Devices.Shared\": \"1.0.2\",\r\n             \"Validation\": \"2.0.6.15003\"\r\n                    }\r\n                }\r\n        }\r\n}\r\n````````````\r\n\r\n\r\n"}}
{"actor":{"display_login":"anhashia"}}