In this azure tutorial, we will discuss how to fix the error, Error While Redeploying The Azure Function System.Exception: Publishing failed. This error I got while redeploying an Azure function using the Visual Studio 2019.
Table of Contents
Error While Redeploying The Azure Function System.Exception: Publishing failed
I have created one Azure HTTP triggered function using the Visual Studio 2019. Below is the function that I have created
using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using System.Collections.Generic;
using Microsoft.Azure.Storage.Queue;
using System.Net.Http;
using System.Collections;
using System.Collections.Concurrent;
using System.Net.Http.Formatting;
namespace MyDemoAzureFunction
{
public static class Function1
{
[FunctionName("Function1")]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req,
ILogger log)
{
log.LogInformation("C# HTTP trigger function processed a request.");
string name = req.Query["name"];
string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
dynamic data = JsonConvert.DeserializeObject(requestBody);
name = name ?? data?.name;
return name != null
? (ActionResult)new OkObjectResult($"Hello, {name}")
: new BadRequestObjectResult("Please pass a name on the query string or in the request body");
}
}
}
Initially, I tried to deploy it, It deployed successfully. But then I modified and added a few lines of code in the above function and when I tried redeploying the Azure function, I got the below complete error message
05-07-2020 11:12:30
System.AggregateException: One or more errors occurred. ---> System.Exception: Publishing failed.
--- 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.<IsBuildCompletedSuccessfully>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.<DefaultCorePublishStep>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.<RunPublishTaskAsync>d__176.MoveNext()
---> (Inner Exception #0) System.Exception: Publishing failed.<---

Error While Redeploying The Azure Function System.Exception: Publishing failed [Solved]
To fix the above error, I was trying different ways but none of them were working. So finally what i have followed the below steps to fix the issue.
Step-1: Login to Azure Portal (https://portal.azure.com/)
Step-2: Navigate to the Azure function app that you have deployed earlier and trying to modify the code trying to redeploy the Azure function app. When I have verified the Azure Function App status was the start. Meaning it was running already.

Step-3: Now click on the Stop button to stop the Azure function App. Click on the Yes button for the confirmation on the Stop web app window.

Step-4: Now when i started redeploying the Azure function App, it deployed successfully with out any issue.
You may like following the below articles
- The term ‘Start-ADSyncSyncCycle’ is not recognized error
- The specified module ‘ADSync’ was not loaded because no valid module file was found in any module directory error
Conclusion
In this article, we have discussed the fix for the Error While Redeploying The Azure Function System. Exception: Publishing failed. Hope it will help you to fix your issue !!!