Tag Archives: azure

Azure Batch Deployment and ‘msshrtmi’ Assembly

Azure Batch Deployment Issue

During Azure Batch deployment, I got the following error.

[22:32:51][Step 2/2] Unhandled Exception: System.AggregateException: One or more errors occurred. ---> Microsoft.Practices.Unity.ResolutionFailedException: Resolution of the dependency failed, type = "SomeNamespace.SomeTask", name = "(none)".
[22:32:51][Step 2/2] Exception occurred while: Calling constructor SomeNamespace.Data.Repositories.SomeRepository(SomeNamespace.Common.Repositories.IStorageRepository storageRepository, SomeNamespace.Common.ILoggingService logger).
[22:32:51][Step 2/2] Exception is: TypeInitializationException - The type initializer for 'Microsoft.ServiceRuntime.RoleEnvironment' threw an exception.
[22:32:51][Step 2/2] -----------------------------------------------
[22:32:51][Step 2/2] At the time of the exception, the container was:
[22:32:51][Step 2/2]
[22:32:51][Step 2/2]   Resolving SomeNamespace.SomeTask,(none)
[22:32:51][Step 2/2]   Resolving parameter "analyticsService" of constructor SomeNamespace.SomeTask(SomeNamespace.Common.IConfigurationManager config, SomeNamespace.Services.ServiceLayer.ISomeServiceA chainService, SomeNamespace.Services.ServiceLayer.ISomeServiceB siteService, SomeNamespace.Common.ILoggingService logger, SomeNamespace.Services.ServiceLayer.ISomeServiceC analyticsService)
[22:32:51][Step 2/2]     Resolving SomeNamespace.Services.ServiceLayer.SomeServiceC,(none) (mapped from SomeNamespace.Services.ServiceLayer.ISomeServiceC, (none))
[22:32:51][Step 2/2]         Resolving SomeNamespace.Services.ServiceLayer.SomeServiceI,(none) (mapped from SomeNamespace.Services.ServiceLayer.ISomeServiceI, (none))
[22:32:51][Step 2/2]         Resolving parameter "someRepository" of constructor SomeNamespace.Services.ServiceLayer.SomeServiceI(SomeNamespace.Common.Repositories.ISomeRepository someRepository)
[22:32:51][Step 2/2]           Resolving SomeNamespace.Data..Repositories.SomeRepository,(none) (mapped from SomeNamespace.Common.Repositories.ISomeRepository, (none))
[22:32:51][Step 2/2]           Calling constructor SomeNamespace.Data..Repositories.SomeRepository(SomeNamespace.Common.Repositories.ISomeRepositoryA someRepositoryA, SomeNamespace.Common.ISomeServiceH someServiceH)
[22:32:51][Step 2/2]  ---> System.TypeInitializationException: The type initializer for 'Microsoft..ServiceRuntime.RoleEnvironment' threw an exception. ---> System.IO.FileNotFoundException: Could not load file or assembly 'msshrtmi, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
[22:32:51][Step 2/2]    at Microsoft..ServiceRuntime.RoleEnvironment.InitializeEnvironment()
[22:32:51][Step 2/2]    at Microsoft..ServiceRuntime.RoleEnvironment..cctor()
[22:32:51][Step 2/2]    --- End of inner exception stack trace ---
[22:32:51][Step 2/2]    at Microsoft..ServiceRuntime.RoleEnvironment.get_IsAvailable()
[22:32:51][Step 2/2]    at SomeNamespace.Data..Repositories.SomeRepository..ctor(ISomeRepositoryA someRepositoryA, ISomeServiceH someServiceH, Boolean forceLocal) in F:\TeamCity\buildAgent\work\2b474eac7536416f\SomeNamespace.Data.\Repositories\SomeRepository.cs:line 64
[22:32:51][Step 2/2]    at lambda_method(Closure , IBuilderContext )
[22:32:51][Step 2/2]    at Microsoft.Practices.ObjectBuilder2.DynamicBuildPlanGenerationContext.<>c__DisplayClass1.<GetBuildMethod>b__0(IBuilderContext context)
[22:32:51][Step 2/2]    at Microsoft.Practices.ObjectBuilder2.DynamicMethodBuildPlan.BuildUp(IBuilderContext context)
[22:32:51][Step 2/2]    at Microsoft.Practices.ObjectBuilder2.BuildPlanStrategy.PreBuildUp(IBuilderContext context)
[22:32:51][Step 2/2]    at Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context)
[22:32:51][Step 2/2]    at Microsoft.Practices.ObjectBuilder2.BuilderContext.NewBuildUp(NamedTypeBuildKey newBuildKey)
[22:32:51][Step 2/2]    at Microsoft.Practices.Unity.ObjectBuilder.NamedTypeDependencyResolverPolicy.Resolve(IBuilderContext context)
[22:32:51][Step 2/2]    at lambda_method(Closure , IBuilderContext )

At a glance, it seems like an issue with Unity IOC container. But when I look closer, it’s actually missing ‘msshrtmi‘ assembly as you can see in the following error message:

System.IO.FileNotFoundException: Could not load file or assembly ‘msshrtmi, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35’

Root Cause

This error happens in the build server, but it’s not happening in local machine.

As a comparision, the build server does have Azure SDK installed, the same version used with the Azure Batch application. It also has .NET Framework installed, but not the SDK.

