I recently upgraded an MSTest project to .NET 4.0 and VS 2010. Several of the tests query an outside vendor service and thus prompt the user for necessary credentials to communicate through our corporate web proxy. This used to work fine in vs2008 but after the upgrade the dialog will only display if the user switches focus from VS to another app immediately after kicking off the tests. Is there anything special that needs to be done when displaying the dialog? The best I can figure is that there is some WPF caveat that got introduced with the redesign of VS.
The code in question
private void PromptUser()
{
if (!credentialsSet)
{
using (CredentialsDialog dialog = new CredentialsDialog(true))
{
Process process = Process.GetCurrentProcess();
IWin32Window window = Control.FromHandle(process.MainWindowHandle);
DialogResult dr = dialog.ShowDialog(window);
if (dr == DialogResult.Cancel)
{
throw new InvalidOperationException("Credentials not entered");
}
credentials = dialog.Credentials;
user = dialog.Username;
password = dialog.Password;
domain = dialog.Domain;
}
credentialsSet = true;
}
}