New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.0.11-1.0.12: Azure Function Host Fails to Initialize #745

Closed
pragnagopa opened this Issue Apr 2, 2018 · 39 comments

Comments

Projects
None yet
10 participants
@pragnagopa

pragnagopa commented Apr 2, 2018

From @Mike-EEE on March 29, 2018 20:29

I apologize if this is already captured somewhere. I did a search and it did not seem to apply to anything recent. I just now upgraded my Azure Function app (which was made from scratch, File -> New->Http Trigger) to 1.0.12, and am running into an error when running F5 to develop locally on my machine.

Here is what is emitted to the console:

[3/29/2018 8:24:56 PM] Reading host configuration file 'C:\Users\..\Documents\Visual Studio 2017\Projects\FunctionApp1\FunctionApp1\bin\Debug\netstandard2.0\host.json'
[3/29/2018 8:24:56 PM] Host configuration file read:
[3/29/2018 8:24:56 PM] {}
[3/29/2018 8:24:56 PM] ScriptHost initialization failed
[3/29/2018 8:24:56 PM] System.Private.CoreLib: Could not load file or assembly 'Microsoft.AspNetCore.Mvc.Abstractions, Version=2.0.2.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. Could not find or load a specific file. (Exception from HRESULT: 0x80131621). System.Private.CoreLib: Could not load file or assembly 'Microsoft.AspNetCore.Mvc.Abstractions, Version=2.0.2.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.
Listening on http://localhost:7071/
Hit CTRL-C to exit...
Object reference not set to an instance of an object.
Press any to continue....[3/29/2018 8:24:58 PM] Reading host configuration file 'C:\Users\..\Documents\Visual Studio 2017\Projects\FunctionApp1\FunctionApp1\bin\Debug\netstandard2.0\host.json'
[3/29/2018 8:24:58 PM] Host configuration file read:
[3/29/2018 8:24:58 PM] {}
[3/29/2018 8:24:58 PM] ScriptHost initialization failed
[3/29/2018 8:24:58 PM] System.Private.CoreLib: Could not load file or assembly 'Microsoft.AspNetCore.Mvc.Abstractions, Version=2.0.2.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. Could not find or load a specific file. (Exception from HRESULT: 0x80131621). System.Private.CoreLib: Could not load file or assembly 'Microsoft.AspNetCore.Mvc.Abstractions, Version=2.0.2.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.
[3/29/2018 8:25:00 PM] Reading host configuration file 'C:\Users\..\Documents\Visual Studio 2017\Projects\FunctionApp1\FunctionApp1\bin\Debug\netstandard2.0\host.json'
[3/29/2018 8:25:00 PM] Host configuration file read:
[3/29/2018 8:25:00 PM] {}
[3/29/2018 8:25:00 PM] ScriptHost initialization failed
[3/29/2018 8:25:00 PM] System.Private.CoreLib: Could not load file or assembly 'Microsoft.AspNetCore.Mvc.Abstractions, Version=2.0.2.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. Could not find or load a specific file. (Exception from HRESULT: 0x80131621). System.Private.CoreLib: Could not load file or assembly 'Microsoft.AspNetCore.Mvc.Abstractions, Version=2.0.2.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.

Additionally, attempting to visit this app via HTTP results in the following message in the browser:
Function host is not running.

Going back in time, it seems this starts with 1.0.11. Version 1.0.10 works without any exceptions and executes as expected.

Please note this is a v2 application that I am running. It appears that all information that is being requested in the template is for deployed instances in Azure. To reiterate, this is a local development host. I apologize in advance if I have overlooked something obvious here that is required.

Please let me know of any further information you need and I will be happy to assist.

Copied from original issue: Azure/azure-functions-host#2605

@pragnagopa

This comment has been minimized.

pragnagopa commented Apr 2, 2018

From @Mike-EEE on March 30, 2018 17:57

I am really surprised no one else is encountering this problem? After performing some spelunking, I found a workaround at moment:

  1. Right-click project folder -> Open Folder in File Explorer.
  2. bin\Debug\netstandard2.0\bin
  3. Copy Microsoft.AspNetCore.Mvc.Abstractions.dll
  4. Navigate to C:\Users\<user>\AppData\Local\Azure.Functions.V2.Cli\2.0.1-beta.22
  5. Rename the existing Microsoft.AspNetCore.Mvc.Abstractions.dll to _Microsoft.AspNetCore.Mvc.Abstractions.dll
  6. Paste the Microsoft.AspNetCore.Mvc.Abstractions.dll from the 3rd step.
