Recusiwe
Recusiwe

Reputation: 1140

Error when trying to publish an azure function from Visual Studio

I get the following error message when I try to publish my function using Visual Studio, any idea how to fix this?

System.AggregateException: One or more errors occurred. ---> System.Exception: Publish has encountered an error. We were unable to determine the cause of the error. Check the output log for more details. --- End of inner exception stack trace --- at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions) at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken) at Microsoft.Publish.Framework.Model.DefaultPublishSteps.<>c__DisplayClass26_0.b__2() at System.Threading.Tasks.Task`1.InnerInvoke() at System.Threading.Tasks.Task.Execute() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Publish.Framework.Model.DefaultPublishSteps.d__23.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Publish.Framework.ViewModel.ProfileSelectorViewModel.d__213.MoveNext() ---> (Inner Exception #0) System.Exception: Publish has encountered an error. We were unable to determine the cause of the error. Check the output log for more details. <---

System.Exception: Publish has encountered an error. We were unable to determine the cause of the error. Check the output log for more details.

===================

Upvotes: 35

Views: 28534

Answers (23)

geezer
geezer

Reputation: 11

in case none of the above answers work, try to relogin your microsoft account credentials

Upvotes: 1

Kelum
Kelum

Reputation: 1775

mine, problem was I created function app name as kelum-func-app-test initially. then I deleted it and created as kelumfuncapptest it works for me :)

Upvotes: 0

Praveen Kumar Thalluri
Praveen Kumar Thalluri

Reputation: 1147

In my case, the link between the Azure Function app and storage was missing.

Make sure that the "AzureWebJobsStorage" app setting is provided for the Azure function app.

https://learn.microsoft.com/en-us/azure/azure-functions/functions-app-settings

Upvotes: 0

JerryM
JerryM

Reputation: 885

I got this error today. Same message anyway. In my case it was that the publish target had changed to an older, no longer existing instance. This value is set in a drop-down list at the top of the publish tab in visual studio. It's just to the left of the Publish button.

Upvotes: 0

Bill
Bill

Reputation: 1477

My reason for this error for me was that I lost my subscriptions to Azure in Visual Studio 2019. In Server Explorer I had to reset my subscriptions and acquire a new token.

Upvotes: 0

zzfima
zzfima

Reputation: 1565

I put attention, when I have got this message, code on Azure updated well. Probably issue with some timeouts, when VS do not receive signal from web.

Upvotes: 0

Fyll
Fyll

Reputation: 1

This bug has wrecked my brain for so long. I have tried everything, publish to new app-services, publish locally, creating new publish profiles, nothing works. For some reason a computer gets bugged for a function and only solution for me has been to swap computer.

But I found a solution. It seems to have to do with ur local visual studio settings and deleting/changing name on your C:\Users{UserName}\AppData\Local\Microsoft\VisualStudio 17.0 or 16.0 and resetting your visual studio settings seems to do the trick to un-bug that computer.

I recommend changing the name of the folder as it contains your visual-studio IDE settings.

Upvotes: 0

Murat Beg
Murat Beg

Reputation: 11

I was having same problem, tried all the above solutions but didn't work. My solution was sign VS into my Azure account. If you are using Cloud Explorer, just check if you're already signed in if not just reenter your credentials.

Upvotes: 1

Rishal Chand
Rishal Chand

Reputation: 41

I had the same issue

I had the same issue

But, there were no failure logs, it said

Web App was published successfully https://xxxxxxxxx/
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
========== Publish: 1 succeeded, 0 failed, 0 skipped ==========

I have Visual Studio 2022, I updated it and had to rebuild the project again, after like 5 or 6 tries and restarts, and it worked.

could be the server was slow or the internet connectivity.

Upvotes: 4

Dwain Browne
Dwain Browne

Reputation: 1090

If you're using Visual Studio 2022

There's a documented bug on github

enter image description here

Solution

1. Navigate to:

C:\Users\{{USER}}\.nuget\packages\microsoft.azure.webjobs.script.extensionsmetadatagenerator\{{LATEST VERSION}}\build

2. Edit File: Microsoft.Azure.WebJobs.Script.ExtensionsMetadataGenerator.targets

3. Inside file search for: _GenerateFunctionsExtensionsMetadataPostPublish

<Target Name="_GenerateFunctionsExtensionsMetadataPostPublish" AfterTargets="Publish"> <GenerateFunctionsExtensionsMetadata SourcePath="$(PublishDir)bin" OutputPath="$(PublishDir)bin"/> </Target>

Changed it to: - Remove "bin" after $(PublishDir)

<Target Name="_GenerateFunctionsExtensionsMetadataPostPublish" AfterTargets="Publish"> <GenerateFunctionsExtensionsMetadata SourcePath="$(PublishDir)" OutputPath="$(PublishDir)"/> </Target>

Upvotes: 3

Terry Lewis
Terry Lewis

Reputation: 51

I deleted the publish profile and then reinstalled it and it worked.

Upvotes: 4

Carlos Araujo
Carlos Araujo

Reputation: 474

I Had Application Insights on the Service Dependencies list with a yellow flag. Since I don't use this tool, I just removed it and it fixed my publishing.

Upvotes: 0

Mayur Sapaliga
Mayur Sapaliga

Reputation: 1

Removing the WEBSITE_RUN_FROM_PACKAGE works for me most of the times. But at times, it does not work.. Here are a few things, I make sure before I publish.

  1. The Azure CLI window should not be open.
  2. Go to File--> Account Settings. Make sure you are signed in.
  3. Use Visual Studio in Administrator mode.
  4. Delete the Publish Profile & recreate.

Upvotes: 0

DawnBlaze
DawnBlaze

Reputation: 1

I installed the latest .NET Core (5.0) and upgraded my project to target .NET Core 5.0. When I was trying to publish my project I encountered this error. I forgot to change the 'Target Framework' to 'net5.0' in the publish window.

Properties: Target Framework

Publish: Target Framework

Upvotes: -1

klenium
klenium

Reputation: 2607

Removing package deploy worked sometimes as @Sajeetharan suggested, but not always.

You should try to stop the host first on the portal. Then publish from VS, that worked me. Finally, restart the host.

Dunno why it now needs manual restarting, probably a Durable Task was running, blocking the automatic restarting.

Upvotes: 2

Joe Park
Joe Park

Reputation: 95

None of the above worked for me. So I just re-downloaded the publish profile and imported it into VS and it worked.

Weird, but just in case none of the above worked for you. May worth try.

Upvotes: 5

Tim Davis
Tim Davis

Reputation: 541

I have found a workaround since none of these things works for me. It's a little strange, so bear with me.

  1. Publish function to azure
  2. Wait for failure enter image description here
  3. Go to Azure Portal / All Resources
  4. Find your failed published function app
  5. Click "Functions".. inside the Function

enter image description here

  1. Click refresh
  2. Publish again.. this time it works.

That's it..

Upvotes: 12

JARMO
JARMO

Reputation: 1

Default timeout is 100 seconds. So publish fail after 100 seconds. I had this same problem in my own code when upload blob and this is how I fix it to 5 minutes. So same code to Visual Studio fix it.

_client.Timeout = TimeSpan.FromMinutes(5);
CancellationTokenSource source = new CancellationTokenSource(TimeSpan.FromMinutes(5));
CancellationToken token = source.Token;
HttpResponseMessage responseMessage = await _client.PostAsync(url, content, token);

Upvotes: 0

vjirovsky
vjirovsky

Reputation: 208

I experienced same strange problem - it was caused by error in my code -

I had #if DEBUG #else #if statement in my code, so debug on my computer worked, but publishing (with Release profile) failed.

Click on Output tab and you should see the real issue.

Upvotes: 5

Recusiwe
Recusiwe

Reputation: 1140

The solution was to update to the newest SDK.

Upvotes: 1

Chris Schaller
Chris Schaller

Reputation: 16554

Without sharing your project on a playform like GitHub, it is really hard for us to offer specific advice,there are so many variables, so many combinations of NuGET packages and references that your project may have that conflict in such a way that will cause this error.

Especially with v2 Functions, I have experienced this issue or similar ones a number of times. One of the biggest factors with Functions is the competing concepts between v1 and v2.

When you use the Visual Studio publish wizard to create the target resource in Azure, it tends to have greater success, if you have been struggling with this for a while I suggest you follow this process, as a proof of concept if nothing else:

This advice works equally well in VS2017 and 2019

  1. Create a new Function Project in visual studio, in the same solution.
    • Replicate the name of your original function
  2. Publish the function to a NEW Azure resource, use the publish wizard to create this resource.
  3. If publishing is successful:
    • Move your original project code across to the new project
    • Pay close attention to the versions of nuget packages that you want to bring across, they and their dependencies will need to be v2 compliant
  4. If publishing is NOT successful
    • Make sure you upgrade your Visual Studio to the latest
    • Make sure your Azure Tools are also upgraded to the latest

As a general rule of thumb, for general success with Azure Functions:

  1. Use v1 for .Net Framework projects, or if ANY of your reference projects or NuGET packages have .Net Fx dependencies. (so .Net 4+... or anything that is not .Net Core.)

    Even when those dependencies target multiple projects, with Functions the deployment tends to fail as it is not able to properly detect the correct platform when evaluating the NuGET dependencies during deployment.

  2. Use v2 ONLY for .Net Core projects, make sure that your references are also only .Net core

Compile and publish your code incrementally, also use AzureDevOps or GitHub or other source code repositories to checkin your code often with Functions. At the early stages of a Functions project we often bring in mutliple refrences and NuGET packages and they seem to work locally but not when we deploy.

  • using a source code repo makes it easy to commit changes before installing new packages and rollback if installing the package results an un-deployable code.
  • It seems messy, but due to NuGet versioning, going back to the state before installing a package it not assimple as uninstalling that package, it may very easily have upgraded other packages, and in this changing Azure environment many package authors have chosen to upgrade their resources between .Net Framework and .Net Core, and not always have they done it well, or sometimes the retain some .Net framework elements that will cause conflicts in Azure Functions.

There are some interesting discussions that may help:

Upvotes: 0

Sajeetharan
Sajeetharan

Reputation: 222582

Can you try this

Remove WEBSITE_RUN_FROM_PACKAGE setting entirely from Azure Functions Application Settings from Azure Portal.

Upvotes: 20

suziki
suziki

Reputation: 14088

This is a Visual Studio timeout issue, which means that your code and some other settings are not the key to the problem. This error occurs because Visual sets a timeout limit on the release. (The file is too large or the internet speed is unstable)

If your deployment project is not too big, you can wait until the network speed is stable before trying to run it. Of course, you can also try other deployment methods to avoid this problem, such as zip deploy.

Upvotes: 9

Related Questions