InvalidOperationException: Cannot dispose the build manager

.NET obfuscator and automated error reporting

InvalidOperationException: Cannot dispose the build manager

Postby Ognyandim » Fri Jan 11, 2013 12:18 pm

I have setup SA Pro on TFS 2012 Build Agent according to these two articles :

The project compiles ( According to the Activity log of the TFS Build Agent) but then the part where SA should come in fails. First I tried the first article and after getting the same error as this one pasted below I tried the original article from Red-Gate.
I made it so but still the same error. I tried several combinations but the error stays the same. The current state of (the end) of my .csproj is :

Code: Select all
<PropertyGroup Condition=\"'$(TfsBuild)' == 'True' and '$(RunSmartAssembly)' == 'True' \">
   <SmartAssemblyConfigurationFileRelativePath Condition=\"'$(SmartAssemblyConfigurationFileRelativePath)' == ''\">$(ProjectName).saproj</SmartAssemblyConfigurationFileRelativePath>
  <UsingTask TaskName=\"SmartAssembly.MSBuild.Tasks.Build\" AssemblyName=\"SmartAssembly.MSBuild.Tasks, Version=, Culture=neutral, PublicKeyToken=7f465a1c156d4d57\" />
  <Target Name=\"AfterBuild\" Condition=\"'$(TfsBuild)' == 'True' and '$(RunSmartAssembly)' == 'True'\">
    <SmartAssembly.MSBuild.Tasks.Build ProjectFile=\"$(SmartAssemblyConfigurationFileRelativePath)\" Input=\"@(MainAssembly)\" OverwriteAssembly=\"True\" />

but there is no difference - still the same error. I have set up SA only for Feature Usage and Error reporting. I have already ran SA Pro through its interface on the Build Agent machine and it works perfectly.

That brings me to the conclusion that I am doing it wrong in the csproj file.

This is the error TFS displays ( web access or VS 2012 - the same) and I can not possibly know what is happening - it is rather vague. I tried to google for this error but the only thing I found was multiple processor building errors - I did not enable any multi processor build. I looked at BuildAgent Activity log but still no clue.

Code: Select all
Unhandled Exception: System.InvalidOperationException: Cannot dispose the build manager because it is not idle.
at Microsoft.Build.Execution.BuildManager.Dispose(Boolean disposing)
at Microsoft.Build.Execution.BuildManager.Dispose()
at Microsoft.Build.CommandLine.MSBuildApp.BuildProject(String projectFile, String[] targets, String toolsVersion, Dictionary`2 globalProperties, ILogger[] loggers, LoggerVerbosity verbosity, DistributedLoggerRecord[] distributedLoggerRecords, Boolean needToValidateProject, String schemaFile, Int32 cpuCount, Boolean enableNodeReuse, TextWriter preprocessWriter, Boolean debugger, Boolean detailedSummary)
at Microsoft.Build.CommandLine.MSBuildApp.Execute(String commandLine)
at Microsoft.Build.CommandLine.MSBuildApp.Main()

Exception Message: MSBuild error 255 has ended this build. You can find more specific information about the cause of this error in above messages. (type BuildProcessTerminateException)

Exception Stack Trace:    at System.Activities.Statements.Throw.Execute(CodeActivityContext context)

   at System.Activities.CodeActivity.InternalExecute(ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager)

   at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation)

Did I mess the csproj? There should be some misconfiguration between TFS Build and SA. Any clue what is going on?

Posts: 10
Joined: Tue Jan 08, 2013 12:31 pm
Location: Sofia, Bulgaria


Postby Ognyandim » Fri Jan 11, 2013 12:56 pm

It was once again a user privileges problem between SQL and Smart Assembly. I have connected SmartAssembly at the TFS Build Agent while running SmartAssembly GUI using Windows Authentication and it connected to SQL successfully. But TFS is running with 'NT AUTHORITY\\NETWORK SERVICE' which does not have sufficient privileges for the SQL! When TFS invokes Smart Assembly it tries to connect to SQL with 'NT AUTHORITY\\NETWORK SERVICE' and not with the windows account I have connected through the standard interface.

How To Solve :

1. In the build definition change the logging verbosity to 'Diagnostics'
2. Run the build.
3. When it fails open the project log. Not the Activity Log of the Build Agent. At the bottom of the log there are these few lines.
Code: Select all
 error : SmartAssembly build failed:
 error : Failed: SmartAssembly.InformationException: Unable to connect to the SQL database:
 error : 'Cannot open database "SmartAssembly" requested by the login. The login failed.
 error : [b]Login failed for user 'NT AUTHORITY\\NETWORK SERVICE'.'[/b]

4. Create SQL user - SmartAssemblyUser, map the user to the SmartAssembly database and grant it db_datawriter privilege. You can use this user with every SA Developer on devs machines - that is good because this user has minimum rights in the SQL server and therefore IMHO will not be a security breach if someone gets this user from the SmartAssembly.settings file.
5. Edit the SmartAssembly.settings which is located in C:\\ProgramData\\Red Gate\\SmartAssembly ( in my case because I installed it the standart way ) the way this article describes
6. Save and start the normal GUI, open the project, click options and see if it is connected. If it is not it will diplay an error.
7. If it ( SA ) is connected to SQL now - run your build again and ENJOY!
Posts: 10
Joined: Tue Jan 08, 2013 12:31 pm
Location: Sofia, Bulgaria

Return to SmartAssembly 6

Who is online

Users browsing this forum: No registered users and 0 guests