@pragnagopa

This comment has been minimized.

pragnagopa commented Apr 2, 2018

Root cause: Visual Studio has not been updated to use the latest CLI tools.
Work around until VS tools get updated:

  • npm install -g azure-functions-core-tools

  • cd to Fucntion App folder with .csproj

  • start azure functions host manually --> func host start

Note: we are working on releasing an update to VS tools

@pragnagopa

This comment has been minimized.

pragnagopa commented Apr 2, 2018

@andreujuanc

This comment has been minimized.

andreujuanc commented Apr 3, 2018

@pragnagopa npm install -g azure-functions-core-tools without specifying the version?

Shoudnt it be 2.0.1-beta.25?

EDIT:

Found this for v2:
npm i -g azure-functions-core-tools@core --unsafe-perm true
As per official docs: https://github.com/Azure/azure-functions-core-tools

And I think the installation folder (to replace the dll) is this one: C:\Users\andre\AppData\Roaming\npm\node_modules\azure-functions-core-tools\bin

@pragnagopa

This comment has been minimized.

pragnagopa commented Apr 3, 2018

@andreujuanc - yes you are right. To install cli for v2 please use: npm i -g azure-functions-core-tools@core --unsafe-perm true

@Mike-EEE

This comment has been minimized.

Mike-EEE commented Apr 3, 2018

cd to Fucntion App folder with .csproj
start azure functions host manually --> func host start

Alright I am a little confused here, unfortunately. This is for Visual Studio, correct? When I hit F5 I get the same functionality here in regards to func host start, so I guess I am wondering am I supposed to do this func host start before I hit F5 or when? Help a newb out here please. 😆

@pragnagopa

This comment has been minimized.

pragnagopa commented Apr 3, 2018

@Mike-EEE - when you hit F5 from VS, it starts the azure functions host via CLI. For the workaround to debug locally, you would just run it manually instead of F5 from the Visual Studio.

@andreujuanc

This comment has been minimized.

andreujuanc commented Apr 3, 2018

Azure function guys have a little mess here :D and looks like tools and sdk are not fully in sync.

So, the thing is you got a dependency on some dll: Microsoft.AspNetCore.Mvc.Abstractions, Version=2.0.2.0 But the actual host that runs the function is not in your project, but in here: C:\Users\<user>\AppData\Roaming\npm\node_modules\azure-functions-core-tools\bin , and there you MUST have the same dll versions as in your projects, otherwise you might get that kind of errors.

Also, Im not sure about this, BUT, on those last steps that @pragnagopa indicated, when doing:

cd to Fucntion App folder with .csproj

It wont work. To run the host you need:

  1. Build the project
  2. go to <.csproj folder>\bin\Debug\netstandard2.0\bin
  3. and then start in that folder the host manually: func host start

if you run the host where the csproj is , you will get a message saying

No job functions found. Try making your job classes and methods public.

Hope this helped you understand the issue and debug it in the future.

@Mike-EEE

This comment has been minimized.

Mike-EEE commented Apr 3, 2018

Alright @pragnagopa now I am even more confused. 😆 When you say "debug locally"... that's what I am doing when I hit F5. So are you saying that we no longer F5 now from Visual Studio and do func start host from the directory the csproj is instead? FWIW, I did try doing this but got the following message:

No job functions found. Try making your job classes and methods public. If you're using binding extensions (e.g. ServiceBus, Timers, etc.) make sure you've called the registration method for the extension(s) in your startup code (e.g. config.UseServiceBus(), config.UseTimers(), etc.).

@Mike-EEE

This comment has been minimized.

Mike-EEE commented Apr 3, 2018

LOL @andreujuanc you just cleared it up for me. 😄 Thank you!

@andreujuanc

This comment has been minimized.

andreujuanc commented Apr 3, 2018

And @Mike-EEE BTW, after running "manually" from terminal using func host start. You are no really debugging anything.

To actually debug the project, you need to attact the debugger to the func.exe process.

Once you get func host start running, and terminal shows everything is fine, got o VS and Menu Debug > Attach to process > Filter processes > Write func.exe, select it and click attach.

I know it's a pain, but it works and you will have a full VS experience.

@Mike-EEE

This comment has been minimized.

