Hibernating Rhinos

Zero friction databases

Uber Prof Production Profiling–Profiling production application on Azure

In this post I’m going to cover one of the great features of Uber Prof v2.0: production profiling of remote applications running on Windows Azure.

The production profiling feature is currently supported in the following profilers: NHibernate Profiler, Entity Framework Profiler, Linq to SQL Profiler, LLBLGen Profiler. In this post I’m going to demonstrate how to use this with the Entity Framework Profiler.

First, we need to create our project. Since we want to host the project on Windows Azure, I’ll use an ASP.NET MVC + Web API project.


The next thing is to enable production profiling. In order to so, we need to install the EntityFrameworkProfiler.Production NuGet package.


As a side note, if you wonder what is the other package called EntityFrameworkProfiler, you probably want to read this post.

After the package is installed, you can see that it created the following file in our project:

using System;
using System.IO;
using System.Web.Http;
using HibernatingRhinos.Profiler.Production;

[assembly: WebActivator.PreApplicationStartMethod(typeof(ProductionProfilingOnAzureSample.App_Start.EntityFrameworkProfilerProductionBootstrapper), "PreStart")]
namespace ProductionProfilingOnAzureSample.App_Start
    public static class EntityFrameworkProfilerProductionBootstrapper
        public static void PreStart()
            // Initialize the profiler with the production profiling feature. 
            // Production profiling let's you let you see profiling information remotely using the following URL: http://your-server/profiler/profiler.html
            string license = GetResource("ProductionProfilingOnAzureSample.App_Start.EntityFrameworkProfilerLicense.xml");
            ProductionProfiling.Initialize(license, GlobalConfiguration.Configuration);

        private static string GetResource(string sourcesResource)
            using (var sourceCodeStream = typeof(EntityFrameworkProfilerProductionBootstrapper).Assembly.GetManifestResourceStream(sourcesResource))
                if (sourceCodeStream == null)
                    throw new InvalidOperationException(string.Format("Resource file is missing: {0}", sourcesResource));
                return new StreamReader(sourceCodeStream).ReadToEnd();

This class will run on the startup of your project and will expose a URL endpoint that we can use to load the profiler UI. In this case we’re using the GlobalConfiguration.Configuration from the WebAPI Web Host package, but please note that you can also expose your own self hosted server in order to production profile a different types of projects, like a service, or what not…

Also note that we’re embedding the license file as an embedded resource in our project and we’re passing the license string to the Initialize method of the ProductionProfiling class. This is needed since the profiler is now split into to parts, the server – which is embedded right into your application and will run within your application own process, and the UI client which is a Silverlight application that you can get from the remote server through your browser. So again, the license string is passed and evaluated right from the server initialization process.

Now it’s time to run our project. I’m running it but get the following exception: …

Resource file is missing: ProductionProfilingOnAzureSample.App_Start.EntityFrameworkProfilerLicense.xml

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationException: Resource file is missing: ProductionProfilingOnAzureSample.App_Start.EntityFrameworkProfilerLicense.xml
Source Error:

Line 22: 			{
Line 23: 				if (sourceCodeStream == null)
Line 24: 					throw new InvalidOperationException(string.Format("Resource file is missing: {0}", sourcesResource));
Line 25: 				return new StreamReader(sourceCodeStream).ReadToEnd();
Line 26: 			}

Source File: c:\Users\Fitzchak\Documents\Visual Studio 11\Projects\ProductionProfilingOnAzureSample\ProductionProfilingOnAzureSample\App_Start\EntityFrameworkProfilerBootstrapper.cs    Line: 24

Remember what I told you? We need to embedded a license file. So let’s go and ask for a trial license file: http://hibernatingrhinos.com/products/efprof/trial.

After that I’m doing that, I got a trial license in my email inbox. Now we need to include this in the project as an embedded resource.


And now we are ready to see the profiler in action. Run the project and browse to the /profiler/profiler.html endpoint:


Do you see that? This is Entity Framework Profiler running right in your browser and let you profile your remote production application right from your computer!

