BlogEngine.Net 2.0 on a .Net 4 Host

Topics: ASP.NET 2.0
Mar 11, 2011 at 8:03 PM

Hello,

I think the title says it all.  But here is a slight description of what I am doing.

I have a MVC 3 site that works great.  Thanks to a Scott Hanselman article I see that I can even add ASP.Net pages to my site with a slight Routing update.  That too works great.

What I want to do is have a /Blog folder contain BE 2.0.  I know I had to create a new application start point and it needs a different App Pool that is using .Net 2.0/3/3.5SP1.  Locally it works great.

On my hosting site I can only have 1 App Pool and there inlies the problem.

So, is there a way to have a .Net 4 application running BE 2?

Thanks,
Kevin

Coordinator
Mar 11, 2011 at 9:01 PM

Sure, try this link.

Mar 14, 2011 at 6:53 PM

Aah, I was so happy to see there was an actual article on this.  I thought I was good to go.  Seems so close.  It ran in 3.5.  Made the changes for 4 and it builds.  However, when I run it I get the following error.  If it means anything, I am on VS2010 SP1.  THANK you for the quck resonse.

Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.

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.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.

Source Error:

Line 453:            foreach (Assembly a in codeAssemblies)
Line 454:            {
Line 455:                var types = a.GetTypes();
Line 456:                foreach (var type in types)
Line 457:                {


Source File: C:\Users\kgrigsby\Documents\Visual Studio 2010\Projects\BlogEngine Source Code\blogengine_f1a45ac8058e\BlogEngine\DotNetSlave.BusinessLogic\Web\Extensions\ExtensionManager.cs Line: 455

Stack Trace:

[ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.]
   System.Reflection.RuntimeModule.GetTypes(RuntimeModule module) +0
   System.Reflection.RuntimeModule.GetTypes() +4
   System.Reflection.Assembly.GetTypes() +78
   BlogEngine.Core.Web.Extensions.ExtensionManager.LoadExtensions() in C:\Users\kgrigsby\Documents\Visual Studio 2010\Projects\BlogEngine Source Code\blogengine_f1a45ac8058e\BlogEngine\DotNetSlave.BusinessLogic\Web\Extensions\ExtensionManager.cs:455
   BlogEngine.Core.Web.Extensions.ExtensionManager.ExtensionEnabled(String extensionName) in C:\Users\kgrigsby\Documents\Visual Studio 2010\Projects\BlogEngine Source Code\blogengine_f1a45ac8058e\BlogEngine\DotNetSlave.BusinessLogic\Web\Extensions\ExtensionManager.cs:108
   BlogEngine.Core.Utils.<LoadExtensions>b__20(SortedExtension x) in C:\Users\kgrigsby\Documents\Visual Studio 2010\Projects\BlogEngine Source Code\blogengine_f1a45ac8058e\BlogEngine\DotNetSlave.BusinessLogic\Utils.cs:961
   System.Linq.WhereListIterator`1.MoveNext() +58
   BlogEngine.Core.Utils.LoadExtensions() in C:\Users\kgrigsby\Documents\Visual Studio 2010\Projects\BlogEngine Source Code\blogengine_f1a45ac8058e\BlogEngine\DotNetSlave.BusinessLogic\Utils.cs:961
   ASP.global_asax.Application_Start(Object sender, EventArgs e) in c:\Users\kgrigsby\Documents\Visual Studio 2010\Projects\BlogEngine Source Code\blogengine_f1a45ac8058e\BlogEngine\BlogEngine.NET\Global.asax:72



Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.225

<!-- [ReflectionTypeLoadException]: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information. at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module) at System.Reflection.RuntimeModule.GetTypes() at System.Reflection.Assembly.GetTypes() at BlogEngine.Core.Web.Extensions.ExtensionManager.LoadExtensions() in C:\Users\kgrigsby\Documents\Visual Studio 2010\Projects\BlogEngine Source Code\blogengine_f1a45ac8058e\BlogEngine\DotNetSlave.BusinessLogic\Web\Extensions\ExtensionManager.cs:line 455 at BlogEngine.Core.Web.Extensions.ExtensionManager.ExtensionEnabled(String extensionName) in C:\Users\kgrigsby\Documents\Visual Studio 2010\Projects\BlogEngine Source Code\blogengine_f1a45ac8058e\BlogEngine\DotNetSlave.BusinessLogic\Web\Extensions\ExtensionManager.cs:line 108 at BlogEngine.Core.Utils.<LoadExtensions>b__20(SortedExtension x) in C:\Users\kgrigsby\Documents\Visual Studio 2010\Projects\BlogEngine Source Code\blogengine_f1a45ac8058e\BlogEngine\DotNetSlave.BusinessLogic\Utils.cs:line 961 at System.Linq.Enumerable.WhereListIterator`1.MoveNext() at BlogEngine.Core.Utils.LoadExtensions() in C:\Users\kgrigsby\Documents\Visual Studio 2010\Projects\BlogEngine Source Code\blogengine_f1a45ac8058e\BlogEngine\DotNetSlave.BusinessLogic\Utils.cs:line 961 at ASP.global_asax.Application_Start(Object sender, EventArgs e) in c:\Users\kgrigsby\Documents\Visual Studio 2010\Projects\BlogEngine Source Code\blogengine_f1a45ac8058e\BlogEngine\BlogEngine.NET\Global.asax:line 72 -->
Mar 14, 2011 at 6:59 PM

If it helps, when I ran it again (no changes) it worked.  Seems like each time I do a Rebuild, then run I get the error.  But then run again debug or not and it works.

Coordinator
Mar 14, 2011 at 7:19 PM

Did you do step 1 - download fresh code from suggested change set? There were few fixes after final 2.0 release related to .net 4.0 complience, including fixing that error you running into.

Mar 14, 2011 at 7:29 PM

Yes.  This is the version I got: blogengine_f1a45ac8058e

Mar 14, 2011 at 8:24 PM

BTW - I figured since it seemed to work the 2nd time after each Rebuild I figured I would push it.  Expect the error but then just run it again and be fine.  Well, no such luck.  Here is what I get on my site where I have a /Blog folder.  It's the same error, just seems one place up in the stack.

 

Server Error in '/Blog' Application.

Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.

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.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.

Source Error:

Line 70:     void Application_Start(object sender, EventArgs e)
Line 71:     {
Line 72:         Utils.LoadExtensions();
Line 73:     }
Line 74: 


Source File: e:\web\screami1\Blog\Global.asax Line: 72

Stack Trace:

[ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.]
   System.Reflection.RuntimeModule.GetTypes(RuntimeModule module) +0
   System.Reflection.RuntimeModule.GetTypes() +4
   System.Reflection.Assembly.GetTypes() +78
   BlogEngine.Core.Web.Extensions.ExtensionManager.LoadExtensions() in C:\Users\kgrigsby\Documents\Visual Studio 2010\Projects\BlogEngine Source Code\blogengine_f1a45ac8058e\BlogEngine\DotNetSlave.BusinessLogic\Web\Extensions\ExtensionManager.cs:455
   BlogEngine.Core.Web.Extensions.ExtensionManager.ExtensionEnabled(String extensionName) in C:\Users\kgrigsby\Documents\Visual Studio 2010\Projects\BlogEngine Source Code\blogengine_f1a45ac8058e\BlogEngine\DotNetSlave.BusinessLogic\Web\Extensions\ExtensionManager.cs:108
   BlogEngine.Core.Utils.<LoadExtensions>b__20(SortedExtension x) in C:\Users\kgrigsby\Documents\Visual Studio 2010\Projects\BlogEngine Source Code\blogengine_f1a45ac8058e\BlogEngine\DotNetSlave.BusinessLogic\Utils.cs:961
   System.Linq.WhereListIterator`1.MoveNext() +58
   BlogEngine.Core.Utils.LoadExtensions() in C:\Users\kgrigsby\Documents\Visual Studio 2010\Projects\BlogEngine Source Code\blogengine_f1a45ac8058e\BlogEngine\DotNetSlave.BusinessLogic\Utils.cs:961
   ASP.global_asax.Application_Start(Object sender, EventArgs e) in e:\web\screami1\Blog\Global.asax:72

[HttpException (0x80004005): Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.]
   System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) +421
   System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +124
   System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +182
   System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +339
   System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +181

[HttpException (0x80004005): Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.]
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +543
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +90
   System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +191



Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1

<!-- [ReflectionTypeLoadException]: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information. at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module) at System.Reflection.RuntimeModule.GetTypes() at System.Reflection.Assembly.GetTypes() at BlogEngine.Core.Web.Extensions.ExtensionManager.LoadExtensions() in C:\Users\kgrigsby\Documents\Visual Studio 2010\Projects\BlogEngine Source Code\blogengine_f1a45ac8058e\BlogEngine\DotNetSlave.BusinessLogic\Web\Extensions\ExtensionManager.cs:line 455 at BlogEngine.Core.Web.Extensions.ExtensionManager.ExtensionEnabled(String extensionName) in C:\Users\kgrigsby\Documents\Visual Studio 2010\Projects\BlogEngine Source Code\blogengine_f1a45ac8058e\BlogEngine\DotNetSlave.BusinessLogic\Web\Extensions\ExtensionManager.cs:line 108 at BlogEngine.Core.Utils.<LoadExtensions>b__20(SortedExtension x) in C:\Users\kgrigsby\Documents\Visual Studio 2010\Projects\BlogEngine Source Code\blogengine_f1a45ac8058e\BlogEngine\DotNetSlave.BusinessLogic\Utils.cs:line 961 at System.Linq.Enumerable.WhereListIterator`1.MoveNext() at BlogEngine.Core.Utils.LoadExtensions() in C:\Users\kgrigsby\Documents\Visual Studio 2010\Projects\BlogEngine Source Code\blogengine_f1a45ac8058e\BlogEngine\DotNetSlave.BusinessLogic\Utils.cs:line 961 at ASP.global_asax.Application_Start(Object sender, EventArgs e) in e:\web\screami1\Blog\Global.asax:line 72 [HttpException]: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information. at System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) at System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) at System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) at System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) at System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) [HttpException]: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information. at System.Web.HttpRuntime.FirstRequestInit(HttpContext context) at System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) at System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) --><!-- This error page might contain sensitive information because ASP.NET is configured to show verbose error messages using <customErrors mode="Off"/>. Consider using <customErrors mode="On"/> or <customErrors mode="RemoteOnly"/> in production environments.-->
Coordinator
Mar 14, 2011 at 8:33 PM

