Azure / Azure/azure-functions-host
Improve handling of NuGet packages that require assembly binding redirects
- Dominant language
- C#
- Stars
- 2k
- Forks
- 482
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 38
Description
The IOT hub client SDK version 1.0.22 requires an assembly binding redirect (this is added automatically when installing the SDK into a console app). However in functions that assembly binding redirect is not applied and it results in an error.
Steps to reproduce:
1. Create a function with this code and project.json:
``` C#
using System;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Azure.Devices.Client;
private const string DeviceConnectionString = "connection string”;
public static void Run(string input, TraceWriter log)
{
DeviceClient deviceClient = DeviceClient.CreateFromConnectionString(DeviceConnectionString, TransportType.Http1);
if (deviceClient == null)
{
log.Info($"Failed to create DeviceClient!");
}
SendEvent(deviceClient,log).Wait();
log.Info($"C# End");
}
static async Task SendEvent(DeviceClient deviceClient, TraceWriter log)
{
string dataBuffer;
dataBuffer = "Hello world" + Guid.NewGuid().ToString();
Message eventMessage = new Message(Encoding.UTF8.GetBytes(dataBuffer));
log.Info($"C# Send message to the device");
await deviceClient.SendEventAsync(eventMessage);
}
```
```
{
"frameworks": {
"net46":{
"dependencies": {
"Microsoft.Azure.Devices.Client": "1.0.22"
}
}
}
}
```
2. Paste in an appropriate IOT hub connection string and attempt to run the code
Expected result: no assembly loading errors occur
Actual result: `Exception while executing function: Functions.DevicesTest. mscorlib: Exception has been thrown by the target of an invocation. mscorlib: One or more errors occurred. Microsoft.Azure.Devices.Client: 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.`
Contributor guide
Assessment
This issue has not been assessed yet.