0

I think I'm setting up ServiceStack's profiler correctly, but maybe I'm not. I'm just trying to get the basics in place.

What I've done so far

The only steps I 've taken so far to install profiling -- In Global.asax.cs:

   private void Application_BeginRequest(object sender, EventArgs e)
    {
        if (Request.IsLocal)
        {
            Profiler.Start();
        }
    }

    private void Application_EndRequest(object sender, EventArgs e)
    {
        Profiler.Stop();
    }

In my _SiteLayout.cshtml page, before any other javascript files are rendered, I attempt to render this:

<body>
<!-- ... -->

@Html.Raw(HttpUtility.HtmlDecode(Profiler.RenderIncludes().ToString()))

<!-- ...other scripts... -->
</body>

The Error I receive:

[NullReferenceException: Object reference not set to an instance of an object.]

ServiceStack.MiniProfiler.UI.MiniProfilerHandler.RenderIncludes(Profiler profiler, Nullable1 position, Nullable1 showTrivial, Nullable1 showTimeWithChildren, Nullable1 maxTracesToShow, Boolean xhtml, Nullable`1 showControls, String path) +293

ServiceStack.MiniProfiler.Profiler.RenderIncludes(Nullable1 position, Nullable1 showTrivial, Nullable1 showTimeWithChildren, Nullable1 maxTracesToShow, Boolean xhtml, Nullable`1 showControls) +99

....

Given that I'm trying to accomplish the basics, I'm unsure what could be null at this point. Is some sort of additional setup required prior to starting the profiler? Could it be a routing issue?

Community
  • 1
  • 1
SeanKilleen
  • 8,809
  • 17
  • 80
  • 133
  • As a note: I am generally new to ServiceStack, and we are mostly using it for the OrmLite functionality, so we may not have done other initial setup that the wiki may assume has already been done.. – SeanKilleen Apr 03 '14 at 15:38
  • @DourHighArch this has nothing to do with the concept of a NullReferenceException. It is me asking why in this specific case a library (which I can't see into) could be generating a nullReferenceException. This is a question as to what in the configuration could possibly be null at this point to generate an exception. I'd appreciate it if you'd remove the vote to close. – SeanKilleen Apr 03 '14 at 16:56
  • OK, but you have to edit the question for me to rescind my vote. Perhaps add some more of your .cshtml. Have you included `@ServiceStack.MiniProfiler.Profiler.RenderIncludes()`? – Dour High Arch Apr 03 '14 at 17:46
  • @DourHighArch I understand in general, but if you look in the middle of the question, I already specifically post the code that renders the includes. – SeanKilleen Apr 03 '14 at 17:53
  • To prevent gaming/trolling the site does not allow rescinding votes unless the question is edited. It's still a good idea to add more of your .cshtml; I suspect the problem is in code you haven't shown. Do you have any other classes in your project? IIRC they have to be registered in your global.aspx, host, DTD, or something. – Dour High Arch Apr 03 '14 at 18:28
  • @DourHighArch I will edit the question to enable you to rescind the votes; thanks! The only reason I wasn't more descriptive is that these are literally the only changes that I made in my attempt to add it. I will attempt to add more context around the .cshtml to at least indicate that I add it before the close of the body tag. – SeanKilleen Apr 03 '14 at 19:01

1 Answers1

1

The solution in this case seems to be to just use the standard MiniProfiler library instead of the one included with ServiceStack.

Initial Setup

In the Nuget package installer, I ran:

Install-Package MiniProfiler
Install-Package MiniProfiler.MVC4

I modified global.asax in the following ways:

private void Application_BeginRequest(object sender, EventArgs e)
{
        MiniProfiler.Start();
}

private void Application_AuthenticateRequest(object sender, EventArgs e)
{
     //stops the profiler if the user isn't on the tech team
    var currentUser = ClaimsPrincipal.Current.Identity as ClaimsIdentity;
    if (!Request.IsLocal && !currentUser.GetGlobalRoles().Contains(Constant.Roles.TechTeam))
    {
        MiniProfiler.Stop(discardResults:true);
    }
}

private void Application_EndRequest(object sender, EventArgs e)
{
    MiniProfiler.Stop();
}

Then, in my Layout.cshtml file, before the end of the body tag, I placed:

    @MiniProfiler.RenderIncludes()    

    </body>
</html>

Profiling a DB Connection

In the section of code that returns my OrmLiteConnectionFactory, I use the following code:

    private OrmLiteConnectionFactory claimFactory = new OrmLiteConnectionFactory(ConfigurationManager.ConnectionStrings["MyConnectionString"].ToString(), true, SqlServerDialect.Provider)
     {
         ConnectionFilter = x => new ProfiledDbConnection(x as System.Data.SqlClient.SqlConnection, MiniProfiler.Current)
     };

This seems to profile the SQL and connections just fine.

SeanKilleen
  • 8,809
  • 17
  • 80
  • 133