Resolving “Mapper not initialized. Call Initialize with appropriate configuration.”


In case you’re using AutoMapper to map entity objects; something like below line of code

Mapper.Map<User, UserEntity>(user);

and if you get the exception, “Mapper not initialized. Call Initialize with appropriate configuration.“, then it means, well, that you’ve not initialized AutoMapper and need to do so before mapping entitiesūüôā

So in order to initialize AutoMapper and create maps, use the below code in your application. It is better to call the below method on application startup.

public static void InitializeAutoMapper()
            Mapper.Initialize(x =>

In the above code, ‘MapProfile’ is a custom class that I’ve added which inherits from AutoMapper.Profile class and overrides the Configure method to define custom maps required in the application. The code inside MapProfile is as shown below.

internal class MapProfile : AutoMapper.Profile
        protected override void Configure()
            CreateMap<DataModel.User, BusinessEntities.UserEntity>();
            CreateMap<BusinessEntities.UserEntity, DataModel.User>();

In case you add more entities in your application and need more maps, you can just add the CreateMap<> statements in the above Configure method as required.

Once the above code is added, AutoMapper gets initialized and the exception no longer throws while mapping objects.

Hope this helps!

Posted in .NET, General | Tagged , , , , , , , , , | Leave a comment

Recreate azure cloud service package with correct instance size from a package having incorrect VM size


Consider a scenario where you’re given azure cloud service packages for deployment and you don’t have access to the code base used to create that package. And in case one of the package’s ServiceDefinition.csdef file has an incorrect VM size mentioned.

In this case, you either have to request for a new package which might take lot of time based on the dev team’s availability or else, you can recreate the package if you have Azure SDK installed in your local machine. This post will explain the steps required to re-create the package with the right size VM in case getting another package is not possible immediately and deployment is time-critical.

Follow below steps to re-create package:

  1. As a backup, take a copy of the incorrectly-sized package. We will work on the copy from now.
  2. Rename the package such that it’s extension is now .ZIP as shown below
  3. Extract the contents of the above created ZIP file into a folder. You should see some 7 items inside as shown below.
  4. Note the file that is highlighted in the above image. the file with the .CDSX extension. You need to update the extension of this file also to .ZIP.
  5. After extracting the above file, open the folder and you will see the ServiceDefinition.csdef file. Edit the file and change the VMSize to the required size. See below.
    3 4
  6. After editing the csdef file, go back to the previous folder and now select and rename the file with .CSSX extension to have a .ZIP extension. This file’s name will start with the rolename. Extract this zip as well. See below
    5 6
  7. Note the highlighted two items in the above extracted zip. The approot folder has all the binaries of the cloudservice that needs to be deployed. And the __entrypoint.txt file has the entry point DLL mentioned in it. Edit the __entrypoint.txt text file to be of the format EntryPoint=dllname.dll. It might not have the initial EntryPoint=, you will have to add it. Otherwise there is a chance of facing exception later on.
  8. Now navigate to the below folder in command prompt.
    C:\Program Files\Microsoft SDKs\Azure\.NET SDK\v2.9\bin
  9. This folder has the cspack.exe that is used to generate cloud packages. Type the below command now to generate the cloud package again. Make sure the role name, quotations and paths are correctly mentioned in the below command.
    cspack.exe “path_to_csdef_File\ServiceDefinition.csdef” /role:<RoleName>;<path_to_Binaries\approot> /out:D:\NewPackage.cspkg /rolePropertiesFile:<rolename>;<path_to_entry_point_file\entrypoint.txt>
  10. The newly created cloud package has the updated VM Size. Deploy this package to update the cloud service to the correct VM size.

Please refer to the below links for more information about cloud packaging.

Hope this helps!!

Posted in .NET, General | Tagged , , , | Leave a comment

Add Bot Framework C# Template to Visual Studio 2015


In this post, we’ll see how to add the Microsoft Bot Framework’s template to Visual studio’s New Project dialog.

Follow the below steps to add it to the New Project Dialog.

  1. Download the C# VS template from here. It will be a zip file. Keep the zip file as is.
  2. Open the folder location where Visual Studio looks for User Templates.
    1. You can get the location by navigating to Tools –> Options –> Projects¬†and Solutions –> User Projects Templates location.
  3. Copy the downloaded template into the C# folder. You can choose to paste it directly or create a folder and then paste it into that. Creating a folder will help in having the template in a more organized fashion in the New Project dialog. In this case, I have created another folder Bot Applications and pasted the zip file into it.
    In the image above, you can see the folder I have created and in the bottom part of the image, you can see the zip file that I have pasted into that folder.
  4. Now, close all open instances of Visual studio and reopen VS again. Click on New Project and you should see Bot Application section and the corresponding template added.
  5. You can now create your Bots!

Hope this helps!

Posted in .NET | Tagged , , , , , , , , , , , , , , , , , | Leave a comment

[TFS] Label older code base in TFS branch despite new check-ins


Consider a scenario where you need to label a TFS branch at end-of-day everyday and you missed labelling it yesterday and today there are quite a number of check-ins already committed in the branch. How do you label yesterday’s code base then?

TFS provides a very easy way to label branches and solution to above scenario also exists. Follow the below steps to label the older code base.

  1. Right-click the TFS branch to be labelled and click on View History. Note the last changeset number at which you want to label the branch.
  2. Go back to Source Control Explorer and right-click the branch to be labelled. Go to Advanced –> Apply label
  3. In the drop-down, select Changeset and enter the change set number that you noted down earlier.
  4. Enter the label name of your choice and then click on create.

Now the TFS branch code base is labelled at the level of the last changeset which we entered. To verify the labelled code, compare the latest version of the code with the labelled code that you just created. There have to be differences and these differences will be that of the check-ins made AFTER the change set noted down above.

Hope this helps!

Posted in .NET, TFS | Tagged , , , , , , , | Leave a comment

Difference between different display modes of SplitView in XAML


The below graphic gives a very clear explanation of the differences between types of DisplayModes of SplitView in XAML.

Source :

SplitView display modes

Hope this Helps!

Posted in .NET | Tagged , , , , , , , , , , | Leave a comment