X Blogs

who you gonna call?

SharePoint User Code Service not starting

clock January 17, 2011 20:42 by author Robi

I tried to publish a sandbox solution on SharePoint Server and was getting error that Sandbox Code service server was not found. I checked in Central Administration and found out, that Microsoft SharePoint Foundation Sandboxed Code Service was running and that SharePoint 2010 User Code Host Service was set to automatic but not running.

In the event logs, I found out, that I have errors in system logs:

  • Event Id: 7031, 7034;
  • source: Service Control Manager;
  • details: The SharePoint 2010 User Code Host service terminated unexpectedly.

I found out, that service account that was running Sandbox code service needs to have access to performance counters on the server. So what you need to do is pretty simple, you need to grant service account access to counters and you can do it by adding service account as a member of local group Performace Monitor Users in Server Manger.


Voila, after adding user to Performace Monitor Users everything works as expected.

MVC3 Windows Azure Deployment

clock January 14, 2011 21:12 by author Rok Bermež

For RTM version of MVC 3 make sure the deployment contains following dlls:

  • Microsoft.Web.Infrastructure
  • System.Web.Helpers
  • System.Web.Mvc
  • System.Web.Razor
  • System.Web.WebPages
  • System.Web.WebPages.Deployment
  • System.Web.WebPages.Razor


Windows Azure Full IIS

clock January 11, 2011 08:00 by author Rok Bermež

Some time ago I wrote how to deploy multitenant application to the Cloud. The process was tricky at best. With new Windows Azure SDK 1.3 things just got a lot simpler and I absolutely love it. The feature is called Full IIS and allows your web roles to access the full range of web server features that are available in on-premise IIS installations. However if you choose to use them, there are a few differences from the classic Azure Hosted Web Core (HWC) model.

First you need to tell Windows Azure SDK to use Full IIS instead of HWC and you do this by adding a valid <Sites> section to your ServiceDefinition.csdef  file.  By default Visual Studio will create HWC model definition like this:

      <Site name="Web">
          <Binding name="Endpoint1" endpointName="Endpoint1" />

You can easily customize it to define multiple web sites, or virtual apps (virtual directories are also supported now):

  <Site name="MainSite">
    <VirtualApplication name="WebApp1" physicalDirectory="D:\Delo\Projects\WebApp1\" />
      <Binding name="HttpIn" endpointName="HttpIn" />
  <Site name="AnotherSiteOrSubDomain" physicalDirectory="D:\Delo\Projects\ AnotherSiteOrSubDomain ">
      <Binding hostHeader="anothersiteorsubdomain.myall.si" name="HttpIn" endpointName="HttpIn"/>

Things are much more similar to on-premises application then in HWC model. While RoleEntryPoint  runs under different process (WaIISHost.exe) than your web roles  (w3wp.exe), OnStart method still gets called but configuration settings work a bit differently. You cannot register or store some static values to be available to all websites. Remember its running in a different process... so you wont be able to access its data. What I mean by this is, probably everyone dealing with Azure Development has something similar to this in their role onstart method:

