Spark views work initially, but then get a “Dynamic view compilation failed” error after 30 minutes or so

我与影子孤独终老i 提交于 2019-11-30 10:15:33

As qstarin mentioned, recycling the AppPool does seem to kick the assemblies out. Here's the original Spark discussion regarding the issue:

http://groups.google.com/group/spark-dev/browse_thread/thread/dbee06a0d1b2766f#

In general, it seems the issue is caused by Spark trying to compile the views BEFORE the AppPool has had time to load all of the assemblies.

Picking the assemblies one-by-one still seemed to cause random glitches for me, so I tweaked the code in that discussion post and load it as the first line in Application_Start(). Since then, I've pushed out a dozen or so applications over time and haven't seen the precompile issue once.

private void PreLoadAssemblies()
{
    // Deal with the compiling issue with Spark.
    var initialAssemblies = AppDomain.CurrentDomain.GetAssemblies();
    var di = new DirectoryInfo(Server.MapPath("~/bin"));
    var files = di.GetFiles("*.dll");
    foreach (var fi in files)
    {
        var found = false;
        //already loaded? 
        foreach (var asm in initialAssemblies)
        {
            var a = Assembly.ReflectionOnlyLoadFrom(fi.FullName);
            if (asm.FullName == a.FullName)
                found = true;
        }

        if (!found)
            Assembly.LoadFrom(fi.FullName);
    }
}

and then your Application_Start():

protected override void Application_Start(object sender, EventArgs e)
{
    PreLoadAssemblies();
    base.Application_Start(sender, e);

    //Whatever else you normally do in Application_Start():
    MvcHandler.DisableMvcResponseHeader = true;
    ViewEngineManager.Configure(ViewEngines.Engines);
    RouteManager.RegisterRoutes(RouteTable.Routes);
    new InjectionManager().StartNinject();
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!