Azure / azure-functions-host

The host/runtime that powers Azure Functions
https://functions.azure.com
MIT License
1.93k stars 441 forks source link

Improve handling of NuGet packages that require assembly binding redirects #1017

Open paulbatum opened 7 years ago

paulbatum commented 7 years ago

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:
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"
                    }
                }
        }
}
  1. 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.

paulbatum commented 7 years ago

The experience of debugging this type of issue would also be improved by https://github.com/Azure/azure-webjobs-sdk-script/issues/1023

christopheranderson commented 7 years ago

@fabiocav proposing that we relax some of the matching rules.