Azure / Azure/azure-functions-host

Assembly load of Microsoft.Rest.ClientRuntime (and possibly others) doesn't respect nuget reference

Open
#1,743 2 comments 0 reactions 1 assignee Claimed by @fabiocav View on GitHub
needs-investigation
Dominant language
C#
Stars
2k
Forks
482
Avg merge
2d 10h
Merged PRs (30d)
36

Description

#### Investigative information

Please provide the following:

- Timestamp: UTC/GMT is 22:42 on Tuesday, August 1, 2017
- Function App name: assemblyload
- Function name(s) (as appropriate): ManualTriggerCSharp1
- Invocation ID: just run it
- Region: north europe

#### Repro steps

Create a manual CSharp trigger function
Add a project.json with the following content
```
{
"frameworks": {
"net46":{
"dependencies": {
"Microsoft.Rest.ClientRuntime": "2.3.8",
"Microsoft.Rest.ClientRuntime.Azure": "3.3.8"
}
}
}
}
```
Add the following code to run.csx
```
using System;

public static void Run(string input, TraceWriter log)
{
log.Info($"C# manually triggered function called with input: {input}");
var microsoftRestClientRuntime = typeof(Microsoft.Rest.Serialization.TransformationJsonConverter).Assembly.Location;
log.Info(microsoftRestClientRuntime);
log.Info(System.Diagnostics.FileVersionInfo.GetVersionInfo(microsoftRestClientRuntime).FileVersion);

var microsoftRestClientRuntimeAzure = typeof(Microsoft.Rest.Azure.JsonSerializerExtensions).Assembly.Location;
log.Info(microsoftRestClientRuntimeAzure);
log.Info(System.Diagnostics.FileVersionInfo.GetVersionInfo(microsoftRestClientRuntimeAzure).FileVersion);

}
```

#### Expected behavior
When the function is run, I would expect that I get references to the two Nuget packages that I have referenced. But instead the Microsoft.Rest.ClientRuntime.dll gets loaded from the Function runtime installation directory.

The actually output are:
```
2017-08-01T22:40:03.630 D:\Program Files (x86)\SiteExtensions\Functions\1.0.11027\bin\Microsoft.Rest.ClientRuntime.dll
2017-08-01T22:40:03.646 2.3.3.0
2017-08-01T22:40:03.646 D:\home\data\Functions\packages\nuget\Microsoft.Rest.ClientRuntime.Azure\3.3.8\lib\net452\Microsoft.Rest.ClientRuntime.Azure.dll
2017-08-01T22:40:03.646 3.3.8.0
````

This might not be the only assembly that where this is the behavior, I suspect you can reproduce the problem for other assemblies that are shipped with the function runtime and already loaded into the appdomain before the function executes. But this particular version of Microsoft.Rest.ClientRuntime have a bug, which makes it unable to parse certain ARM responses, which effectively prevents me from doing ARM requests from my function app using the nuget libraries provided by Microsoft, because the function runtime uses and old buggy version and/or assembly loading is not working correctly.

Note: you cannot reproduce this error in the visual studio 2017 tooling on a local machine, here it will work. However it will not work when that project is published to azure, then it will fail by loading the wrong verion of the assembly.

#### Known workaround
Rewrite my code to not use function apps or not use the ARM management libraries, neither is really appealing :/

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.