Miniprofiler on medium trust.. not working?

Hi there,

Miniprofiler doesn’t work with medium trust. We are using miniprofiler 3.0.10

Mvc 4.0, .Net 4.5.1 on shared hosting.

Error is here:

[NullReferenceException: Object reference not set to an instance of an object.]
StackExchange.Profiling.Settings…cctor() +813

What should we do?

We really need to find a solution for this issue. Otherwise we have to remove miniprofiler from our project.

Is there any way that you can push the pdb files up as well, so that we can get line numbers on the stack trace? (and is there any more to the stack trace than that one line)?

Where in your code is this thrown?

We have a plugin manager which loads plugins during application initialization. At this stage our product management plugin also being loaded and initialized and in its initialization code we have a miniprofiler step. It ıs workıng without a problem on full trust environment but it raises an error on shared hosting’s medium trust environment.

Error: The type initializer for ‘Settings’ threw an exception.

Stack Trace:
   at StackExchange.Profiling.MiniProfiler.Settings.EnsureProfilerProvider()
   at Yaziylabir.Extensions.B2C.BaseManagement.ProductManager.Initialize()

Is this explanation enough or do you need pdb file or more detail about error?

The line in question here is here

ProfilerProvider = new WebRequestProfilerProvider();

This itself leads here

public static void RegisterRoutes()
    var routes = RouteTable.Routes;
    var handler = new MiniProfilerHandler();
    var prefix = MiniProfiler.Settings.RouteBasePath.Replace("~/", string.Empty).EnsureTrailingSlash();

    using (routes.GetWriteLock())
        var route = new Route(prefix + "{filename}", handler)
            // specify these, so no MVC route helpers will match, e.g. @Html.ActionLink("Home", "Index", "Home")
            Defaults = new RouteValueDictionary(new { controller = "MiniProfilerHandler", action = "ProcessRequest" }),
            Constraints = new RouteValueDictionary(new { controller = "MiniProfilerHandler", action = "ProcessRequest" })

        // put our routes at the beginning, like a boss
        routes.Insert(0, route);

Within this - I have no idea what is getting messed up in Medium Trust. I would suggest that you experiment with making your own implementation of WebRequestProvider, starting with what we have there, and see if you can get it to work in medium trust. You can attach your implementation by setting MiniProfiler.Settings.ProfileProvider = NameOfYourProfileProvider before things get initialized. If you have a solution that works, please check back and we can see about integrating it with the main package (either by changing the existing WebRequestProvider or by adding a new MediumTrustWebRequestProvider).

You might want to also try adding <trust level="Medium" originUrl="" /> to the system.web section of your web.config to try it out locally on medium trust.

adding trust level to web.config is no option because of the hosting company’s configuration, it produces error.

By the way, after initialization Miniprofiler works perfectly on medium trust without a problem.

I think problem is here

By the way

catch {      location = HttpContext.Current.Server.MapPath("~/bin/MiniProfiler.dll"); }

in here could be used as System.Web.Hosting.HostingEnvironment.MapPath to ensure it works all the time. If there is no request (like during application initialization) it wont fail.

And more try catch blocks with manually thrown errors would be useful to get miniprofiler errors more readable on this constructor.

Sorry about my poor english, I don’t mean to be rude or smartass.

My suggestion was for you to add that to web.config on your local dev environment for testing purposes.

When adding links to github code pages, if you click on the line in the code, the url will change to be a link that will scroll directly to that line. This would be more helpful than just a link to the code page (or you could give a link to the code page, along with a line number if you like).

I am unclear if the MapPath comment is for your current issue, or if it is an additional item as well.

If you have a PR that you would like to submit with a fix that would work for medium trust, I would be happy to look it over.

Hi Ellis,

Thank you for informing me about the usage of github code pages.

I mentioned mappath as an additional item.

These days we will try to fix problems like this on our system, if we fix this issue about miniprofiler by changing miniprofiler codes, I will inform you about it.

Thank you again.