I am using throughout my NopCommerce website a component called BundleTransformer which extends the 'bundling' feature of MVC4. It uses another component called Yahoo.Yui.Compressing to transform and compress javascript files. All is working fine. JS files are compressed and bundled as expected.
However, there seems to be an issue with AntiForgeryToken. In my registration page, I added this simple line inside my form:
@Html.AntiForgeryToken()
This seems to conflict with Yahoo.Yui.Compressing. The error message I am getting is here below:
Cannot find embedded resource assembly named Yahoo.Yui.Compressor.Resources.Microsoft.IdentityModel.dll
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.DllNotFoundException: Cannot find embedded resource assembly named Yahoo.Yui.Compressor.Resources.Microsoft.IdentityModel.dll
Source Error:
Line 43: @using (Html.BeginForm())
Line 44: {
Line 45: @Html.AntiForgeryToken()
Line 46: <div class="page registration-page">
Line 47: <div class="page-body">
Source File: e:\www\....\TheWebsite\Themes\TheTheme\Views\Customer\Register.cshtml Line: 45
Stack Trace:
[DllNotFoundException: Cannot find embedded resource assembly named Yahoo.Yui.Compressor.Resources.Microsoft.IdentityModel.dll]
Yahoo.Yui.Compressor.AssemblyResolver.<Initialise>b__0(Object sender, ResolveEventArgs args) +248
System.AppDomain.OnAssemblyResolveEvent(RuntimeAssembly assembly, String assemblyFullName) +224
[FileLoadException: Could not load file or assembly 'Microsoft.IdentityModel, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. Could not find the specified DllImport Dll.]
System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMarkHandle stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName, ObjectHandleOnStack type) +0
System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName) +70
System.RuntimeType.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark) +39
System.Type.GetType(String typeName) +50
System.Web.Helpers.Claims.ClaimsIdentityConverter.GetDefaultConverters() +71
System.Web.Helpers.Claims.ClaimsIdentityConverter..cctor() +91
[TypeInitializationException: The type initializer for 'System.Web.Helpers.Claims.ClaimsIdentityConverter' threw an exception.]
System.Web.Helpers.Claims.ClaimsIdentityConverter.get_Default() +14
System.Web.Helpers.AntiForgery.CreateSingletonAntiForgeryWorker() +124
System.Web.Helpers.AntiForgery..cctor() +8
[TypeInitializationException: The type initializer for 'System.Web.Helpers.AntiForgery' threw an exception.]
System.Web.Helpers.AntiForgery.GetHtml() +45
System.Web.Mvc.HtmlHelper.AntiForgeryToken() +21
ASP._Page_Themes_CambridgeSatchel_Views_Customer_Register_cshtml.Execute() in e:\www\....\TheWebsite\Themes\TheTheme\Views\Customer\Register.cshtml:45
System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +199
System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +104
System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +78
System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance) +236
System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer) +107
System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +291
System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult) +13
System.Web.Mvc.<>c__DisplayClass1a.<InvokeActionResultWithFilters>b__17() +23
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +245
System.Web.Mvc.<>c__DisplayClass1c.<InvokeActionResultWithFilters>b__19() +22
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +245
System.Web.Mvc.<>c__DisplayClass1c.<InvokeActionResultWithFilters>b__19() +22
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +245
System.Web.Mvc.<>c__DisplayClass1c.<InvokeActionResultWithFilters>b__19() +22
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +245
System.Web.Mvc.<>c__DisplayClass1c.<InvokeActionResultWithFilters>b__19() +22
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +245
System.Web.Mvc.<>c__DisplayClass1c.<InvokeActionResultWithFilters>b__19() +22
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +245
System.Web.Mvc.<>c__DisplayClass1c.<InvokeActionResultWithFilters>b__19() +22
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +176
System.Web.Mvc.Async.<>c__DisplayClass2a.<BeginInvokeAction>b__20() +75
System.Web.Mvc.Async.<>c__DisplayClass25.<BeginInvokeAction>b__22(IAsyncResult asyncResult) +99
System.Web.Mvc.Async.WrappedAsyncResult`1.End() +50
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +27
System.Web.Mvc.<>c__DisplayClass1d.<BeginExecuteCore>b__18(IAsyncResult asyncResult) +14
System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +23
System.Web.Mvc.Async.WrappedAsyncResult`1.End() +55
System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +39
System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +23
System.Web.Mvc.Async.WrappedAsyncResult`1.End() +55
System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +29
System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +10
System.Web.Mvc.<>c__DisplayClass8.<BeginProcessRequest>b__3(IAsyncResult asyncResult) +25
System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +23
System.Web.Mvc.Async.WrappedAsyncResult`1.End() +55
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +31
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9629708
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155
Does anyone know the solution?
It seems to be a bug somewhere between Yahoo.Yui.Compressor, BundleTransformer or the AntiForgeryToken.
Upgrading to BundleTransformer 1.6.6 solves the problem.
There was a problem with BundleTransformer 1.6.5 and YUI Compressor .NET 2.1.0.0 that was fixed in the last release (See Taritsyn comment on http://bundletransformer.codeplex.com/discussions/398013/)