Compiling Azure Function v1 (.NET Framework) gives FileNotFoundException for Microsoft.Azure.WebJobs

|▌冷眼眸甩不掉的悲伤 提交于 2021-02-11 09:40:19

问题


I have an Azure Functions v1 project (ala .NET Framework) in Visual Studio 2017. It would build / compile just fine for a long time, now it's giving the following FileNotFoundException complaining it can't find 'Microsoft.Azure.WebJobs' v2.2. The thing it this project was building just fine, then all of a sudden this error is occurring.

In the past I would close Visual Studio, then reopen it and the build would work. Or even if you Clean the solution, the build would then work. The problem is now I get this error no matter what I do. I've even restarted the computer!

Here the full compiler exception displayed in Visual Studio 2017 for the Azure Functions v1 project:

Severity    Code    Description Project File    Line    Suppression State
Error       System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Azure.WebJobs, Version=2.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
File name: 'Microsoft.Azure.WebJobs, Version=2.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
   at System.ModuleHandle.ResolveType(RuntimeModule module, Int32 typeToken, IntPtr* typeInstArgs, Int32 typeInstCount, IntPtr* methodInstArgs, Int32 methodInstCount, ObjectHandleOnStack type)
   at System.ModuleHandle.ResolveTypeHandleInternal(RuntimeModule module, Int32 typeToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext)
   at System.Reflection.RuntimeModule.ResolveType(Int32 metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
   at System.Reflection.CustomAttribute.FilterCustomAttributeRecord(CustomAttributeRecord caRecord, MetadataImport scope, Assembly& lastAptcaOkAssembly, RuntimeModule decoratedModule, MetadataToken decoratedToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, Object[] attributes, IList derivedAttributes, RuntimeType& attributeType, IRuntimeMethodInfo& ctor, Boolean& ctorHasParameters, Boolean& isVarArg)
   at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType, Boolean mustBeInheritable, IList derivedAttributes, Boolean isDecoratedTargetSecurityTransparent)
   at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeType type, RuntimeType caType, Boolean inherit)
   at System.Attribute.InternalGetAttributeUsage(Type type)
   at System.Attribute.InternalParamGetCustomAttributes(ParameterInfo param, Type type, Boolean inherit)
   at MakeFunctionJson.ParameterInfoExtensions.GetDisabledAttribute(ParameterInfo parameterInfo)
   at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
   at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
   at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source)
   at MakeFunctionJson.MethodInfoExtensions.GetDisabled(MethodInfo method)
   at MakeFunctionJson.MethodInfoExtensions.HasUnsuportedAttributes(MethodInfo method, String& error)
   at MakeFunctionJson.FunctionJsonConverter.<GenerateFunctions>d__9.MoveNext()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   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
    Company.Assembly    C:\Users\chris\.nuget\packages\microsoft.net.sdk.functions\1.0.24\build\netstandard1.0\Microsoft.NET.Sdk.Functions.Build.targets    41  

Notice the last line shows an error generating functions metadata and the path displayed is a 'netstandard1.0' path. This looks to be the root cause of the problem. However, this project is a .NET Framework 4.6.1 project; not .NET Standard 1.0.

Any suggestions you have to offer would be greatly appreciated. Also, I'll post my solution once I get it figured out. Thanks!

Update 1: I had previously referenced a NuGet Package that was built for .NET Standard 2.0, so I removed the reference for that, and found a couple references to NETStandard and NETCore packages within the 'package.config' file, so I removed those.

<package id="Microsoft.NETCore.Platforms" version="1.1.0" targetFramework="net461" />
<package id="NETStandard.Library" version="1.6.1" targetFramework="net461" />

Removing those 2 references did NOT work to fix the problem. It seems it's still trying to build a .NET Framework based Azure Functions v1 project as if it were .NET Standard 1.0.

Update 2: I tried deleting the C:\Users\chris\.nuget\packages\microsoft.net.sdk.functions local folder that is referenced in the build exception to see if that would "fix" the issue by re-downloading from Nuget the build files for Azure Functions v1; this is the build script that's throwing the exception. Visual Studio did re-download the files from Nuget, but this did NOT fix the problem either.


回答1:


After going around and around with what could possibly be the issue, I finally fixed it!

Apparently, the Microsoft.Azure.WebJobs.ServiceBus v2.3 NuGet Package is NOT compatible with .NET Framework based Azure Functions v1. I removed the Nuget reference then added a reference to Microsoft.Azure.WebJobs.ServiceBus v2.2 and the build started working again. So much for backwards compatibility! I hope this helps others fix this issue when it arises.



来源:https://stackoverflow.com/questions/54154354/compiling-azure-function-v1-net-framework-gives-filenotfoundexception-for-mic

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!