Mike-EEE commented Apr 3, 2018

BTW... can't we just copy the contents of C:\Users\<user>\AppData\Roaming\npm\node_modules\azure-functions-core-tools\bin into C:\Users\<user>\AppData\Local\Azure.Functions.V2.Cli\2.0.1-beta.22? Making backups before doing so, of course. 😛

@Mike-EEE

This comment has been minimized.

Mike-EEE commented Apr 3, 2018

Right @andreujuanc that's sort of the line I was drawing. Thank you for that. 👍

@ahmelsayed

This comment has been minimized.

ahmelsayed commented Apr 3, 2018

there seem to be a bit of confusion on this issue regarding where the cli is installed and what VS does.

Let me try to explain how everything works:

The CLI (azure-functions-core-tools) can be installed through multiple distribution channels. Those channels include:

  • npm
  • apt-get
  • yum
  • homebrew
  • Chocolaty (soon)
  • Visual Studio

Each package manager installs it in a different location with the end goal of having func on your path (except for Visual Studio). The idea is that you can install it in which ever manner that you are most familiar with or whatever is feasible for you depending on your platform.

VS puts the cli under %UserProfile%\AppData\Local\Azure.Functions.Cli for V1 and %UserProfile%\AppData\Local\Azure.Functions.V2.Cli for v2.

%UserProfile% being usually C:\Users\<userName>

Installing the cli from any of the package managers (only npm for Windows currently but soon Chocolaty and maybe an msi installer) won't change the version VS is using.

VS, like other tools, has a feed that it grabs the CLI from, that way when we update the CLI, we just need to update the feed that VS consumes and it should get the most up-to-date version of the cli.

Unfortunately that is only implemented for V1, and not yet V2. So whenever we release an update for v2 we need VS to also release an update.

At this moment the released CLI, SDK, and all nuget packages should be in sync. The only component that's still pending an update is the VS VSIX that includes the latest v2 cli. We are working with VS to improve this process to not go out of sync like this again

@andreujuanc

This comment has been minimized.

andreujuanc commented Apr 3, 2018

@ahmelsayed Exactly. That's why we are doing manual start.

Also, if I copypasta the npm to Azure.Functions.V2.Cli folder, would that count as an update?

UPDATE: Does not work xD

I need to update 2.0.1-beta.22 to the latest. which is 25 IIRC. D:

@ahmelsayed

This comment has been minimized.

ahmelsayed commented Apr 3, 2018

You can also grab the zip from here https://github.com/Azure/azure-functions-core-tools/releases

VS uses the -no-runtime builds. They are the only signed builds currently

@andreujuanc

This comment has been minimized.

andreujuanc commented Apr 3, 2018

I found it few minutes ago, got some errors while executing. Posted an issue/question there: Azure/azure-functions-core-tools#422 anyway.

Thanks for that info

@ahmelsayed

This comment has been minimized.

ahmelsayed commented Apr 3, 2018

sorry I missed that notification. I replied there.

@andreujuanc

This comment has been minimized.

andreujuanc commented Apr 3, 2018

It was my fault, i posted without refreshing the page :)

@Mike-EEE

This comment has been minimized.

Mike-EEE commented Apr 4, 2018

OK! To fix this problem, do the following (note: works on my machine):

  1. Unzip Azure.Functions.Cli.no-runtime.2.0.1-beta.25.zip to C:\Users\<user>\AppData\Local\Azure.Functions.V2.Cli\2.0.1-beta.25
  2. Set the argument to launch from the new func.dll as described here, but with this setting:
    %AppData%\..\Local\Azure.Functions.V2.Cli\2.0.1-beta.22\func.dll host start --pause-on-error
  3. You will get yet more assembly reference errors (COMEONMAN! 😛) like such: System.Private.CoreLib: Could not load file or assembly 'Microsoft.AspNetCore.Http.Abstractions, Version=2.0.2.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. Could not find or load a specific file. (Exception from HRESULT: 0x80131621). System.Private.CoreLib: Could not load file or assembly 'Microsoft.AspNetCore.Http.Abstractions, Version=2.0.2.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'
  4. Copy files as described here for:
    Microsoft.AspNetCore.Http.Abstractions
    Microsoft.AspNetCore.Http.Features
  5. Try hitting F5.
  6. Sacrifice chicken.
  7. Cross your fingers, and...
  8. WHALAH YOU NOW HAVE A WORKING ATTACHED SERVER WITH ALL THE LATEST WORKING BITS!!!
