23
votes

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.

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

12
I'm running into a similar issue at the moment in Visual Studio 2019 - though I'm trying to publish to folder in my case. I'm still trying to track down what is causing this, but I've tried this so far in my case: 1.) Clear NuGet cache, 2.) Remove bin and obj folders 3.) Created a new folder profile Also, what do you see in the output log file? Anything useful? - VirtualValentin
Have you tried to deploy it through Git via Deployment Center - pavle
if any of the suggestions below doesn't work. restart the VS2019 and rebuild, publish. - Emil

12 Answers

15
votes

Can you try this

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

8
votes

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.

3
votes

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.

2
votes

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.

1
votes

The solution was to update to the newest SDK.

0
votes

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:

0
votes

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);
0
votes

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..

0
votes

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.

0
votes

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

0
votes

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.
0
votes

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.