Tag Archive | Visual Studio

TFS connection Value cannot be null

In our company, we are upgrading from TFS 2010 to TFS 2012. So to test everything we have a clone of the TFS server.

To test the clone I had to switch my connection to the different servers. After hitting the “Connect” button I got a “Value cannot be null.” exception. It said that also that: “Parameter name: baseUri” was the problem. After contacting a colleague of me, he said to delete the cache of the TFS server on my computer. After doing that, the connection worked as it suppose to work.

You can find the cache in the following folder: C:\Users\<yourusername>\Local Settings\Application Data\Microsoft\Team Foundation\2.0\Cache

Minification and Bundling in MVC 4 RC

Asp .NET MVC 4 Release Candidate is out. One of the features that is included is called the minification and bundling feature. This was already there in the beta but in the release candidate version it has changed.

Why should we use it

The reason why we should use the bundling and minification feature is performance. The features increases your loading performance of your website. Every time you reference a JavaScript (like jQuery or your own), or CSS file in your page, the browser makes a call to the server. This is done for each separate reference. Each referenced file has included all the comments and spacing in your file. This makes the file larger then when we should delete those spaced. The bundling and minification feature does this for us.

How does it work

In your Global.asax the CSS and JavaScript files are Bundled with BundleConfig.RegisterBundles(BundleTable.Bundles); line.



Reference the files in your page.


When you run the application and use Fiddler to view the calls to your server, you still see all the files called separately.



This is because the Bundling and Minification feature by default only work when your not in debug mode. This handy because then you could debug with all the whitespaces in your files and have the performance in the production environment.

See the difference in your production environment:



Force Bundling and Minification

You can use the BundleTable.EnableOptmizations override but the best way for a little test is to remove the debug=”true” attribute in your web.config.


Browser caching

When the feature is active, the browser will cache the files. When you add or change some JavaScript or CSS code, the files are generated again and the version number in the references are updated. In that way, the browser knows that there is a new version and your website wont brake.


Change Target Framework version for all the projects in the solution

Ralph Jansen BlogToday I migrated an old project from Visual Studio 2008 to Visual Studio 2010 and with that, I changed the Framework to version 4.0. This is currently the newest .NET Framework. The solution contains a lot of different projects so the challenge was to convert all the target frameworks to the 4.0 version.


There are a couple ways to this:

  1. Change every project by hand. (Open the properties of every project and select the target framework that you want);
  2. Edit the project files by hand in notepad;
  3. Use the macro of Scott Dorman.

The macro of Scott can be found here. Just place the macro on the right place on your pc and execute it. After you executed the macro a popup is shown with the question to which target framework you want to migrate. Choose your framework and press OK.

That’s it!!! Safes a lot of time!!

You can execute a Macro in the Tools->Macros->Macros Explorer window.


Final release Visual Studio 2010 Service Pack 1

Ralph Jansen BlogThe final release of Microsoft Visual Studio 2010 Service Pack 1 (SP1) is available to download. You can find the download here.

Default browser VS2010 Add-in

Ralph JansenLast weekend I was working on a MVC 2 application. When I started the application my default browser (Google Chrome) came up. I actually wanted to change my browser for this application to Internet Explorer because the connectivity between IE and Visual Studio 2010 is much better than with Chrome.

The problem is that you can’t choose for the option “Browse With” in a MVC Application. This is because the controller is deciding which view should start. To fix this problem, I found an add-in for VS2010 that you can switch your default browser on the fly from your toolbar. In that way, you can switch easier between your installed browsers. See the screenshot below. image

You can download the add-in by following the link below.


If you get a popup on the startup of your Visual Studio Instance with the text: “The bits have expired, please download an updated version from http://www.wovs.com&#8221;, you have to download the new version. To do this, follow the steps on this website: http://blog.wovs.com/2010/10/how-to-update-currently-expired.html
Search in the online extension manager for “Default browser switcher”.

Master-Detail with Silverlight RIA Services

Ralph Jansen

If you want to have a master detail view of you data in Silverlight with RIA Services you have to do two things. One thing is to tell your RIA Services meta data file that you’re including the related entities and you will have to tell your domain service as well that your including the related entities. Follow the tutorial beneath to accomplish an example for creating a master detail relation with Silverlight RIA Services.

Silverlight application

Create a new Silverlight 4 application in VS2010 and enable RIA Services. Also don’t forget to check the box to host your Silverlight application in a website.


Create your Entity Framework 4.0 model so we can generate some RIA Service over it. Just use a simple example so we can practice the master detail relationships. The example that I use is shown below.


RIA Services

After your model is created we have to create the Domain Service that exposes your model from the server to the client. If you haven’t used RIA Services before, I suggested you should read the documentation on the http://www.silverlight.net homepage.

