Resolving “make sure that the controller has a parameter less public constructor” error in WebAPIs


If you’re working with WebAPIs and in the your API Controller, you have a constructor that takes parameters which are being injected by Unity or any IoC Container, then there might be a case where you will get the below error when you try to hit an API from your controller.

Make sure that the controller has a parameterless public constructor. Below screen shot is from Fiddler which shows the exception response in more detail. Click on the image to see it more clearly.


The reason why it is expecting a default (parameterless) constructor is because the IoC Container was unable to resolve all or some of the parameters of the constructor. Say for example, your constructor is as shown below.


So, in this case, if the implementations of the above interfaces are in a different assembly than that of the interfaces itself and you have missed adding reference of the assembly which actually has the implementation, then the IoC Container cannot resolve the dependency and thus it will fail to call the above parametered constructor.

So when you make a call to one of the APIs, IoC Container fails to inject the dependencies in the above controller and thus expects it to have a default constructor which is absent in our case. Thus the above exception! So to fix this, make sure you have added all required references (All those which have implementations of the required interfaces) in your project.

Hope this helps!!

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

Resolving “Not Authorized to Connect” error while running Azure Service Fabric application


If you’re relatively new to Azure Service Fabric, then there is a chance you might run into this issue wherein you start debugging your service fabric application in Visual Studio 2015 and you run into this exception.

Not Authorized to connect

The thing here to be noted is, when you create a service fabric application in Visual Studio 2015, there are 2 projects that get created: See below screen shot.


In the above sample, the WebApi is the Fabric Service and the SFApplicationDemo is the Fabric App (The one with the sf-logo project logo).

You need to set THIS (the Fabric APP – the one with the above logo) as the startup project and NOT the Fabric Service. This will resolve the issue.

Hope this helps!!


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

Resolving “CloudConfigurationManager does not exist in the current context” compiler error


In case you get are trying to access the cloud configuration file in your Azure Cloud service and get the error “CloudConfigurationManager does not exist in the current context” on CloudConfigurationManager class, then all you need to do is add the nuget package “Microsoft.WindowsAzure.ConfigurationManager” to your project. And then, make sure you include the using statement “using Microsoft.Azure” in the class where you’re trying to access the cloud configuration file.

Hope this helps!!


As pointed by Matthew Harris, this doesn’t seem to work for ASP.NET 5 json configs. While trying to read configuration specified in json file, please follow the approach mentioned in the below link.

Posted in .NET, C# | Tagged , | 4 Comments

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