model-view-controllersitecoresitecore-mvcsitecore8.2

Sitecore 8.2 MVC can't get MVC bundles to work


I have been trying to set up Sitecore 8.2 MVC and use the MVC bundle to pull all my scripts and styles on to the main layout. I have been running into issues since the global file is no longer being used and best practices I should be initializing the buldler using the pipeline.

BundleConfig.cs

using System.Web;
using System.Web.Optimization;
using Sitecore;
using Sitecore.Pipelines;

namespace MySite.Web.Pipelines
{

    public class RegisterPlatformBundles
    {
        [UsedImplicitly]
        public virtual void Process(PipelineArgs args)
        {
            RegisterBundles(BundleTable.Bundles);
        }
        private void RegisterBundles(BundleCollection bundles)
        {
            bundles.Add(new StyleBundle("~/bundles/styles").Include(
                      "~/Content/bootstrap.css",
                      "~/Content/site.css"));

        }

    }

I tried to add it to the pipeline withthe following config file.

<?xml version="1.0"?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <pipelines>
      <initialize>
        <processor patch:before="processor[@type='Sitecore.Mvc.Pipelines.Loader.InitializeGlobalFilters, Sitecore.Mvc']"
           type="MySite.Web.Pipelines.RegisterPlatformBundles, MySite" />
      </initialize>
    </pipelines>
  </sitecore>
</configuration>

I get the following error when I try to run the site. Any advice or even just the right path to help me set this up would be great. Thanks.

Could not resolve type name: MySite.Web.Pipelines.RegisterPlatformBundles, MySite (method: Sitecore.Configuration.DefaultFactory.CreateFromTypeName(XmlNode configNode, String[] parameters, Boolean assert)). 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.Exception: Could not resolve type name: MySite.Web.Pipelines.RegisterPlatformBundles, MySite (method: Sitecore.Configuration.DefaultFactory.CreateFromTypeName(XmlNode configNode, String[] parameters, Boolean assert)).

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[Exception: Could not resolve type name: MySite.Web.Pipelines.RegisterPlatformBundles, MySite (method: Sitecore.Configuration.DefaultFactory.CreateFromTypeName(XmlNode configNode, String[] parameters, Boolean assert)).]
Sitecore.Diagnostics.Error.Raise(String error, String method) +137
Sitecore.Configuration.DefaultFactory.CreateType(XmlNode configNode, String[] parameters, Boolean assert) +308
Sitecore.Configuration.DefaultFactory.CreateFromTypeName(XmlNode configNode, String[] parameters, Boolean assert) +71
Sitecore.Configuration.DefaultFactory.CreateObject(XmlNode configNode, String[] parameters, Boolean assert, IFactoryHelper helper) +165
Sitecore.Configuration.DefaultFactory.CreateObject(XmlNode configNode, Boolean assert) +68
Sitecore.Pipelines.CorePipelineFactory.GetObjectFromType(XmlNode processorNode) +91
Sitecore.Pipelines.CorePipelineFactory.GetProcessorObject(XmlNode processorNode) +145
Sitecore.Pipelines.CoreProcessor.GetMethod(Object[] parameters) +144
Sitecore.Pipelines.CorePipeline.Run(PipelineArgs args) +470
Sitecore.Pipelines.DefaultCorePipelineManager.Run(String pipelineName, PipelineArgs args, String pipelineDomain) +22
Sitecore.Nexus.Web.HttpModule.Application_Start() +262
Sitecore.Nexus.Web.HttpModule.Init(HttpApplication app) +704
System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +618
System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +172
System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +402
System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +343

[HttpException (0x80004005): Could not resolve type name: MySite.Web.Pipelines.RegisterPlatformBundles, MySite (method: Sitecore.Configuration.DefaultFactory.CreateFromTypeName(XmlNode configNode, String[] parameters, Boolean assert)).]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +539
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +125 System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +731


Solution

  • I have tested the provided code and the main reason why you are receiving this error is because the assembly Mysite is not present in the bin folder.

    1. Make sure that the MySite.dll is copied to the bin folder.
    2. Namespace MySite.Web.Pipelines.RegisterPlatformBundles, MySite is valid