.NET and Open Source: better together


  • Join Us on Facebook!
  • Follow Us on Twitter!
  • LinkedIn
  • Subcribe to Our RSS Feed

Using BlogEngine.NET 2.0 with .NET 4.0 framework

BlogEngine 2.0 is .NET 3.5 application, but you can use it with .NET framework 4.0 with little effort by compiling source code as .NET 4.0 assembly. You can do it with free Visual Web Developer Express 2010 which can be downloaded as stand alone or installed with MS web platform installer, whichever you prefer. Here is short walk through.

Initial setup

At first we want to set up and compile default .NET 3.5 install to make sure we not missing files, download is not corrupted etc. Just a precaution.

  1. Get latest source code here. Click download latest version link in the right side bar and pull zip file to your local drive.
  2. Unzip it to any local directory, launch VS or web developer and open solution file (BlogEngine/BlogEngine.sln).
  3. Right-click BlogEngine.Net project in the solution explorer and click “set as startup project”, then right-click default.aspx and click “set as start page”.
  4. Ctrl+F5 to build and run the project just to make sure all set up properly. You should see BlogEngine site running in your default browser.

.NET 4.0 tweaks

Now as you got default 3.5 install running, lets set it up to use .NET 4.0 instead.

1. Right click BlogEngine.Core project in solution explorer and select “properties”. In the properties dialog, change target framework from 3.5 to 4.0. Click ok and confirm selection.


2. Right click website project and select “property pages”. Also change it from 3.5 to 4.0.


3. Again right-click Core project and select “add reference”. In the add reference dialog, select System.Web.ApplicationServices namespace to add it to the project references. We need this due to slight change in the ASP.NET membership interface in .NET 4.0, otherwise you’ll get lots of compilation errors about namespaces not found.


4. Open setup/ASP.NET_4.0_Web.Config and copy all its content, then open Web.Config and paste it there to override existing configuration file. Save all.

5. Click Ctrl+F5 to build the project. Application should compile as .NET 4.0 with no errors.


If all went well, you are ready to deploy project to any .NET 4.0 web hosting. To run it on the host, you’ll need to copy (FTP) all files in the BlogEngine.Net folder to directory that configured as web application and set write permissions on App_Data folder in the hosting site. In the next post we’ll deploy it to GoDaddy shared hosting running .NET 4.0 as an example.


If you get"Unable to load one or more of the requested types" error, 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)
  return assemblies;

Comments (15) -

  • Ben Amada

    12/22/2010 2:30:11 PM |

    It's probably worth mentioning that the .NET 3.5 compiled BlogEngine.Core.dll will work under .NET 4.0 without being recompiled.  There are BE users running 2.0 RC with the .NET 3.5 compiled DLL (including myself, just during testing).  It's noted at the link below that:

    "Compiled (binary) files that were created using earlier versions of ASP.NET will also run without errors on ASP.NET 4"


    But if the person is going to be doing development with BE 2.0 and .NET 4.0, then this recompilation to .NET 4.0 is of course a very good idea.

    • Jon

      4/23/2011 1:30:48 AM |

      For some reason, I'm having issues using the ASP.NET Admin panel to add users to the site... It's having issues with the web.config line pertaining to the XmlRoleProvider.

      Any ideas on how I can fix this problem? IIS is working, and the blog appears to be rendering just fine, but I can't add administrators or editors to get this thing deployable.

  • rtur.net

    12/22/2010 2:42:52 PM |

    Yes, agree. Or, as in my case - when you need integration with another application that uses .NET 4.0

  • rossisdead

    12/23/2010 8:59:55 AM |

    Just make sure to point out that people who commit changes to the project shouldn't commit the project as .Net 4, or include .Net 4 specific features!

  • Daniel

    12/31/2010 11:55:45 AM |

    Thank you for your help. I followed your directions on discountASP.net and it worked well. This was my first time ever to work with ASP pages and Visual Studio and the hosting service and am pleased that things went quite well. Thank you.

  • Kris Golko

    1/5/2011 3:46:51 AM |

    Hi Ruslan,

    Perhaps you could explain the changes to web.config and why are they are necessary?


    • rtur.net

      1/5/2011 5:14:23 AM |

      I haven't look into it closely yet, just took configuration file created by Ben and use it. I've seen discussions on Codeplex where people were running into issues with .net 4.0 and this config file was created based on those issues and supposed to fix them.
      Wanted link to discussion thread, but couldn't find - search function on Codeplex useless, sometimes I feel as getting random results.

      • Kris Golko (neuromancer)

        1/12/2011 11:42:53 AM |

        It worked for me without any modification while using ASP.NET 4.0 Classic. Switching to ASP.NET 4.0 gave the bloody mess as reported on Codeplex (related to "rights" attribute in the sitemap.


  • J Hamnlin

    1/22/2011 11:30:26 AM |

    I am now running 4 blog engine sites on Server 2008 R2 with IIS 7.5 and ASP 4.  The system uses Plesk which made a few things tricky.

    1)  The new version of Blog Engine includes an ASP.NET 4 web config. file.  Use it and it works perfectly.
    2)  If running Plesk be sure the Plesk WP User is the account that has write access to the 'ap data' folder.

    Check out the site:  www.greenbenefits.org - ASP.NET4.


  • George Fahnbulleh

    3/19/2011 12:25:08 AM |

    Thanks for this post.

    I get an error: Unable to load one or more of the requested types

    • rtur.net

      3/19/2011 3:54:30 AM |

      I've added update to the post about this error. It could be that I made this change just to the fork I've been working with or it got overridden later on.

  • George Fahnbulleh

    3/20/2011 11:35:12 AM |

    Ruslan, thank you very much.  Works like a charm!

  • Richard McSharry

    4/1/2011 3:09:49 AM |

    Thanks so much, got me up and running without a hitch! Much appreciated.

  • George Fahnbulleh

    5/8/2011 9:10:03 AM |


    I downloaded the latest build for 2.5.  I opened the solution in VS2010 and compiled. Everything went well.

    Moved it over to my host, ran the SQL 2.5 script.  Page comes up, but it will not login.

    Any suggestions?

    • rtur.net

      5/11/2011 10:55:56 AM |

      Make sure you are using database provider for Membership and Roles in the web.config. Although, Ben is still working on 2.5 scripts - could be something he did not implemented yet.

Pingbacks and trackbacks (2)+

Comments are closed