@MV10

This comment has been minimized.

MV10 commented Apr 4, 2018

Edit -- Oops, didn't read far enough back, everyone is already fetching via npm here.

@andreujuanc

This comment has been minimized.

andreujuanc commented Apr 4, 2018

Replacing the zip file in program files does not work. Sadly.

But @Mike-EEE workaround works. just instead of doing anything weird, like the "chicken" part, you can just point the arguments to 2.0.1-beta.25 directly. Obviously it wont exists , and just need to extract the no-runtime as @ahmelsayed described.

At least we have a workaround for now!

@MV10 MV10 referenced this issue Apr 4, 2018

Closed

Easy install of the functions core tools #368

5 of 5 tasks complete
@Mike-EEE

This comment has been minimized.

Mike-EEE commented Apr 6, 2018

Looks like a new Azure Functions Tools VSIX was deployed yesterday/today and everything works again. 👍 From my perspective this issue is resolved and can be closed. Nice work, team!

@soninaren soninaren closed this Apr 6, 2018

@stevenlivz

This comment has been minimized.

stevenlivz commented May 1, 2018

On VS Mac alpha latest, the instructions by @andreujuanc at #745 (comment) are the only thing that works. Specifically need to run the func host start from within the bin folder itself.

@jefflafay

This comment has been minimized.

jefflafay commented Aug 21, 2018

We've been developing azure functions for months (functions 1.x), everything going well with an exception of the cosmos document feed processor hosing the lease collection and not listening at times.

I am trying to upgrade one of the function apps to 2.0 to hopefully get some bug fixes with the document feed and cosmos document change trigger. Also some fixes for Event Grid triggers since we're using that heavily for our serverless infrastructure. Except, it forces us to use .net standard instead of framework and now I can't use other .net class libraries in my solution that I've built up so I have to do a lot from scratch all over again for this one function app.

What really sucks is that hitting run from VS worked just fine to debug locally. But I'm running into this issue and I can't do that. I tried debugging remotely and that is unreliable. Sometimes it will enable the breakpoints, sometimes it will say symbols not loaded for the break points, sometimes it can't make the initial connection to the function app and sometimes everything looks good but breakpoints won't stop the app running so I can do the debugging I need to do.

The whole azure function, cosmos db change feed, event grid experience has been very disappointing. If my employer didn't have a bizspark account, I would have suggested that we just use Amazon's platform instead. Documentation is very much lacking for what we've utilized and it's been a pain finding the right combination of dependency versions just to get things working correctly.

This has to be improved; we developers cannot manage to build software and systems with this sort of poor experience and low quality tools/platform.

@davidrevoledo

This comment has been minimized.

davidrevoledo commented Oct 26, 2018

@Mike-EEE what is the solution ? I've download the npm tools today and it is still not working for me, I've expending like an entire day trying to debug locally v2 functions.

@soninaren

This comment has been minimized.

soninaren commented Oct 26, 2018

@davidrevoledo : Try the following steps

Steps:

  1. Open Visual Studio
  2. Go to Tools -> Extensions and Updates -> Updates -> Azure Functions and Web Jobs Tools
  3. Make sure the Azure Functions and Web Jobs Tools version is 15.10.2046.
  4. Close all instances of VS
  5. Open %localappdata%AzureFunctionsTools
  6. Rename %localappdata%\AzureFunctionsTools to AzureFunctionsTools_bak
  7. Rename %localappdata%\.templateengine to templateengine_bak
  8. Open VS, make sure you have good network connection, since this will be a sizeable download.
  9. Go to File -> New -> Project -> Azure Functions -> Click OK
  10. You should see the New Project dialog box

image
11. Wait for the update to complete

@PabloFerroDev

This comment has been minimized.

PabloFerroDev commented Oct 26, 2018

It's working for new projects, however it's not working for an existing one. We have a [QueueTrigger] that is failing loading "function.json". The file itself exists not in the "bin" folder, but in the folder with the function name instead.

@davidrevoledo

This comment has been minimized.

davidrevoledo commented Oct 26, 2018

@soninaren @PabloFerroDev we're together, your steps worked for a new azure function but for storage account queue trigger it is not... : (

@soninaren

This comment has been minimized.

soninaren commented Oct 26, 2018

