Azure / azure-functions-host

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

FileNotFoundException: Could not load file or assembly for Function app referencing custom assembly #2961

Open mikhailshilkov opened 6 years ago

mikhailshilkov commented 6 years ago

I'm running Host from the latest sources of dev branch as described in Running locally (Visual Studio) (v2+).

I'm pointing to my test Function App which consists of two C# projects: FunctionApp and it references a library Lib. When I start debugging and call the function, I get

FileNotFoundException: Could not load file or assembly 'Lib...

image

If I remove the reference of library and all usages, the functions runs just fine.

It seems to be a recent regression, since the exact same project works fine when I checkout v2.0.11651-alpha. v2.0.11737-alpha already fails.

Function App is referencing Microsoft.NET.Sdk.Functions version 1.0.13, and is just a basic app with 1 HTTP function.

mikhailshilkov commented 6 years ago

cc @fabiocav

fabiocav commented 6 years ago

I'm unable to repro this with bits in dev or currently released bits.

Here's the repro code I'm using: https://github.com/fabiocav/ProjectDependencyFunctionIssue

Running from both, the standalone host and the CLI seems to work.

mikhailshilkov commented 6 years ago

OK, I get the same error with your function.

BOOM. What am I doing wrong?

fabiocav commented 6 years ago

Ha.... that code path, currently, does rely on the AzureWebJobsScriptRoot being set as an environment variable. For your flow, just set that in the project properties (under debug) and that should take care of the problem

mikhailshilkov commented 6 years ago

That helps indeed, thanks. I suggest to fix it though for the setting, or get rid of the setting altogether.

fabiocav commented 6 years ago

Moving this to unknown for now. It is an improvement we should make, but doesn't impact customer facing scenarios.

bipsmojio commented 5 years ago

I found a similar issue while debugging it can not start the host because of the file not found for the function assembly with .net core sdk 2.2 and fix was changing the build property type from 64 bit to Any .

kps-promad commented 5 years ago

I am facing a similar issue now when running locally and using a dll from an internally published Nuget.

System.Private.CoreLib: Exception while executing function: ProcessRawImageDataASC. ContainerImgScanning: Could not load file or assembly 'Microsoft.Azure.Security.Detection.ContainerVA.Contracts, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. Could not find or load a specific file. (Exception from HRESULT: 0x80131621). System.Private.CoreLib: Could not load file or assembly 'Microsoft.Azure.Security.Detection.ContainerVA.Contracts, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'

I see that this dll is present in the bin folder when VS builds the project. I tried setting the "AzureWebJobsScriptRoot" to point to the bin folder but that did not help either.

My build property is "AnyCPU" as well .. Can someone please assist here.

SeanFeldman commented 4 years ago

Running into the same issue. @fabiocav is this environment variable still the one to use?