I'll check this out later today. I remember fixing this error a while ago, may be in the fork.

Coordinator
Mar 15, 2011 at 5:40 AM

To fix this error you need to modify this function in Utils.cs in the core project, just replace what you have with code below.

 

private static IEnumerable<Assembly> GetCompiledExtensions()
{
   var assemblies = new List<Assembly>();
   var s = Path.Combine(HttpContext.Current.Server.MapPath("~/"), "bin");
   var fileEntries = Directory.GetFiles(s);
     foreach (var asm in from fileName in fileEntries
            where fileName.EndsWith(".dll", StringComparison.OrdinalIgnoreCase)
            select Assembly.LoadFrom(fileName)
            into asm
            let attr = asm.GetCustomAttributes(typeof(AssemblyConfigurationAttribute), false)
            where attr.Length > 0
            let aca = (AssemblyConfigurationAttribute)attr[0]
            where aca != null && aca.Configuration == "BlogEngineExtension"
            select asm)
     {
        assemblies.Add(asm);
     }
  return assemblies;
}

 

 

GetCompiledExtensions
Mar 15, 2011 at 3:40 PM
That did the trick!
Thank you So much for taking your time and making this work.

Now I have to start blogging. :)

Thanks again,
Kevin


I don't fear death, but I sure don't like those three footers for par.