Select add new item on your server website. The same place as you created your Entity Framework model. Now search for the Domain Service template. After you clicked the OK button, you will get a popup that is asking you to specify which entity the domain service should expose from your Entity Framework model. Click the Brands and Product collections, select the checkbox to generate meta data files and to enable client access.

Your Domain Service would look something like this:

Creating the UI

Open your MainPage.xaml file that is generated by creating the Silverlight Application. Open your Data Sources window in VS2010 and drag the Brands and Products grids to your MainPage. You have to drag your Products from the inner collection of Brands.


Now if you run your code. Only the brands will be shown because the UI is connected to the GetBrandsQuery. Now we want to include the products to create a Master Detail relation.

Configure the Meta data

Open your meta data file that is generated by the Domain Service. Find your Brands Entity and in that entity the inner collection property of Products. Add the [Include] attribute above the inner collection of products. In that way we tell RIA Services to include the products for the brand if the products are available.


Make the products available

To make the products available for RIA Services you should include them in the correct query that is used in the client. In our case it is the GetBrands in the Domain Service class.


Add the include statement like below to the query.


Now you are ready to run your code and see a nice example of a master detail relationship in the client.


It is better to create a new query then change the default query. In that way the performance is better because you don’t need the products every time you use the GetBrands query. You can create a query like GetBrandsWithProducts. If you do this, don’t forget to change the query name in the client. This is still referenced to the GetBrands query!!!

Change Class template in Visual Studio 2010

Ralph JansenIf you want to change the default ItemTemplate of a class file in Visual Studio 2010, you can follow the steps below.

  1. Go to the right folder on your local machine.
    1. x64: C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ItemTemplates\CSharp\Code\1033
    2. x86: C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\ItemTemplates\CSharp\Code\1033
  2. In that folder you will see the Class.zip file. If you open the class file directly from the zip, you can see the default class template of Visual Studio 2010. In my case, I want to add some default stuff like regions and constructors.
  3. Save the class file. It could be that you get a question that the zip file has changed and want to be reloaded. Click in that case “Yes”.
  4. Now, if you open VS2010, you won’t get the new class template yet. This is because the class template is not yet available in VS2010. VS2010 uses an ItemTemplatesCache directory to store the active templates. You need to override the already active template. This sounds very difficult but is very easy to do. Open your Visual Studio command prompt from the visual studio installation folder in your start menu.
    image(You maybe need to open it as Administrator)
    Fill in this comamnd: “devenv.exe /installvstemplates”
    The strange part here is that you won’t get any confirmation about the success of the installation. This could take a while because when I looked several times in visual studio, I still got the old template. After a few minuts, the new template was suddenly there.

  • It is better to close all your Visual Studio instances. before you follow these steps above.

  • These steps should also work for Visual Studio 2008 but I haven’t tested it.
    Sample template:

    /*using System;
    using System.Collections.Generic;
    $if$ ($targetframeworkversion$ >= 3.5)using System.Linq;
    $endif$using System.Text;

    namespace $rootnamespace$
    public class $safeitemrootname$

    #region Constants


    #region Private Fields


    #region Private Properties


    #region Public Properties


    #region Constructors

    /// <summary>
    /// The default Constructor
    /// </summary>
    public $safeitemrootname$()


    #region Private Methods


    #region Public Methods





  • How to change the setup.exe icon

    Ralph JansenIf you create an application, you have also create an installer project. The installer creates two files for you. An setup.exe file and a msi file. The icons of the two files are set by the default windows icons. In Windows 7 it looks like this: image

    If you want to change the icon of the installer, you can not do that by default in your installer project. Also, the icon of the msi file can not be changed at all. For the setup.exe file you have to do it manually for each time you create a new installer. So every time you fix a bug and releases a new version of your application by the new created installer you have to set the icon manually. Lucky that this is not hard to do.

    Change the icon

    1. Create an installer project with the right settings that you want and build it.
    2. Now open the setup.exe file in the release folder (that is the one that you want to give to your client) in Visual Studio. You can do this as follow:
      1. Click in Visual Studio on File –> Open –> File
      2. Navigate to the exe in the release folder
      3. Click open and then you will see an explorer in Visual Studio
    3. Right click with your mouse on the icon folder and choose “Add Resource…”
    4. The icon type is now selected by default. Choose on the right of the popup for “Import”
    5. Navigate to the right icon that you want and select it
    6. The popup will now close and the icon folder in the explorer is expanded
    7. Make sure that your new icon has the lowest ID. If you don’t do that, the icon will not been shown
    8. Save the setup.exe and return in Windows Explorer to the release folder. You should now see the new icon.