@davidrevoledo , @PabloFerroDev
You need to update the Microsoft.NET.Sdk.Functions package to version 1.0.23 and Install Microsoft.Azure.WebJobs.Extensions.Storage version 3.0.0.

@davidrevoledo

This comment has been minimized.

davidrevoledo commented Oct 26, 2018

@PabloFerroDev could you check that ?

@davidrevoledo

This comment has been minimized.

davidrevoledo commented Oct 26, 2018

@soninaren unfortunately this is not working, we had the 1.0.24 and we tried with that also coming back to .23 and the same error : We have a [QueueTrigger] that is failing loading "function.json". is not getting the function.json,

For information if we remove the Queue Trigger everthing work well with time trigger for instance but we have to remove the Microsoft.Azure.WebJobs.Extensions.Storage which convert in useless the function.

What other thing we can try ? It's becoming a quite paintfull (Not your fault of course)

@soninaren

This comment has been minimized.

soninaren commented Oct 26, 2018

@davidrevoledo 1.0.24 does not exist.
https://www.nuget.org/packages/microsoft.net.sdk.functions/

Can you share your csproj file contents?

I don't know what you mean by

if we remove the Queue Trigger everthing work well with time trigger for instance but we have to remove the Microsoft.Azure.WebJobs.Extensions.Storage which convert in useless the function.

Microsoft.Azure.WebJobs.Extensions.Storage contains QueueTrigger property. Also i am assuming you are using Functions v2.

@davidrevoledo

This comment has been minimized.

davidrevoledo commented Oct 26, 2018

@soninaren so sorry my bad :( ,
I meant Microsoft.Azure.WebJobs.Extensions.Storage from 3.0.1 to 3.0.0
yes of course. Thanks for you help BTW ! 💯 🥇

  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
    <AzureFunctionsVersion>v2</AzureFunctionsVersion>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Inyector" Version="1.2.0" />
    <PackageReference Include="Inyector-AspNetCore" Version="1.2.0" />
    <PackageReference Include="MediatR" Version="5.1.0" />
    <PackageReference Include="MediatR.Extensions.Microsoft.DependencyInjection" Version="5.1.0" />
    <PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Storage" Version="3.0.0" />
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.23" />
    <PackageReference Include="Mindscape.Raygun4Net.NetCore" Version="6.0.1" />
  </ItemGroup>
  <ItemGroup>
    <ProjectReference Include="..\BuildingBlocks\Loggin\Loggin.Core\Loggin.Core.csproj" />
  </ItemGroup>
  <ItemGroup>
    <None Update="host.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Update="local.settings.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <CopyToPublishDirectory>Never</CopyToPublishDirectory>
    </None>
  </ItemGroup>
</Project> ```
@davidrevoledo

This comment has been minimized.

davidrevoledo commented Oct 26, 2018

@soninaren I'm getting the error here ->

TryReadFunctionConfig in Utility.

System.IO.FileNotFoundException: 'Could not find file 'C:\Users\Deivit\source\repos\...\...\bin\Debug\netstandard2.0\bin\function.json'.'

image

@soninaren

This comment has been minimized.

soninaren commented Oct 26, 2018

Function.json is not supposed to be directly inside of the bin folder. I think the issue you are facing is not related to this GitHub issue.

The expected folder structure is as follows.
netstandard2.0\functionName\function.json

Let me try and create a simple project based on the dependencies from the csproj file you shared.

@soninaren

This comment has been minimized.

soninaren commented Oct 26, 2018

Created an app with the dependencies from your csproj + queue triggered function. Not sure what is going on with your app.
https://github.com/soninaren/TestApp

P.S. there is another package MediatR.Extensions.Microsoft.DependencyInjectionFixed.

@davidrevoledo

This comment has been minimized.

davidrevoledo commented Oct 27, 2018

@soninaren very weird, we tried re install the CLI in our both machines will try that thanks !

@davidrevoledo

This comment has been minimized.

davidrevoledo commented Oct 27, 2018

@soninaren Same error in both our machines, I thought It was an our error as in your pc it is working. But I tried in an azure virtual machine w/VS installing Azure CLI tools and same error 👎.

I've returned back to V1 and everything is working well, I don't know what other thing I can do (I've followed the instructions and same error) Will come back to V2 when everything will be more smoothly and we don't have to fight against the platform. 👎

Really thanks for your help anyway very much appreciated 💯 .

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment