Trying to create instance of class which uses System.ValueTuple from netstandard2.0 project which is referenced by net461/net462/net47 function project results in runtime exception:
Could not load file or assembly 'System.ValueTuple, Version=0.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51’ or one of its dependencies.
Function compiles and works without errors.
Function compiles without errors but throws FileNotFoundException at runtime.
Could not load file or assembly 'System.ValueTuple, Version=0.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51’ or one of its dependencies.
Redirector class
public static class AssemblyRedirector
{
public static void RedirectAssembly(string shortName, string publicKeyToken, string redirectToVersion)
{
ResolveEventHandler handler = null;
handler = (sender, args) =>
{
var requestedAssembly = new AssemblyName(args.Name);
if (requestedAssembly.Name != shortName)
{
return null;
}
var targetPublicKeyToken = new AssemblyName("x, PublicKeyToken=" + publicKeyToken).GetPublicKeyToken();
requestedAssembly.SetPublicKeyToken(targetPublicKeyToken);
requestedAssembly.Version = new Version(redirectToVersion);
requestedAssembly.CultureInfo = CultureInfo.InvariantCulture;
AppDomain.CurrentDomain.AssemblyResolve -= handler;
return Assembly.Load(requestedAssembly);
};
AppDomain.CurrentDomain.AssemblyResolve += handler;
}
}
Function code
public static class Function
{
static Function()
{
AssemblyRedirector.RedirectAssembly("System.ValueTuple", "cc7b13ffcd2ddd51", "4.0.2.0");
}
[FunctionName("Function")]
public static Task Run([HttpTrigger(WebHookType = "genericJson")]HttpRequestMessage req, TraceWriter log)
{
...
}
}
Experiencing same issue.
Created simple test repo : https://github.com/Sharpiro/StandardTuplePackageTest
create a new http trigger function, add project.json:
{
"frameworks": {
"net46":{
"dependencies": {
"StandardTuplePackageTest": "1.0.1"
}
}
}
}
run.csx:
using System.Net;
using System.Net.Http.Headers;
using StandardTuplePackageTest;
public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log)
{
await Task.Yield();
var testClass = new TestClass();
var data = testClass.GetData();
var response = new HttpResponseMessage(HttpStatusCode.OK);
response.Content = new StringContent(data.ToString());
response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
return response;
}
Error:
{
"id": "cc10b081-bc86-487e-b07d-7c1b1c1c0efe",
"requestId": "7b5f5e4d-958a-440b-bbbe-37e809a1176b",
"statusCode": 500,
"errorCode": 0,
"message": "Exception while executing function: Functions.FacebookCallback -> One or more errors occurred. -> Could not load file or assembly 'System.ValueTuple, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)"
}
I'm having the same issue, and I'm not even using Tuples - I guess a dependency must be. I was just upgrading my codebase to target .NET Standard 2.0, and am now getting this.
Does anyone know if there's an approximate ETA for a fix for this? I'm just wondering whether to wait for a fix, or try and find a way around it. I'm guessing a breaking issue like this would have quite a high priory/turnaround - so I'm wary about spending time trying to work around it if it's going to be fixed soon. But saying that - it has been a month since it was reported ¯_(ツ)_/¯
Actually, I've managed to find a way around it by adding an assembly redirect. As my issue was with Azure Functions, which doesn't have an app.config or web.config - I had to do it programmatically using the method described int he blog post below ...
+1
I get the same problem at compile time, not runtime with an Azure Function project:
Severity Code Description Project Path File Line Source Suppression State
Error System.IO.FileNotFoundException: Could not load file or assembly 'System.ValueTuple, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The system cannot find the file specified.
File name: 'System.ValueTuple, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'
at MakeFunctionJson.FunctionJsonConverter.TryGenerateFunctionJsons()
at MakeFunctionJson.FunctionJsonConverter.TryRun()
=== Pre-bind state information ===
LOG: DisplayName = System.ValueTuple, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51
(Fully-specified)
LOG: Appbase = file:///C:/.../.nuget/packages/microsoft.net.sdk.functions/1.0.8/tools/net46/
LOG: Initial PrivatePath = NULL
LOG: This bind starts in default load context.
LOG: No application configuration file found.
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
LOG: Post-policy reference: System.ValueTuple, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51
LOG: Attempting download of new URL file:///C:/Users/name/.nuget/packages/microsoft.net.sdk.functions/1.0.8/tools/net46/System.ValueTuple.DLL.
LOG: Attempting download of new URL file:///C:/Users/name/.nuget/packages/microsoft.net.sdk.functions/1.0.8/tools/net46/System.ValueTuple/System.ValueTuple.DLL.
LOG: Attempting download of new URL file:///C:/Users/name/.nuget/packages/microsoft.net.sdk.functions/1.0.8/tools/net46/System.ValueTuple.EXE.
LOG: Attempting download of new URL file:///C:/Users/name/.nuget/packages/microsoft.net.sdk.functions/1.0.8/tools/net46/System.ValueTuple/System.ValueTuple.EXE.
Error generating functions metadata
AzureFunctionPoc C:\Users\name.nuget\packages\microsoft.net.sdk.functions\1.0.8\build\netstandard1.0 C:\Users\name.nuget\packages\microsoft.net.sdk.functions\1.0.8\build\netstandard1.0\Microsoft.NET.Sdk.Functions.Build.targets 39 Build
Visual Studio 15.5.6
Microsoft.NET.Sdk.Functions 1.0.8
I checked the System.ValueTuple project, but cannot find a version 4.0.2.0.
Same problem here. Microsoft is unable to deliver any software that just works.
I create a new Azure Function in a blank, new and up to date Visual Studio 2017 - and when trying to publish the Function App, I get there strange error messages complaining about System Tuples which I have never heard of before...
Why is it so complicated to test things?
I had this too - reverting my Function App to Microsoft.NET.Sdk.Functions (1.0.6) resolved it for me.
Deleting the following folder worked for me. Project now compiles.
C:\Users\name.nuget\packages\microsoft.net.sdk.functions\1.0.8\build\netstandard1.0
Visual Studio 15.5.7, .NET Standard 2.0, Microsoft.NET.Sdk.Functions (1.0.8)
Same problem that @leftside described, build error. The problem with deleting the folder is that only solves the problem for my development machine. The build machine starts clean each time and pulls the nuget packages down fresh so that folder keeps showing up.
Most helpful comment
Deleting the following folder worked for me. Project now compiles.
C:\Users\name.nuget\packages\microsoft.net.sdk.functions\1.0.8\build\netstandard1.0
Visual Studio 15.5.7, .NET Standard 2.0, Microsoft.NET.Sdk.Functions (1.0.8)