The local machine, on the other hand, has Visual Studio installed, Azure SDK and .NET Framework, but not .NET Framework SDK.

The exception is caused by build server doesn’t have installed Azure SDK library in its Global Assembly Cache (GAC). In local machine, the installation of Visual Studio put Azure SDK into GAC.


It’s as easy as adding msshrtmi assembly to Global Assembly Cache (GAC) in the build server. See here for adding GAC.

Leave a comment

Posted by on January 30, 2018 in General


Tags: , , ,

Azure Storage Blob Listing Query with Search Pattern

Azure Storage blob is not behaving like files and folders in your local computer, albeit looking like one. So, there’s no support for search pattern, such as *.txt

The solution is to write your own search pattern.


public static String WildCardToRegular(String value) {
    return "^" + Regex.Escape(value).Replace("\\*", ".*") + "$";

Then, using it in Listing the blob:

var blobList = await container.ListBlobsSegmentedAsync(blobFilePath, true, BlobListingDetails.None, 1000, token, null, null);
var items = blobList.Results.Select(x => x as CloudBlockBlob);

// Filter items by search pattern, if specify
if (!string.IsNullOrEmpty(searchPattern))
    items = items.Select(i =>
        var filename = Path.GetFileName(i.Name);
        if (Regex.IsMatch(filename, WildCardToRegular(searchPattern), RegexOptions.IgnoreCase))
            return i;
	return null;

Leave a comment

Posted by on September 9, 2017 in General


Tags: ,

Azure Active Directory IDs

Setting up or accessing Azure Active Directory require many IDs. Below is how to find them:

Tenant ID
Azure Portal > Azure AD > Domain names
Azure Portal > Azure AD > Properties > Directory ID


Client ID / Application ID / Audience
Azure Portal > Azure AD > App registrations > ApplicationId

Client Secret / Application Secret
Azure Portal > Azure AD > App registrations > choose the application > Keys
Keys are hidden and only visible the first time you add them.

Redirect URIs or Reply URLs
Azure Portal > Azure AD > App registrations > choose the application > Settings > Redirect URIs or Reply URLs

Azure Portal > Azure AD > App registrations
SQL database:

Azure AD

Leave a comment

Posted by on August 17, 2017 in General


Tags: ,

Azure Key Vault PowerShell Commands


# List all Key vaults

# Get a key given the secret name.
Get-AzureKeyVaultKey -VaultName "vault-name" -Name "secret-name"

# List all secrets
Get-AzureKeyVaultSecret -VaultName "vault-name"

# Get a secret
Get-AzureKeyVaultSecret -VaultName "vault-name" -Name "secret-name"

Azure Get Started

Leave a comment

Posted by on August 17, 2017 in General


Tags: , ,

Azure: On Premises vs IaaS vs PaaS vs SaaS

Azure cloud model is generally divided into two: Infrastructure as a Service (IaaS) and Platform as a Service (PaaS).

The difference is how much you have to manage in each service. The more you have to manage, the more you have to pay.

See this graph below:


Leave a comment

Posted by on May 21, 2015 in General


Tags: , , , ,

Difference Between Azure Web App and Cloud Service

When I first getting started on Microsoft Azure, I was confused between these two: Azure Web Site and Web Role.

Azure Web Site is one of many Azure services while Web Role is an instance running behind Azure Cloud Service, another service offered by Azure. Since then, Azure Web Site has been changed to Azure Web App.

Basically, the difference is the control you have and portion you have to manage in each service.

Azure Cloud Service, Web Role in this case, gives you more control, but with more control, comes greater responsibility. See this graph below:


For detail technical difference, see Feature Comparison on Azure App Service, Cloud Services, and Virtual Machines comparison.

Leave a comment

Posted by on May 20, 2015 in General


Tags: , , ,

Introduction to Azure Services

Microsoft Azure is evolving universe. Couple years ago, there were only less than 15 services. Today, there are hundreds and Microsoft keeps adding more so expect even more to come.

Generally, the services are divided into the following group. There more than what is listed here, but these are the main groups.

  • Compute
  • Data Management
  • Networking
  • Mobile
  • Messaging and Integration
  • Backup
  • Identity and Access
  • Big Data

See below graph to get some idea which service belongs to which group. Again, these are generally idea, not every service and group are listed here.


To get more detail on Azure Services and its groups, check out this Azure infographic from Microsoft.


Now, what do all these components mean to you as a developer? Each component is a tool and you can use it as a building block to your application, be it a web, mobile or windows application. To give you some ideas, this is what your typical application architecture would look like using Azure Platform.


Open World

What’s really amazing about Microsoft Azure is Microsoft has opened up Azure for ecosystem other than Microsoft. If you are MEAN stack developer, you can deploy MongoDB, Express, AngularJS and Node.js in Azure. You can even deploy MySQL, write PHP code or spin up Linux virtual machine in Azure. Yes, it’s now Microsoft Azure and not WIndows Azure anymore because it doesn’t just belong to Windows or .Net developers, but all kind of developers.

The Future

Azure is huge and it is the future. If you haven’t got your hand in Azure, roll up your shirt sleeves and get dirty now. And if you care to read more, head out to Introducing Microsoft Azure.

Leave a comment

Posted by on May 11, 2015 in General


Tags: ,

%d bloggers like this: