Windows Azure Package creation (or Publish) fails with “Build Failed” message in Visual studio output window

Action

Tried to publish Windows Azure Service using Publish option in Visual Studio
or
Tried to create a service package using Package option in Visual Studio

 

Result

Package creation fails with similar messages to below in Visual Studio output window

Build started: Project: TestApp, Configuration: Release Any CPU ------
TestApp -> C:\Projects\TestApp\TestApp\bin\TestApp.dll
Build started: Project: TestApp.Azure, Configuration: Release Any CPU ------
Publish started: Project: TestApp.Azure, Configuration: Release Any CPU ------
Transformed Web.config using Web.Release.config into obj\Release\TransformWebConfig\transformed\Web.config.
Done building project "TestApp.Azure.ccproj" -- FAILED.

Build FAILED.
========== Build: 2 succeeded or up-to-date, 0 failed, 0 skipped =========
========== Publish: 0 succeeded, 1 failed, 0 skipped ================

Symptoms

  • Issue does not occur for sample, small applications.
  • There is no message box displayed detailing the exception other than the “Build Failed” message in VS output window

 

Cause

In most of the cases, issue seems to be occurring due to the OutOfMemoryException in devenv process. If you were to attach a debugger to devenv process which is building the package and troubleshoot the issue, you would see exception similar to below

Microsoft.Build.Shared.InternalErrorException was unhandled
Message=MSB0001: Internal MSBuild Error: Exception of type 'System.OutOfMemoryException' was thrown.
=============
System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.
at System.IO.MemoryStream.set_Capacity(Int32 value)
at System.IO.MemoryStream.EnsureCapacity(Int32 value)
at System.IO.MemoryStream.Write(Byte[] buffer, Int32 offset, Int32 count)
at MS.Internal.IO.Packaging.PackagingUtilities.CopyStream(Stream sourceStream, Stream targetStream, Int64 bytesToCopy, Int32 bufferSize)
at MS.Internal.IO.Packaging.SparseMemoryStream.WriteToStream(Stream stream)
at MS.Internal.IO.Zip.ZipIOFileItemStream.Save()
at MS.Internal.IO.Zip.ZipIOLocalFileBlock.Save()
at MS.Internal.IO.Zip.ZipIOBlockManager.SaveContainer(Boolean closingFlag)
at MS.Internal.IO.Zip.ZipIOBlockManager.SaveStream(ZipIOLocalFileBlock blockRequestingFlush, Boolean closingFlag)
at MS.Internal.IO.Zip.ZipIOModeEnforcingStream.Dispose(Boolean disposing)
at System.IO.Stream.Close()
at System.IO.Packaging.PackagePart.Close()
at System.IO.Packaging.Package.DoClose(PackagePart p)
at System.IO.Packaging.Package.DoOperationOnEachPart(PartOperation operation)
at System.IO.Packaging.Package.System.IDisposable.Dispose()
at Microsoft.ServiceHosting.Tools.Packaging.PackageCreator.CreateRolePackages(ModelProcessor modelProcessor, PackageManifest applicationManifest, Package applicationPackage)
at Microsoft.ServiceHosting.Tools.Packaging.PackageCreator.CreatePackage(Stream outputStream)
at Microsoft.ServiceHosting.Tools.Packaging.ServiceApplicationPackage.CreateServiceApplicationPackage(String serviceModelFileName, String serviceDescriptionFile, Stream output, IPackageSecurity encrypt, Dictionary`2 namedStreamCollection, String userInfo, EventHandler`1 rolePackagePartAddedHandler)
at Microsoft.ServiceHosting.Tools.MSBuildTasks.CSPack.TryCreatePackage(ServiceDefinitionModel sm)
at Microsoft.ServiceHosting.Tools.MSBuildTasks.CSPack.Execute()
at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask, Boolean& taskResult)
at Microsoft.Build.BackEnd.TaskBuilder.InitializeAndExecuteTask(TaskLoggingContext taskLoggingContext, ItemBucket bucket, TaskHost taskHost, TaskExecutionMode howToExecuteTask, Boolean& taskResult)
at Microsoft.Build.BackEnd.TaskBuilder.ExecuteBucket(TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask, Dictionary`2 lookupHash)
at Microsoft.Build.BackEnd.TaskBuilder.ExecuteTask(TaskExecutionMode mode, Lookup lookup)
at Microsoft.Build.BackEnd.TaskBuilder.ExecuteTask(TargetLoggingContext loggingContext, BuildRequestEntry requestEntry, ITargetBuilderCallback targetBuilderCallback, ProjectTargetInstanceChild taskInstance, TaskExecutionMode mode, Lookup inferLookup, Lookup executeLookup)
at Microsoft.Build.BackEnd.TargetEntry.ProcessBucket(ITaskBuilder taskBuilder, TargetLoggingContext targetLoggingContext, TaskExecutionMode mode, Lookup lookupForInference, Lookup lookupForExecution)
at Microsoft.Build.BackEnd.TargetEntry.ExecuteTarget(ITaskBuilder taskBuilder, BuildRequestEntry requestEntry, ProjectLoggingContext projectLoggingContext)
at Microsoft.Build.BackEnd.TargetBuilder.ProcessTargetStack(ITaskBuilder taskBuilder)
at Microsoft.Build.BackEnd.TargetBuilder.BuildTargets(ProjectLoggingContext loggingContext, BuildRequestEntry entry, IRequestBuilderCallback callback, String[] targetNames, Lookup baseLookup)
at Microsoft.Build.BackEnd.RequestBuilder.BuildProject()
at Microsoft.Build.BackEnd.RequestBuilder.BuildAndReport()
at Microsoft.Build.BackEnd.RequestBuilder.RequestThreadProc()

 

Resolution

  • If you have a 64 bit machine, easiest option to resolve the issue would be by creating a package using 64 bit high-end hardware machine. 64 bit machines will provide more system resources to application compared to 32 bit machines.
  • If you do not have 64 bit machines, you can try stopping as many as services, programs you can and allow Visual Studio to use more memory to resolve the issue. If you are still getting the issue with bare minimum programs/services running on the machine, it is highly unlikely you can resolve the issue using 32 bit machines. I suggest using 64 bit machines.

 

Applies To:

Windows Azure SDK 1.6

 

Hope this helps!

 

Keywords: Windows Azure, Build Failed, Visual Studio, Package, Publish

Comments

  • Anonymous
    June 09, 2013
    What if I am already on a 64-bit machine with 16GB RAM, and I still occasionally get this error when I try to do an Azure publish with SDK 1.8?

  • Anonymous
    June 10, 2013
    Hi bPratik, This issue applies to only SDK 1.6. If you are getting this with SDK 1.8, then it is different issue. Please contact  Azure support(www.windowsazure.com/.../options)  to investigate this further. Thanks, Hari

  • Anonymous
    August 18, 2014
    Clear the output log. It starves the MSBuild process for ram. The log itself can be 55mb+