Stack Exchange Network

Stack Exchange network consists of 183 Q&A communities including Stack Overflow , the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

MSB4018: The "SqlBuildTask" task failed unexpectedly ==> System.OutOfMemoryException

Sometimes, rebuilding my solution I get following error. Solution is huge, 270+ projects and I have no idea how to get rid of this error. It happens sometimes, most of the times solution builds correctly. I have 32GB RAM, so it is not a problem, I have also a ReSharper, a friend at work don't have it, and have never experienced the error, so maybe there is a problem. Anyway, if anybody have idea how to repair it, I would be very glad to hear it ;)

C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\Microsoft\VisualStudio\v15.0\SSDT\Microsoft.Data.Tools.Schema.SqlTasks.targets(559,5): Error: MSB4018: The "SqlBuildTask" task failed unexpectedly. 31>Microsoft.Data.Tools.Schema.Sql.Build.BuildFailedException: Exception of type 'System.OutOfMemoryException' was thrown. ---> System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.

  • visual-studio-2017
  • memory-error

kubwosz's user avatar

  • (x86) looks like you are using a 32bit process which would result in a limit of 4GB of memory for the process (and the process requesting more than that). Double check using task manager that the process is running in 64bit mode. –  Gizmo Jan 14, 2019 at 14:28
  • @Gizmo - Visual Studio being a 32-bit process is not the cause of this problem. –  Ramhound Jan 15, 2019 at 12:13

This seems like a known problem reported in Unbounded SQLite instances/connections contributing to OOM failures #22650 .

The problem was apparently solved in Visual Studio 2017 version 15.5, and the fix may have been back-ported to 15.4.

Updating Visual Studio 2017 to the latest version should solve the problem (if it is indeed the same).

Since that didn't solve the problem, it's worthwhile noting that the OutOfMemoryException error does not mean lack of memory, but rather the impossibility of allocating memory. I will explain below why these are not the same.

As Visual Studio is a 32-bit program, its memory space is limited to 4 GB. From this, it can "only" use about 2 GB for its data, the rest used by Windows software and for programs. Physical memory is allocated virtual addresses in this space, so that some addresses are already allocated and some are not. There is no garbage collection mechanism possible, so that an address, once allocated, stays allocated.

Imagine, for example that from the 2 GB that are available, 100 MB are allocated, and one wants to allocate an additional 1 GB. Logically, the available memory is far more than enough. However, if the 100 MB are allocated in the middle of the 2 GB space, it is no longer possible to allocate 1 GB of contiguous memory. In this case, the OutOfMemoryException condition will be raised, although it looks flatly impossible.

This case can arise when memory is allocated and freed in such a way that allocated memory fragments are scattered through the available address space and only leave "holes" that are not enough for a large allocation.

Therefore, there are only two possibilities:

A bug in Visual Studio, as for example when attempting to increase the length of an instance of the StringBuilder class beyond what is specified by its current MaxCapacity property, will also cause the OutOfMemoryException condition.

Too many allocations are done, so that, even freed, the memory is too fragmented.

Your case seems to better fit the second case, but your options for a solution here are pretty limited.

A 64-bit version of Visual Studio would solve the problem by enlarging the address space, but that is not in the Visual Studio Roadmap .

Your other option is to reduce memory allocation as much as possible. You could reduce the number of add-ons of Visual Studio or try to break this enormous VS solution into smaller ones. Or you could close and restart Visual Studio, since some memory allocations are done in parallel by Visual Studio threads, so there is a random element involved.

harrymc's user avatar

  • Unfortunately, I have newest version. I downloaded all new VS about month ago, and even after update that didn't help. Some coworkes have same problem as well. –  kubwosz Jan 17, 2019 at 21:07
  • I have added to my answer. –  harrymc Jan 18, 2019 at 9:48

This site is temporarily in read-only mode and not accepting new answers.

Not the answer you're looking for browse other questions tagged sql-server visual-studio-2017 memory-error ..

  • The Overflow Blog
  • Who owns this tool? You need a software component catalog
  • Down the rabbit hole in the Stack Exchange network
  • Featured on Meta
  • Upcoming privacy updates: removal of the Activity data section and Google...
  • Changing how community leadership works on Stack Exchange: a proposal and...

Hot Network Questions

  • Horror short story set on Everest, where climbers left behind are eaten by a creature masquerading as a climber
  • Newbie: How to identify a chip on a board, what is the best strategy?
  • \phantom not giving correct space?
  • Understanding the joke, "Make an 'ell, I say" (from The Crux)
  • Can an Eidetic Spellcaster benefit from the Geometer feature that allows one page per spell in the spellbook?
  • Swap letter cases
  • Scientific Calculator
  • What is the proof of consistency of anterior reflection?
  • Could the bassist and the rhythm guitarist be the same person?
  • Is there global law that governs Denaturalization to stateless status for children?
  • What's the reason to live in this life?
  • Abbreviation I haven’t seen before
  • Roots of quartic equation - given product of two roots, find missing coefficient
  • Getting started for executing retro emulator-newbie
  • Can you cast a Wall of Force into water?
  • Visualizing the reverse pyramid in a good way
  • Why deplane all passengers and not the troublemaker?
  • Book series with parallel earths and a secret governmental agency
  • What is the definition of 909/808/707/etc. percussion?
  • Switch and wildcard option in WN
  • As a private tutor, is it ethical to recommend the student take more classes?
  • Mellin-Barnes integral representation of the exponential function with a non-real argument
  • Why would the triangles join up to a rhombus?
  • Why don't we just unshift the IR photos from Webb?

sql build task failed unexpectedly

This browser is no longer supported.

Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.

Diagnose MSBuild task failures

  • 7 contributors

MSB6006 is emitted when a ToolTask –derived class runs a tool process that returns a nonzero exit code if the task did not log a more specific error.

Identify the failing task

When you encounter a task error, the first step is to identify the task that is failing.

The text of the error specifies the tool name (either a friendly name provided by the task's implementation of ToolName or the name of the executable) and the numeric exit code. For example, in error MSB6006: "custom tool" exited with code 1. the tool name is custom tool and the exit code is 1 .

To find the failed MSBuild task:

In the command-line builds : If the build was configured to include a summary (the default), the summary will look like this:

This result indicates that the error occurred in a task defined on line 19 of the file S:\MSB6006_demo\MSB6006_demo.csproj , in a target named InvokeToolTask , in the project S:\MSB6006_demo\MSB6006_demo.csproj .

In the Visual Studio UI : The same information is available in the Visual Studio error list in the columns Project , File , and Line .

Find more failure information

Error MSB6006 is emitted when the task did not log a specific error. The failure to log an error is often because the task is not configured to understand the error format emitted by the tool it calls.

Well-behaved tools generally emit some contextual or error information to their standard output or error stream, and tasks capture and log this information by default. Look in the log entries before the error occurred for additional information. Rerunning the build with a higher log level may be required to preserve this information. Hopefully, the additional context or errors identified in logging reveal the root cause of the problem. If not, you may have to narrow down the potential causes by examining the properties and items that are inputs to the failing task.

MSBuild recognizes a specific diagnostic output format. The details of this format are documented at MSBuild and Visual Studio format for diagnostic messages .

Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see: https://aka.ms/ContentUserFeedback .

Submit and view feedback for

Additional resources

Donovan Brown

Technology Blog

The "SqlBuildTask" task failed unexpectedly. System.MethodAccessException

I get the The "SqlBuildTask" task failed unexpectedly. System.MethodAccessException error when I try and build a solution that as a SSDT project in it.

Reinstall the latest version SSDT from here http://go.microsoft.com/fwlink/?LinkID=393521 .

Explanation :

I recently built a 2013 Update 4 build machine and none of my projects that included SSDT projects would build.  It turned out to be old target files for MSBuild.  Not sure how that is possible given this was a clean machine and a new install of Visual Studio.  Nevertheless, reinstalling the SSDT bits did the trick.

Related posts

  • The "SqlBuildTask" task failed unexpectedly. System.MethodAccessException Problem:I get the The "SqlBuildTask" task failed unexpectedly. System.MethodAccessException error wh
  • Writing my first Node.js based VSTS Task In this post I am going to show you how to write your first Node.js based Visual Studio Team Service...
  • Test VSTS build tasks written in PowerShell with PowerShell Tools for Visual Studio 2015 Test VSTS build tasks written in PowerShell with PowerShell Tools for Visual Studio 2015

Add comment

Cancel reply to comment

Type the 3rd number 1 8 7 2 The captcha value you provided is incorrect.

Search code, repositories, users, issues, pull requests...

Provide feedback.

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly.

To see all available qualifiers, see our documentation .

  • Notifications

Fix: SqlDeploy Task Fails with NullReferenceException at ExtractPassword

Date Published: 10 March 2010

Fix: SqlDeploy Task Fails with NullReferenceException at ExtractPassword

Still working on getting a TeamCity build working ( see my last post ). Latest exception is:

C:Program FilesMSBuildMicrosoftVisualStudiov9.0TeamDataMicrosoft.Data.Schema.SqlTasks.targets(120, 5): error MSB4018: The "SqlDeployTask" task failed unexpectedly. System.NullReferenceException: Object reference not set to an instance of an object. at Microsoft.Data.Schema.Common.ConnectionStringPersistence.ExtractPassword(String partialConnection, String dbProvider) at Microsoft.Data.Schema.Common.ConnectionStringPersistence.RetrieveFullConnection(String partialConnection, String provider, Boolean presentUI, String password) at Microsoft.Data.Schema.Sql.Build.SqlDeployment.ConfigureConnectionString(String connectionString, String databaseName) at Microsoft.Data.Schema.Sql.Build.SqlDeployment.OnBuildConnectionString(String partialConnectionString, String databaseName) at Microsoft.Data.Schema.Build.Deployment.FinishInitialize(String targetConnectionString) at Microsoft.Data.Schema.Build.Deployment.Initialize(FileInfo sourceDbSchemaFile, ErrorManager errors, String targetConnectionString) at Microsoft.Data.Schema.Build.DeploymentConstructor.ConstructServiceImplementation() at Microsoft.Data.Schema.Extensibility.ServiceConstructor`1.ConstructService() at Microsoft.Data.Schema.Tasks.DBDeployTask.Execute() at Microsoft.Build.BuildEngine.TaskEngine.ExecuteInstantiatedTask(EngineProxy engineProxy, ItemBucket bucket, TaskExecutionMode howToExecuteTask, ITask task, Boolean& task Result)

This time searching yielded some good stuff, including this thread that talks about how to resolve this via permissions . The short answer is that the account that your build server runs under needs to have the necessary permissions in SQL Server. You’ll need to create a Login and then ensure at least the minimum rights are configured as described here:

Required Permissions in Database Edition

Alternately, you can just make your build server account an admin on the database (which is probably running on the same machine anyway) and at that point it should be able to do whatever it needs to.

If you’re certain the account has the necessary permissions, but you’re still getting the error, the problem may be that the account has never logged into the build server. In this case, there won’t be any entry in the HKCU hive in the registry, which the system is checking for permissions (see this thread ). The solution in this case is quite simple: log into the machine (once is enough) with the build server account. Then, open Visual Studio (thanks Brendan for the answer in this thread ).

  • Make sure the build service account has the necessary database permissions
  • Make sure the account has logged into the server so it has the necessary registry hive info
  • Make sure the account has run Visual Studio at least once so its settings are established

In my case I went through all 3 of these steps before I resolved the problem.

Tags - Browse all tags

Category - browse all categories.

  • Uncategorized

Steve Smith

About Ardalis

Software architect.

Steve is an experienced software architect and trainer, focusing on code quality and Domain-Driven Design with .NET.

🎓 ONLINE TRAINING

  • Refactoring to SOLID C# Code NEW!
  • ASP.NET Core 6 Web API: Best Practices
  • Working with C# Generics: Best Practices
  • Domain-Driven Design Fundamentals
  • Refactoring for C# Devs
  • Kanban: Getting Started
  • SOLID Principles for C# Devs
  • Design Patterns Overview

📋 CATEGORIES

  • Career Advice ( 2 )
  • Iraq ( 158 )
  • Personal ( 37 )
  • Productivity ( 166 )
  • Security ( 7 )
  • Software Development ( 897 )
  • Uncategorized ( 489 )

📘 FREE ARCHITECTURE EBOOK

book

Get the Book!

🖊️ recent articles.

  • An Active Local NuGet Server
  • Introducing Modular Monoliths: The Goldilocks Architecture
  • Hello, MongoDB - Getting Started with Mongo and dotnet 8
  • Hello, Redis - Getting Started with Redis and dotnet 8
  • Solved! Visual Studio .http File Not Sending Authorization Header

🐦 RECENT TWEETS

The art of simplicity

Search this blog, error msb4018: the "sqlbuildtask" task failed unexpectedly. microsoft.isam.esent.interop.esentversionstoreoutofmemoryexception:.

A customer contacted me about a problem on their build servers. The build for one of their applications failed sometimes with the following error message:

C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\SSDT\Microsoft.Data.Tools.Schema.SqlTasks.targets(550,5): Error MSB4018: The "SqlBuildTask" task failed unexpectedly. Microsoft.Isam.Esent.Interop.EsentVersionStoreOutOfMemoryException: Version store out of memory (cleanup already attempted) at Microsoft.Isam.Esent.Interop.Api.Check(Int32 err)

The solution contained a SQL Server Database project, that resulted in the error above. When we removed the database project from the build configuration, the error disappeared.

Further investigation brought us to a final solution; an update of the SQL Server Data Tools on the Build server solved the problem.

Popular posts from this blog

Devtoys–a swiss army knife for developers, help i accidently enabled hsts–on localhost, azure devops/ github emoji.

IMAGES

  1. MSB4018: The "SqlBuildTask" task failed unexpectedly ==> System

    sql build task failed unexpectedly

  2. Resolve My SQL Error 1067: The Process Terminated Unexpectedly Easily

    sql build task failed unexpectedly

  3. Cannot find SQLite.UWP.2015 and LinkAssemblies task failed unexpectedly

    sql build task failed unexpectedly

  4. variables

    sql build task failed unexpectedly

  5. Resolve My SQL Error 1067: The Process Terminated Unexpectedly Easily

    sql build task failed unexpectedly

  6. Wait on the Database Engine Recovery Handle Failed SQL Server Installa

    sql build task failed unexpectedly

VIDEO

  1. You Can't Run from SQL

  2. How to Fix SQL Server Restore Failed Database in Use

  3. Sending an e-mail with SQL Query Results from a SmartConnect SQL Task

  4. SQL Working Session Task 3: Refer description section to know more about this requirement

  5. HOW TO FIX, MSSQLSERVER DATABASE ATTACH ERROR || LOG FILE NO FOUND || DATABASE ACCESS DENIED ERROR

  6. SQL Working Session Task 4: Refer description section to know more about this requirement

COMMENTS

  1. "The "SqlBuildTask" task failed unexpectedly..." exception in SSDT

    One of them is returning the exception "The "SqlBuildTask" task failed unexpectedly. Microsoft.Data.Tools.Schema.Sql.Build.BuildFailedException: An entry with the same key already exists.". I went into the Microsoft.Data.Tools.Schema.SqlTasks.targets and took a look at the (posting it below)

  2. sql server

    1 Answer Sorted by: 0 This seems like a known problem reported in Unbounded SQLite instances/connections contributing to OOM failures #22650. The problem was apparently solved in Visual Studio 2017 version 15.5, and the fix may have been back-ported to 15.4.

  3. MSB4018

    10/20/2021 3 contributors Feedback This error is emitted when a task fails with an unhandled exception. This is generally a sign of a bug in the task. Error MSB4018 may be caused when running a task in an environment that it was not prepared for, for instance when a task has an x86 dependency but is running in a 64-bit MSBuild environment.

  4. Error MSB4018: The "SqlBuildTask" task failed unexpectedly

    Wednesday, December 10, 2008 4:19 PM Answers 0 Sign in to vote You cannot do this, this way. The only supported way is to install the GDR bits, we do not support XCOPY or manual installation of just the MSBuild related pieces, we are adding this for the next release as part of the Team Build support. -GertD

  5. Diagnose MSBuild task failures

    To find the failed MSBuild task: In the command-line builds : If the build was configured to include a summary (the default), the summary will look like this: Build FAILED.

  6. MSB4018: The "SqlBuildTask" task failed unexpectedly ...

    MSB4018: The "SqlBuildTask" task failed unexpectedly ==> System.OutOfMemoryException - YouTube MSB4018: The "SqlBuildTask" task failed unexpectedly ==>...

  7. Error MSB4018: The "SqlBuildTask" task failed unexpectedly

    Error MSB4018: The "SqlBuildTask" task failed unexpectedly Archived Forums Visual Studio > Visual Studio Database Development Tools (Formerly "Database Edition Forum") Question 0 Sign in to vote I figured it was time to try out SQL Server Data Tools in VS 2010.

  8. Donovan Brown

    Solution: Reinstall the latest version SSDT from here http://go.microsoft.com/fwlink/?LinkID=393521. Explanation: I recently built a 2013 Update 4 build machine and none of my projects that included SSDT projects would build. It turned out to be old target files for MSBuild.

  9. MSB4018: The task failed unexpectedly

    \n. To resolve this, ensure that the task expresses a dependency on the runtime environment it requires in the task's UsingTask element. \n ","renderedFileInfo":null ...

  10. Error: MSB4018: The "SqlBuildTask" task failed unexpectedly

    Hello, I got filenotfoundexception while building my database project. i didn't change any file location though. How can i solve this? (Sorry if i post in wrong category). -Janak · Hello Janaks, I suspect the problem is more related to SSDT forum instead of MSBuild forum here. Anyway, please see some related topics below: https://michaelmairegger ...

  11. MSB4018: The "SqlBuildTask" task failed unexpectedly

    MSB4018: The "SqlBuildTask" task failed unexpectedly. Archived Forums 361-380 > SQL Server Data Tools. SQL Server Data Tools ...

  12. Fix: SqlDeploy Task Fails with NullReferenceException at ...

    Summary. Make sure the build service account has the necessary database permissions. Make sure the account has logged into the server so it has the necessary registry hive info. Make sure the account has run Visual Studio at least once so its settings are established. In my case I went through all 3 of these steps before I resolved the problem.

  13. SQL Server database project: Error MSB4018 "SqlDeployTask"

    1. Unloaded the project, deleted the *.dbmdl files, and reloaded project. 2. Switch project properties to just create a deploy script 3. Switch back to creating a deploy script and deploy 4. Cleaned the project

  14. Error MSB4018: The "SqlBuildTask" task failed unexpectedly ...

    Here is the current list: Converters JSON <> YAML Timestamp Number Base Cron Parser Encoders / Decoders HTML URL Base64 Text & Image GZip JWT Decoder Formatters JSON SQL XML Generators Hash (MD5, SHA1, SHA256, SHA512) UUID 1 and 4 Lorem Ipsum Checksum Text Escape / Unescape Inspector & Case Converter Regex Tester Text Comparer XML Validator ...

  15. error MSB4018: The "SqlBuildTask" task failed unexpectedly

    error MSB4018: The "SqlBuildTask" task failed unexpectedly. I updated latest SSDT tools in my local machine and TFS server. Even then I am getting same error . Please help me Thursday, March 12, 2015 7:22 PM Answers 0 Sign in to vote Hi Narasimha, Visual Studio 2013 is not support SSDT project now.

  16. Using MSBuild to build SSDT projects with VS2017 fails

    3 I am trying to set up continuous integration of .sqlproj SSDT projects on our windows server 2016 server. In order to do this I have installed VS2017 and SSDT tools onto the server to get the required tools. I have also installed MS build tools 2017.