diff --git a/src/Orchard.Web/Global.asax.cs b/src/Orchard.Web/Global.asax.cs index 761432803..519a345f7 100644 --- a/src/Orchard.Web/Global.asax.cs +++ b/src/Orchard.Web/Global.asax.cs @@ -1,12 +1,11 @@ -using System.Collections.Generic; -using System.Linq; +using System; +using System.Collections.Generic; +using System.IO; +using System.Reflection; using System.Web; using System.Web.Mvc; using System.Web.Routing; -using Autofac; using Autofac.Builder; -using Autofac.Integration.Web; -using Autofac.Modules; using Orchard.Environment; namespace Orchard.Web { @@ -40,16 +39,61 @@ namespace Orchard.Web { } protected void Application_Start() { + // This is temporary until MVC2 is officially released. + // We want to avoid running against an outdated preview installed in the GAC + CheckMvcVersion(new Version("2.0.41116.0")/*MVC2 Beta file version #*/); RegisterRoutes(RouteTable.Routes); - - _host = OrchardStarter.CreateHost(MvcSingletons); _host.Initialize(); //TODO: what's the failed initialization story - IoC failure in app start can leave you with a zombie appdomain } + private void CheckMvcVersion(Version requiredVersion) { + Assembly loadedMvcAssembly = typeof(System.Web.Mvc.Controller).Assembly; + Version loadedMvcVersion = ReadAssemblyFileVersion(loadedMvcAssembly); + + if (loadedMvcVersion != requiredVersion) { + string message; + if (loadedMvcAssembly.GlobalAssemblyCache) { + message = string.Format( + "Orchard has been deployed with a version of {0} that has a different file version ({1}) " + + "than the version installed in the GAC ({2}).\r\n" + + "This implies that Orchard will not be able to run properly in this machine configuration.\r\n" + + "Please un-install MVC from the GAC or install a more recent version.", + loadedMvcAssembly.GetName().Name, + loadedMvcVersion, + requiredVersion); + } + else { + message = string.Format( + "Orchard has been configured to run with a file version {1} of \"{0}\" " + + "but the version deployed with the application is {2}.\r\n" + + "This probably implies that Orchard is deployed with a newer version " + + "and the source code hasn't been updated accordingly.\r\n" + + "Update the Orchard.Web application source code (look for \"CheckMvcVersion\") to " + + "specify the correct file version number.\r\n", + loadedMvcAssembly.GetName().Name, + loadedMvcVersion, + requiredVersion); + } + + throw new HttpException(500, message); + } + } + + private Version ReadAssemblyFileVersion(Assembly assembly) { + object[] attributes = assembly.GetCustomAttributes(typeof(AssemblyFileVersionAttribute), true); + if (attributes == null || attributes.Length != 1) { + string message = string.Format("Assembly \"{0}\" doesn't have a \"{1}\" attribute", + assembly.GetName().Name, typeof(AssemblyFileVersionAttribute).FullName); + throw new FileLoadException(message); + } + + var attribute = (AssemblyFileVersionAttribute)attributes[0]; + return new Version(attribute.Version); + } protected void Application_EndRequest() { _host.EndRequest(); diff --git a/src/Orchard.Web/Orchard.Web.csproj b/src/Orchard.Web/Orchard.Web.csproj index c5bd99e4a..242135c87 100644 --- a/src/Orchard.Web/Orchard.Web.csproj +++ b/src/Orchard.Web/Orchard.Web.csproj @@ -62,6 +62,7 @@ False ..\..\lib\aspnetmvc\System.Web.Mvc.dll + True 3.5