You may be wonder why we do not see actual data in the profiler yet but this is your work to do. Attach it to your application and you’ll see some nice information that will let you understand what your ORM is doing easily.

Here is an example:

ScreenShots-EFProf-InBrowser (1)

Wait a second… Didn’t you said that we’re going to run this on Azure?

Yes, I added the following code to the HomeController and pushed the code to azure:

public class HomeController : Controller
    public ActionResult Index()
        for (int i = 0; i < 2; i++)
            using (var context = new ApplicationContext())

                context.Messages.Add(new Message {Text = "Text 1", CreatedAt = DateTime.UtcNow});

                var messages = context.Messages.ToList();

                var messages2 = context.Messages
                                        .Where(message => message.Text == "Profiling on Azure" && message.Text.Length > 10)
        return View();

You can run the above code by opening the following page,  http://efprof.cloudapp.net/, and see the profiler in action here: http://efprof.cloudapp.net/profiler/profiler.html.


For any feedback, please contact us in the profilers forums, by email (support at hibernatingrhinos.com) or just leave a comment here.


Posted By: Fitzchak Yitzchaki

Published at

Originally posted at


Jon Leigh
12/18/2012 02:01 PM by
Jon Leigh

Amazing, congrats!

Any plans for this to be made available to us on the Java stack?

01/10/2013 02:11 PM by


Excellent! This is a feature I've been waiting for.

I'm running in to trouble when giving this a quick try however.

I'm trying to enable this on an existing (.NET 4) web app that is using NHibernate (3.2).

First I installed the "NHibernate Profiler Production Profiling" NuGet package. I got compilation errors because System.Web.Http (referenced from NHibernateProfilerProductionBootstrapper) was missing.

After a little research I installed the "Microsoft ASP.NET Web API Web Host" NuGet package (+dependency packages). That fixed the initial error.

After adding the licence file as an embedded resource, compilation now fails with a number of log4net-errors, such as "Could not create Appender FooAppender of type [log4net.Appender.RollingFileAppender,log4net]" and then "Appender named [FooAppender] not found".

Looking in web.config, there are a lot of squiggly red underlinings in the log4net section. VS tells me that the log4net references used are ambiguous, and seems to find definitions in the log4net dll as well as the HibernatingRhinos.Profiler.Production dll.

Commenting out my log4net stuff gets rid of those errors but I remain with an "Exception has been thrown by the target of an invocation" (File error ASPRUNTIME) error.

Running aspnetcompiler with "-errorstack" tells me this (edited): [FileNotFoundException]: Could not load file or assembly 'NAppUpdate.Framework, Version=, Culture=neutral, PublicKeyToken=d1f1d1f19f9e5a56' or one of its dependencies. The system cannot find the file specified. at HibernatingRhinos.Profiler.Client.Infrastructure.AutoUpdate.ProfilerAutoUpdate..ctor(UserPreferences userPreferences) at HibernatingRhinos.Profiler.Client.Host.ClientService.Initialize() at HibernatingRhinos.Profiler.Production.ProductionProfiling.StartBackendInProccess() at HibernatingRhinos.Profiler.Production.ProductionProfiling.Initialize(String license, HttpConfiguration configuration) at InboxEDI.Web.AppStart.NHibernateProfilerProductionBootstrapper.PreStart() in ...\App_Start\NHibernateProfilerBootstrapper.cs:line 16

[TargetInvocationException]: Exception has been thrown by the target of an invocation. ... [InvalidOperationException]: The pre-application start initialization method Run on type WebActivator.ActivationManager threw an exception with the following error message: Exception has been thrown by the target of an invocation.. ... [HttpException]: The pre-application start initialization method Run on type WebActivator.ActivationManager threw an exception with the following error message: Exception has been thrown by the target of an invocation..

Any ideas? Did i miss some prerequisites or config?

01/10/2013 02:31 PM by

Just want to add that I wasn't doing anything Azure related. The web app is just running in local IIS.

Comments have been closed on this topic.