StyleCopTask" task failed unexpectedly Modal dialog

Jun 4, 2010 at 12:34 PM
Edited Jun 4, 2010 at 12:37 PM

Hi! I'm running StyleCop from the msbuild extensions sytlecop task using TFS. We get an exception from StyleCop but since StyleCop tries to show this exception in a modal dialog, I cannot find out what exception...

 The "StyleCopTask" task failed unexpectedly. [MyProject.csproj]
 System.InvalidOperationException: Showing a modal dialog box or form when the application is not running in UserInteractive mode is not a valid operation. Specify the ServiceNotification or DefaultDesktopOnly style to display a notification from a service application. [MyProject.csproj]
    at System.Windows.Forms.MessageBox.ShowCore(IWin32Window owner, String text, String caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton, MessageBoxOptions options, Boolean showHelp) [MyProject.csproj]
    at Microsoft.StyleCop.AlertDialog.DisplayMessageBox(Control parent, String message, String title, MessageBoxButtons buttons, MessageBoxIcon icon) [MyProject.csproj]
    at Microsoft.StyleCop.AlertDialog.Show(StyleCopCore core, Control parent, String message, String title, MessageBoxButtons buttons, MessageBoxIcon icon) [MyProject.csproj]
    at Microsoft.StyleCop.StyleCopCore.LoadAddins(String path, Byte[] publicKey) [MyProject.csproj]
    at Microsoft.StyleCop.StyleCopCore.Initialize(ICollection`1 addInPaths, Boolean loadFromDefaultPath) [MyProject.csproj]
    at Microsoft.StyleCop.StyleCopConsole..ctor(String settings, Boolean writeResultsCache, String outputFile, ICollection`1 addInPaths, Boolean loadFromDefaultPath, Object hostTag) [MyProject.csproj]
    at Microsoft.StyleCop.StyleCopTask.Execute() [MyProject.csproj]
    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() [MyProject.csproj]
    at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask, Boolean& taskResult) [MyProject.csproj]


Any ideas?

Jun 8, 2010 at 8:49 PM

Hi there, I've found this a couple of times before. Your best bet is to remote desktop onto your build machine and use msbuild from the command line on the tfs build script that is failing - this usually allows stylecop to show the message box and might move you forwards a little.

Jun 9, 2010 at 7:07 AM

One question, Erik - do you have your referenced assemblies (including stylecop) set up in one folder? If that's the case then I think StyleCop tries to enumerate through all the other assemblies that are in the same folder as it to see if they contain analysis plug-ins. Sometimes doing this causes it to show a dialog when it can't resolve a reference.

If that is the way you have structured your files, I would recommend putting the stylecop DLLs into a separate folder - that should fix things for you.


Jun 11, 2010 at 6:42 AM
Edited Jun 11, 2010 at 6:45 AM


Thanks for your help! I did run the msbuild manually on the server and the dialog showed. It was a strong name validation failure, I've recompiled the MSBuild.ExtensionPack.StyleCop, because they reference stylecop 4.4 in 4.0. But I can't use that with our Stylecop for resharper plugin so I needed to recomplile the code and didn't take care of strong name.

That was solved by this discussion on the MSBuild Extension pack: 

I took a look at the StyleCop code in this process though, and some rainy day, mabye I'll contribute and rewrite the logging part of StyleCop! ;)