CloudStorageAccount.SetConfigurationSettingPublisher((configName, configSetter) =>{

While code is still perfectly sound, it wont do any good to our web roles, so the proper place to register it would by global.asax on ApplicationStart event. It all kind of makes sense, since different websites need different resources anyway.

MultipleGenericBindingGenerator for Ninject.Extensions.Conventions

clock January 11, 2011 02:55 by author Rok Bermež

Ninject.Extensions.Conventions provides convention based binding for Ninject modeled after the StructureMap 2.5 AssemblyScanner by Jeremy Miller.

When StructureMap users can use something like:

Scan(scanner =>
                    scanner.AssembliesFromApplicationBaseDirectory(assembly => assembly.FullName.StartsWith("Ntk.Infrastructure."));
                    scanner.ConnectImplementationsToTypesClosing(typeof (IMessageHandler <,>));
                    scanner.ConnectImplementationsToTypesClosing(typeof (IMessageHandler <>));

Ninject.Extensions.Conventions using GenericBindingGenerator can not:

            kernel.Scan(scanner =>
                scanner.FromAssembliesMatching( "Ntk.Infrastructure.*.dll" );  
                scanner.BindWith(new GenericBindingGenerator(typeof(IMessageHandler<>)));
                scanner.BindWith(new GenericBindingGenerator(typeof(IMessageHandler<,>)));

So slightly modified version of GenericBindingGenerator called MultipleGenericBindingGenerator comes to the rescue:

            kernel.Scan(scanner =>
                scanner.BindWith(new MultipleGenericBindingGenerator(typeof(IMessageHandler<>),typeof(IMessageHandler<,>)));

If anyone needs anything like this, here is the code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Ninject;
using Ninject.Activation;
using Ninject.Extensions.Conventions;

namespace TestProj{
    public class MultipleGenericBindingGenerator  : IBindingGenerator
        private static readonly Type TypeOfObject = typeof (object);
        private readonly Type[] _contractTypes;

        /// <summary>
        /// Initializes a new instance of the <see cref="MultipleGenericBindingGenerator"/> class.
        /// </summary>
        /// <param name="contractTypes">Types of the contract.</param>
        public MultipleGenericBindingGenerator(params Type[] contractTypes)
            foreach (var type in contractTypes)
                if (!(type.IsGenericType || type.ContainsGenericParameters))
                    throw new ArgumentException(String.Format("The contract must be an open generic type ({0}).",type.Name), "contractTypes");
            _contractTypes = contractTypes;

        #region Implementation of IBindingGenerator

        /// <summary>
        /// Processes the specified type creating kernel bindings.
        /// </summary>
        /// <param name="type">The type to process.</param>
        /// <param name="scopeCallback">the scope callback.</param>
        /// <param name="kernel">The kernel to configure.</param>
        public void Process( Type type, Func<IContext, object> scopeCallback, IKernel kernel )
            Type interfaceType = ResolveClosingInterface( type );
            if ( interfaceType != null )
                kernel.Bind( interfaceType ).To( type ).InScope( scopeCallback );


        /// <summary>
        /// Resolves the closing interface.
        /// </summary>
        /// <param name="targetType">Type of the target.</param>
        /// <returns></returns>
        public Type ResolveClosingInterface( Type targetType )
            if ( targetType.IsInterface || targetType.IsAbstract )
                return null;

                Type[] interfaces = targetType.GetInterfaces();
                foreach ( Type @interface in interfaces )
                    if ( !@interface.IsGenericType )

                    if (_contractTypes.Contains(@interface.GetGenericTypeDefinition()))
                        return @interface;
                targetType = targetType.BaseType;
            } while ( targetType != TypeOfObject );

            return null;

T4MVC templates for strongly typed ASP.MVC

clock January 10, 2011 21:19 by author Rok Bermež

T4 templates for strongly typed ASP.MVC


MVC is a software pattern, that has been first introduced 1979 by Norwegian scientist Trygve Reenskaug.  The idea was to decouple the tight knot between views and models, to have a much more control over the software.

For example, very known ASP.NET 2.0 technology had the implementation of views, but controllers and models were combined in the code behind, which has the impact on the testing and other features, which is needed to build a easy proficient sustainable web solution.

Year ago Microsoft has launched a framework ASP.NET MVC for supporting software pattern and add additional value with different view engines , such as Razor, to eliminate this requirement. Since then, developers are having  few consideration about choosing between ASP.NET WebForms and ASP.NET MVC, but that is topic for another blog post.

MVC grew very quickly and alot of developers are using the new .NET framework to write efficient, light weight, powerfull web apps. Even though we do have a great enviroment for writing, testing, debugging  .NET apps, there is still a lack of string and mis-machted typos.

Consider following example:

<%:Html.ActionLink(»My link«,«Indeks«,«Home«) %>

This is a link to the Home controller, with a method Indeks. But wait, there is no indeks method there. It is a typo. Since we forgot to write x, instead of ks, we got a runtime error. We have to run the site, click of the link, read the error message, ask ourself, what did we do, use the debugger, run the site, check again, go through bunch of step, just because we made a typo.

This is the reason, why expert developers, such as david Ebbo, created a helper (T4 templates), that goes through the code and created a strongly typed strings for controllers, views, even a content.

Fixed upper example:

<%:Html.ActionLink(»My link«, MVC.Home.Index)%>

Its so easy. No more runtime checking, no repro bugs, even intellisense helps us understand, which name and even parameters we will use. 

You can use the following strongly typed helpers in the whole app, not only the views ( also in controllers, etc.)

It is quite simple to use it:

1.       Download the zip file on the codeplex site

2.       Required watching the David Ebbo intro with examples

3.       Unzip the file

4.       Add the 2 files in the root of your MVC app (T4MVC.tt and T4MVC.setting.t4)

5.       Build it

6.       Use it J

You can change the setting for t4 in the settings file to bend it to you will J

Happy no-typo coding.

C# and PHP functions

clock January 8, 2011 23:45 by author Rok Bermež

Recently I had to create .NET project that was based on legacy php application. The problem was thet old applications data needed to be preserved and that included hashed passwords for substential current user base. Old application used two hashing mechanisms, md5 (no problem) and oldpassword mysql function. Since data model has been optimized and moved from MySql to MSSql (and later to Sql Azure) that was a bit of a problem.

If anyone encounter something similar, this could help a lot:

        public static string MySqlOldPassword(string sPassword)
            UInt32[] result = new UInt32[2];
            UInt32 nr = (UInt32)1345345333, add = (UInt32)7, nr2 = (UInt32)0x12345671;
            UInt32 tmp;
            char[] password = sPassword.ToCharArray();
            int i;
            for (i = 0; i < sPassword.Length; i++)
                if (password[i] == ' ' || password[i] == '\t')
                tmp = (UInt32)password[i];
                nr ^= (((nr & 63) + add) * tmp) + (nr << 8);
                nr2 += (nr2 << 8) ^ nr;
                add += tmp;
            result[0] = nr & (((UInt32)1 << 31) - (UInt32)1);
            UInt32 val = (((UInt32)1 << 31) - (UInt32)1);
            result[1] = nr2 & val;
            string hash = String.Format("{0:X}{1:X}", result[0], result[1]);
            return hash.ToLower();

        public static string GetMD5Hash(string input)
            System.Security.Cryptography.MD5CryptoServiceProvider x = new System.Security.Cryptography.MD5CryptoServiceProvider();
            byte[] bs = System.Text.Encoding.UTF8.GetBytes(input);
            bs = x.ComputeHash(bs);
            System.Text.StringBuilder s = new System.Text.StringBuilder();
            foreach (byte b in bs)
            string password = s.ToString();
            return password;

... azure looks back at you

clock January 8, 2011 23:22 by author Rok Bermež

It’s been a month since Azure SKD 1.3 has been released with a lot of new features. Let’s take a look at the ability to user Remote Desktop Connection to your roles first.

In order to enable this feature we must configure our deployments to support it. The easiest way to do so is to right click on cloud service project in visual studio and choose deploys. There you can click on 'Configure Remote Desktop connections'.

Here you can enable RDP connections for all roles and you must set the required security credentials. So let’s create a security certificate first.

Then we set user credentials for our RDP account and set its expiration date.

After that, we export the security certificate so we can upload it to the cloud (you can click on view to open it directly).

We also export private key

And then we upload exported file through the Windows Azure Management portal to our chosen hosted service.

If we take a closer look at what our Visual Studio Wizard did, we can open ServiceDefinition.csdef and ServiceConfiguration.cscfg and see xml additions.

Now we can deploy our solution anyway we like.

Once the deployment is complete and our role is in 'ready' state we can download or open .rdp file through Azure Management portal.

Now we can finally connect to our instance

... and azure looks back at you

NOTE: Changes made to instance will NOT be persisted. This was meant for easier debugging. If you want to take full advantage of IIS configuration you will need to use ‘Full IIS’ feature, which will be covered in my next post.

Windws Server backup on Windows Server 2008 R2 crashing

clock December 8, 2010 21:19 by author Robi

So I wanted to change backup location of my Windows Server backups and everytime I wanted to remove or change backups the MMC was crashing.

So I wanted to do it in Windows PowerShell and found out, that by default Windows Powershell does not have module to manage Windows backups.

What you need to do is to add snapin for Windows Backup by typing:

Add-PSSnapin windows.serverbackup

Then you get all the commands that you can find here: http://technet.microsoft.com/en-us/library/ee706683.aspx.

So, to completely remove backups from Windows Server Backups, just type:

Remove-WBPolicy -All

and confirm it with: y.

Now, I can configure new backup set inside Windows Server backup MMC.


Cascading Dropdowns in InfoPath 2010

clock December 8, 2010 20:28 by author Robi

During one of my classes I got a question hot to make cascading dropdowns in InfoPath 2010 for SharePoint 2010, so here is a Visual How to:

First, you have to make lists that will hold lookup data. I made a list called KategorjaNapake which is a category list and I made TipNapake list which is a Subcategory list. I made a reference to a category list with a lookup column.


SubCategory list with a reference to Category list, made with a lookup column.

Columns in subcategory list:

Create columns in main list for data. First I made a column for entering text data and the second column I made was a lookup column to a category list.


Here are the columns I made for a main list...

Next, we will customize a SharePoint list form with InfoPath 2010...

Insert a new line in InfoPath Form

Insert a new dropdown field...

Here, just click OK, we have to go into dropdown field properties to get more choices.

If you want to display column name in SharePoint as TipNapake you have to change it here, so change field1 to name that you want to use.

To create new data source for this field, go to properties

Choose get choices from external data source and click Add.

Pick SharePoint library or list...

Pick List that you want to connect to...

Choose fields that you want to have in your data source. It is very important here to also pick the category field.

To create a cascading dropdowns, prepare yourself for a click fest. So click on the button next to Entries.

Click Filter data

Test the form in InfoPath...

Click the Quick Publish Button...

Test your form in SharePoint List....



Windows Azure SDK 1.3

clock December 2, 2010 00:00 by author Rok Bermež

Enhancments promised at PDC2010 are availiable for the tryout run, as well as new SDK. Get it while its hot Wink

About the author

Rok Bermež is Slovenian Windows Azure MVP, he works as a Software Engineer and Microsoft Certified Trainer at Kompas Xnet. His primary interests include cloud computing and web development. With extensive experience in development and architecture he participated in many projects and since the CTP release of Windows Azure much of those projects are based on Windows Azure platform. Rok has been delivering courses, writing code and speaking at conferences and community events on Microsoft technologies for the last couple of years. You can also find him on Twitter (@Rok_B).

Month List

Sign In