Azure-functions-vs-build-sdk: All in a sudden Functions compilation in Visual Studio fails with exception

Created on 13 Nov 2017  路  12Comments  路  Source: Azure/azure-functions-vs-build-sdk

_From @ChristianWeyer on November 12, 2017 20:57_

Hi all,

Did anybody ever see this?

I have a .NET 4.6.1 project. Everything worked fine - util a certain point.
From one moment to the other I get this exception:

2>C:\Users\Christian Weyer\.nuget\packages\microsoft.net.sdk.functions\1.0.6\build\netstandard1.0\Microsoft.NET.Sdk.Functions.Build.targets(32,5): warning :
2>C:\Users\Christian Weyer\.nuget\packages\microsoft.net.sdk.functions\1.0.6\build\netstandard1.0\Microsoft.NET.Sdk.Functions.Build.targets(32,5): error : System.IO.FileNotFoundException: Could not load file or assembly 'Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The system cannot find the file specified.
2>C:\Users\Christian Weyer\.nuget\packages\microsoft.net.sdk.functions\1.0.6\build\netstandard1.0\Microsoft.NET.Sdk.Functions.Build.targets(32,5): error : File name: 'Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'
2>C:\Users\Christian Weyer\.nuget\packages\microsoft.net.sdk.functions\1.0.6\build\netstandard1.0\Microsoft.NET.Sdk.Functions.Build.targets(32,5): error :    at System.Signature.GetSignature(Void* pCorSig, Int32 cCorSig, RuntimeFieldHandleInternal fieldHandle, IRuntimeMethodInfo methodHandle, RuntimeType declaringType)
2>C:\Users\Christian Weyer\.nuget\packages\microsoft.net.sdk.functions\1.0.6\build\netstandard1.0\Microsoft.NET.Sdk.Functions.Build.targets(32,5): error :    at System.Reflection.RuntimeMethodInfo.FetchNonReturnParameters()
2>C:\Users\Christian Weyer\.nuget\packages\microsoft.net.sdk.functions\1.0.6\build\netstandard1.0\Microsoft.NET.Sdk.Functions.Build.targets(32,5): error :    at System.Reflection.RuntimeMethodInfo.GetParameters()
2>C:\Users\Christian Weyer\.nuget\packages\microsoft.net.sdk.functions\1.0.6\build\netstandard1.0\Microsoft.NET.Sdk.Functions.Build.targets(32,5): error :    at MakeFunctionJson.MethodInfoExtensions.GetDisabled(MethodInfo method)
2>C:\Users\Christian Weyer\.nuget\packages\microsoft.net.sdk.functions\1.0.6\build\netstandard1.0\Microsoft.NET.Sdk.Functions.Build.targets(32,5): error :    at MakeFunctionJson.MethodInfoExtensions.HasUnsuportedAttributes(MethodInfo method, String& error)
2>C:\Users\Christian Weyer\.nuget\packages\microsoft.net.sdk.functions\1.0.6\build\netstandard1.0\Microsoft.NET.Sdk.Functions.Build.targets(32,5): error :    at MakeFunctionJson.FunctionJsonConverter.TryGenerateFunctionJsons()
2>C:\Users\Christian Weyer\.nuget\packages\microsoft.net.sdk.functions\1.0.6\build\netstandard1.0\Microsoft.NET.Sdk.Functions.Build.targets(32,5): error :    at MakeFunctionJson.FunctionJsonConverter.TryRun()
2>C:\Users\Christian Weyer\.nuget\packages\microsoft.net.sdk.functions\1.0.6\build\netstandard1.0\Microsoft.NET.Sdk.Functions.Build.targets(32,5): error : 
2>C:\Users\Christian Weyer\.nuget\packages\microsoft.net.sdk.functions\1.0.6\build\netstandard1.0\Microsoft.NET.Sdk.Functions.Build.targets(32,5): error : WRN: Assembly binding logging is turned OFF.
2>C:\Users\Christian Weyer\.nuget\packages\microsoft.net.sdk.functions\1.0.6\build\netstandard1.0\Microsoft.NET.Sdk.Functions.Build.targets(32,5): error : To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
2>C:\Users\Christian Weyer\.nuget\packages\microsoft.net.sdk.functions\1.0.6\build\netstandard1.0\Microsoft.NET.Sdk.Functions.Build.targets(32,5): error : Note: There is some performance penalty associated with assembly bind failure logging.
2>C:\Users\Christian Weyer\.nuget\packages\microsoft.net.sdk.functions\1.0.6\build\netstandard1.0\Microsoft.NET.Sdk.Functions.Build.targets(32,5): error : To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].
2>C:\Users\Christian Weyer\.nuget\packages\microsoft.net.sdk.functions\1.0.6\build\netstandard1.0\Microsoft.NET.Sdk.Functions.Build.targets(32,5): error : 
2>C:\Users\Christian Weyer\.nuget\packages\microsoft.net.sdk.functions\1.0.6\build\netstandard1.0\Microsoft.NET.Sdk.Functions.Build.targets(32,5): error : Error generating functions metadata
2>C:\Users\Christian Weyer\.nuget\packages\microsoft.net.sdk.functions\1.0.6\build\netstandard1.0\Microsoft.NET.Sdk.Functions.Build.targets(32,5): error :
2>C:\Users\Christian Weyer\.nuget\packages\microsoft.net.sdk.functions\1.0.6\build\netstandard1.0\Microsoft.NET.Sdk.Functions.Build.targets(32,5): error : Metadata generation failed.
2>Done building project "HomeAutomation-Functions.csproj" -- FAILED.

I restarted VS, no help.
Any idea?

Thanks!

_Copied from original issue: Azure/Azure-Functions#586_

Most helpful comment

@Yvand I had a similar issue. I moved all "my" code (not the functions) into a separate project. What also worked was changing the access modifier of "my" classes (not the functions) to internal. Both approaches solved the problem for me.

All 12 comments

_From @tohling on November 13, 2017 19:0_

Could you add an explicit reference for Newtonsoft version 9.0.1 and see if the error goes away?

_From @ChristianWeyer on November 13, 2017 20:32_

Thanks for this idea. Yep, tried that. Same result.

After further investigating, I found my issue is similar to this one:
https://github.com/Azure/azure-functions-vs-build-sdk/issues/115
https://github.com/dotnet/sdk/issues/1405

@ahmelsayed did you ever resolve this? I just ran in to this too but haven't been able to identify the right fix to resolve it.
Thanks

Hello, I have exactly this same error in my .NET 4.6.1 Azure function project, but it's really not clear how I should fix it.
I added this in my .csproj but it doesn't change anything:

<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>

Can anybody provide a simple explanation how to fix this?
Thanks

@Yvand I tried the binding redirect too but it didn't help as I believe the error is happening at runtime for the function generator and not in your components. If you see my referenced comment above I basically had to go through the changes line by line to find the offending code (in my case it was refactoring some azure auth code to a shared method) and remove that code. There may be other methods but that painstaking one was the only one I found which resolved this in my instance.

HI @scottcha, aahh ok, thank you.
This is very bad, I realize now that I get this error just because I created a class that inherits JsonMediaTypeFormatter, I have no idea how to work around this...

@Yvand I had a similar issue. I moved all "my" code (not the functions) into a separate project. What also worked was changing the access modifier of "my" classes (not the functions) to internal. Both approaches solved the problem for me.

@cschwendtner Moving my code to a separate class library project mitigated the problem for me. Thanks!

fixed by @cschwendtner in https://github.com/Azure/azure-functions-vs-build-sdk/pull/151 Please update to 1.0.8

I'm still getting this issue with 1.0.8 on .NET Standard 2.0. (Functions V2).

Severity Code Description Project File Line 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()

WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].

Error generating functions metadata
Mobility.Services.Functions C:\Users\MatthewBa.nuget\packages\microsoft.net.sdk.functions1.0.8\build\netstandard1.0\Microsoft.NET.Sdk.Functions.Build.targets 39

I will try the work around now. I'm a bit confused how my function can call my code in other project if I mark it all as internal?

Thanks.

EDIT: Even an empty .net standard 1.08 project will not compile. Downgrading to 1.07 is the only option right now.

@Moffmo - The fix in #151 / 1.0.8 does only fix certain situations (not the "whole" underlying problem) - see this comment.

Compiling an empty Azure Functions V2 (netstandard2.0) project (with 1.0.8) works fine on my machine.
Could you create a sample project to reproduce the error?

The workaround (that was described in this comment) is changing the access modifier of "your" classes (not the functions) to internal OR to move "your" code (not the functions) into a separate project - not doing both.

I'm getting the same issue. Created a StackOverflow for it. StackOverflow link

Was this page helpful?
0 / 5 - 0 ratings