Archive for the ‘Visual Studio’ Category.

Unit Test in Visual Studio Fails to Copy a Critical Configuration File which Fails Test

I ran into this problem when working with Visual Studio 2010. I had a project which had a SQL Server Compact database file (.sdf) which according to the build was to be Copied to the output directory during builds. But the problem was that during my unit testing, this file was not being copied out to the target directory for unit testing and code coverage. Once the test was run, it would fail because the database file could not be found.


To have any ancillary file included in a test output run, one needs to add it to the test deployment.  Here are the steps

  1. In the Solution Items folder of the solution find Local.testsettings file.
  2. Double click the Local.testsettings file
  3. Select the Deployment category.
  4. Choose the file by selecting the Add File button.
  5. Path to the file.

Done and retest to verify.


Visual Studio: Downloaded Assembly Gives "ValidateXaml" task failed unexpectedly Error or FileLoadException

This is a How To Fix when you have downloaded a foreign (to your computer) assembly which can occur when dealing with Silverlight assemblies but it applies to all assemblies downloaded. Here is more of the errors:

error MSB4018: The "ValidateXaml" task failed unexpectedly.

error MSB4018: System.IO.FileLoadException: Could not load file or assembly ‘… \ImageSequence.dll’ or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)

System.NotSupportedException: An attempt was made to load an assembly from a network location which would have caused the assembly to be sandboxed in previous versions of the .NET Framework. This release of the .NET Framework does not enable CAS policy by default, so this load may be dangerous. If this load is not intended to sandbox the assembly, please enable the loadFromRemoteSources switch. See for more information.

The situation is that the OS has identified that the assembly was not made on the computer and has been blocked. This is usually the case with downloaded assemblies and is a security feature.

Steps To Resolve

  1. In Visual Studio in the Solution Explorer Window right click on the project which contains the dll and select Open Folder in Windows Explorer.
  2. In Windows Explorer find the dll in question and right click and select Properties.
  3. Select Unblock and select OK. (As shown below)


  4. Rebuild.

Once you see the properties and this text its more self explanatory than the Visual Studio error.

This file came from another computer and might be blocked to help protect this computer.


Remember that .Net is an Xcopy install. Meaning that any .Net application can be installed by simply copying over the assemblies. The OS recognizes the assemblies and categorizes them for running. When one copies code over and tries to manipulate it in Visual Studio the OS blocks for safety reasons and it subsequently fails during a Visual Studio build.


VS2010: Not Seeing the Obvious – Named Threads in Profile Reports

iStock_000002461629XSmallCall me crazy but I named my kids, I named my pets and heck, yes I even name my threads. Things which are important to me in life are worth naming; right? Thread names for me can be important in debug situations. When one uses the Performance Wizard and chooses to have a Concurrency Visualization profile report, specifically the Threads section the name of a thread is not used.

Historically and in the latest version of Visual Studio 2010 the profile reports ThreadMedo not show the thread names. Why?

Don’t get me wrong on this, Visual Studio Twenty Ten is a great product and light years ahead of all other versions! I look forward to having it share my cube and work computer for eight plus hours a day when it is finally released. But heck a man can dream can he?

Let us take a look at what inspires me to write this diminutive dissertation on a distilled user suggestion…


One can name threads, simply by, well naming it. Here is a code snippet below:

Thread T1 = new Thread(ThreadOne);

T1.Name = "Jabberwocky";


Viola our thread is named. I cannot think of another reason for naming a thread except for debug purposes. Hey did someone mention debug?


Yep while debugging the nice little Threads window as shown above displays our named thread. But yet the Profile Performance reports do not show it. Are the two groups at Microsoft not talking to each other and sharing technology. ;-)

Heck I even tried a trick to Trojan Horse a name into the profiler (Reference the Microsoft.VisualStudio.Profiler dll located in the install directory at  \Team Tools \Performance Tools\)

Thread t = new Thread(new ParameterizedThreadStart(
threadIndex =>

Console.WriteLine("Hello from thread " + (int)threadIndex);

alas to no avail. The report still only shows the type of thread and its generic ID.


I feel that named threads might give one an edge in debugging race or deadlock conditions in code. This is a great tool which frankly could be made even better by including the actual thread names, if found in the report.

Connect Suggestion

If you find this little diatribe interesting go and put your two cents into the Microsoft Connect issue which I created:

Named Threads: Missing the Obvious on Profile Reports

Thanks for your time and well; taking a second look.


Windows 7: Getting SQL Express to Work with Visual Studio

Here are some of the tips and tricks required to get SQL Express working with Visual Studio 2008 under Windows 7.

SQL Management Studio

Why they don’t supply this with the install of Express is beyond me. But you will need it to solve a problem in a future step so I recommend you download it. Microsoft SQL Server Management Studio Express Note check for a newer version than the one at the time of this writing.

Before you actually install it, do the next section first.

User Account Control Not Just For Vista

This situation actually affects most of the older install programs when it comes to the UAC. The user account control will have an install quietly fail an install and provide no warning to the user that it was the UAC. For example if you run the install for SQL Management Studio with the default UAC settings in Windows 7 this is the error you will get:

The installer has encountered an unexpected error installing this package. This may indicated a problem with this package. The error code is 29506.

The UAC will never come up with any warning either.

So change the UAC settings to be minimal (search for UAC in the start bar and select Control Panel –> Change User Account Control Settings) and set to minimal settings.

Install the Management Studio Now.

Connecting to the Database Complains about .Net…WHAT?

Once you attempt to connect to the sql express database VS2008 will complain such as:

Execution of .NET Framework code is disabled.

Set "clr enabled" configuration option and restart the server.

I love this error because it implies you need change Visual Studio’s setting. Oh no, its the SQL Express Server setting. To add insult to injury one cannot use Visual Studio’s SQL editor to execute the change! It has to be done from management express.

Wow…as a new developer that has to be a challenge. Microsoft gives the tools such as express, but makes it impossible to use out of the gate.

To resolve the problem open up SQL Server Management Studio Express, open up the instance of SQL Express and run this command:

EXEC sp_configure 'CLR ENABLED' , '1'

Once run find Sql Server Configuration Manager in the start program menu and by right clicking the “SQL Server (SQLEXPRESS)” instance restart the service. At that point you should be able to go back to Studio and run the application. HTH


Visual Studio 2010 – Fuzzy Text

In loading Visual Studio 2010 beta 1, I was very disappointed. Out of the box, the dialog menu text is fuzzy along with most dialogs. Here is V2010 and Visual Studio 2008 side by side. Notice the File menu text is fuzzy:


Notice toolbox is the biggest offender. Even the colors while editing are not as crisp. Is it just me or do my eyes fail when looking at VS2010? Someone has beat me to writing a Microsoft Connect issue on this one: Fuzzy text display in Visual Studio 2010 Beta 1.


Test Custom Actions During Install Deployment

In researching a MSDN forum question I needed to see the current user’s credentials during a custom action during an Setup and Deployment project created from a Visual Studio 2005 project. My goal was to show a message box during install that would display the user’s credentials and domain.

What makes this project unique is that we will be using MessageBox, from the System.Windows.Forms namespace. This article shows you how to utilize a MessageBox in a custom action. Here are the steps

  1. Using this article as a basis Walkthrough: Creating a Custom Action we will do everything it does except do a Commit action.
  2. Add a reference to the dll project to include the System.Windows.Form namespace which will not be included by default.
  3. In the custom installer class created in the helper dll override the Install Method such as:
    public partial class ShowInfo : Installer
        public ShowInfo()
        // Add and override this method to show the current user and the domain.
        public override void Install(System.Collections.IDictionary stateSaver)
            WindowsIdentity wi = WindowsIdentity.GetCurrent();
            MessageBox.Show(string.Format("Name :{0}{1}System {2}", wi.Name, Environment.NewLine, Environment.UserDomainName));
    Then add these usings to the top of the file:
    using System.Windows.Forms;
    using System.Security.Principal;
  4. Then in the install project unlike the Walkthrough, add the custom dll to the Custom Actions operation in the Install Node.
  5. Build and install. Note the message box may come up behind other windows during install, so you may have to look.

This is a quick way to show information during an install for debug purposes or user info. Note it is a modal dialog and will stop processing until the user closes the message box window.


Where are the Hidden Files using Visual Studio 2005?

Question: I need to find the hidden files such as reference.cs which is generated for me when I create a web service in Visual Studio 2005 but is is hidden. How do I find them?

Answer: Open up the Solutions Explorer and click the Show All Files button:




Region Macro For Visual Studio

I created this before the code snippit region came along. This macro will work with VS2003 and VS2005. Simply highlight the code you want and a dialog box will come up asking for the name. Note depending on the location the #region and #endregion will be at those positions.

Sub RegionIt()
    Dim sWhat As String
    sWhat = InputBox("Region Name")
    If (sWhat <> "") Then

      Dim selection As TextSelection = DTE.ActiveDocument.Selection()
      Dim start As EditPoint = selection.TopPoint.CreateEditPoint()
      Dim endpt As EditPoint = selection.BottomPoint.CreateEditPoint()

      DTE.UndoContext.Open("Comment Region")
          start.Insert("#region " & sWhat & Chr(13))
          endpt.Insert(Chr(13) & "#endregion")
          'If an error occured, then need to make sure that the undo 
          'context is cleaned up. Otherwise, the editor can be left 
          'in a perpetual undo context
      End Try

    End If
End Sub