From: [email removed]
To: [email removed]
Date: Mon, 14 Mar 2011 21:40:14 -0700
Subject: Re: BlogEngine.Net 2.0 on a .Net 4 Host [blogengine:249371]

From: rtur
To fix this error you need to modify this function in Utils.cs in the core project, just replace what you have with code below.

private static IEnumerable<Assembly> GetCompiledExtensions()
{
   var assemblies = new List<Assembly>();
   var s = Path.Combine(HttpContext.Current.Server.MapPath("~/"), "bin");
   var fileEntries = Directory.GetFiles(s);
     foreach (var asm in from fileName in fileEntries
            where fileName.EndsWith(".dll", StringComparison.OrdinalIgnoreCase)
            select Assembly.LoadFrom(fileName)
            into asm
            let attr = asm.GetCustomAttributes(typeof(AssemblyConfigurationAttribute), false)
            where attr.Length > 0
            let aca = (AssemblyConfigurationAttribute)attr[0]
            where aca != null && aca.Configuration == "BlogEngineExtension"
            select asm)
     {
        assemblies.Add(asm);
     }
  return assemblies;
}


GetCompiledExtensions
Read the full discussion online.
To add a post to this discussion, reply to this email (blogengine@discussions.codeplex.com)
To start a new discussion for this project, email blogengine@discussions.codeplex.com
You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on CodePlex.com.
Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at CodePlex.com