This project has moved. For the latest updates, please go here.
1

Resolved

WebMarkupMin and HTML_PARSING_ERROR

description

Hello. Can you help to deal with error:
I have an action:
[HttpGet]
[MinifyHtml]
public ActionResult GetTariffExtendings(Guid tariffCode)
{
    var model = ... get the model

    return PartialView("Partials/TariffExtendings", model);
}
Partial View loaded with GET AJAX request.
Without minification all work, but when turn on — HTML_PARSING_ERROR.
I have no idea what's wrong. Double check markup.
Example of uncompressed output: ...

Configuration in web.config
<webMarkupMin xmlns="http://tempuri.org/WebMarkupMin.Configuration.xsd">
        <core>
            <html whitespaceMinificationMode="Aggressive" collapseBooleanAttributes="false" removeRedundantAttributes="false" minifyEmbeddedCssCode="true" minifyInlineCssCode="true" minifyEmbeddedJsCode="true" minifyInlineJsCode="true" processableScriptTypeList="text/html" minifyKnockoutBindingExpressions="true" />
            <css defaultMinifier="MsAjaxCssMinifier">
                <minifiers>
                    <add name="MsAjaxCssMinifier" displayName="Microsoft Ajax CSS Minifier" type="WebMarkupMin.MsAjax.Minifiers.MsAjaxCssMinifier, WebMarkupMin.MsAjax" />
                    <add name="NullCssMinifier" displayName="Null CSS Minifier" type="WebMarkupMin.Core.Minifiers.NullCssMinifier, WebMarkupMin.Core" />
                    <add name="KristensenCssMinifier" displayName="Mads Kristensen's CSS minifier" type="WebMarkupMin.Core.Minifiers.KristensenCssMinifier, WebMarkupMin.Core" />
                </minifiers>
            </css>
            <js defaultMinifier="MsAjaxJsMinifier">
                <minifiers>
                    <add name="MsAjaxJsMinifier" displayName="Microsoft Ajax JS Minifier" type="WebMarkupMin.MsAjax.Minifiers.MsAjaxJsMinifier, WebMarkupMin.MsAjax" />
                    <add name="NullJsMinifier" displayName="Null JS Minifier" type="WebMarkupMin.Core.Minifiers.NullJsMinifier, WebMarkupMin.Core" />
                    <add name="CrockfordJsMinifier" displayName="Douglas Crockford's JS Minifier" type="WebMarkupMin.Core.Minifiers.CrockfordJsMinifier, WebMarkupMin.Core" />
                </minifiers>
            </js>
            <logging defaultLogger="ThrowExceptionLogger">
                <loggers>
                    <add name="NullLogger" displayName="Null Logger" type="WebMarkupMin.Core.Loggers.NullLogger, WebMarkupMin.Core" />
                    <add name="ThrowExceptionLogger" displayName="Throw exception logger" type="WebMarkupMin.Core.Loggers.ThrowExceptionLogger, WebMarkupMin.Core" />
                </loggers>
            </logging>
        </core>
        <webExtensions disableMinificationInDebugMode="false" disableCompressionInDebugMode="false" enableMinification="true" enableCompression="true" maxResponseSize="200000" disableCopyrightHttpHeaders="true" />
    </webMarkupMin>
Temporary set <logging defaultLogger="NullLogger">, which not shown an exception, but response is not minified.

Using:
WebMarkupMin.Core 1.1.0
WebMarkupMin.MsAjax 1.0.0
WebMarkupMin.Mvc 1.1.0
WebMarkupMin.Web 1.1.1

comments

Taritsyn wrote Apr 18, 2016 at 1:29 PM

Hello, Modex!

I could not reproduce your error. Send me full text of error message.

Modex wrote Apr 18, 2016 at 1:33 PM

Ошибка сервера в приложении '/DocShellWeb.Lk'.

Category: HTML_PARSING_ERROR
Message: During parsing of HTML-code error has occurred.
File: /DocShellWeb.Lk/IndentificationCenterAgent/GetTariffExtendings?tariffCode=b296dc66-43ae-4249-93e9-b86294d625d1
Line number: 1
Column number: 107
Source fragment:

Line 1: …@�흼��{���{���;�N'���?\fdl��J�ɞ!���?~|?"~�D�{<+.�i�5�g�EӦ�U�ؾ���꣣�8��{<�?�����o�����o��…
--------------------------------------------------------^
Line 2: …��ٲJ��������.��h��H�/�eD������������n?���~3]�\O��)��ܾ?y���v��`w�� �9?����`


Описание: Необработанное исключение при выполнении текущего веб-запроса. Изучите трассировку стека для получения дополнительных сведений о данной ошибке и о вызвавшем ее фрагменте кода. 

Сведения об исключении: WebMarkupMin.Core.Minifiers.MarkupMinificationException: Category: HTML_PARSING_ERROR
Message: During parsing of HTML-code error has occurred.
File: /DocShellWeb.Lk/IndentificationCenterAgent/GetTariffExtendings?tariffCode=b296dc66-43ae-4249-93e9-b86294d625d1
Line number: 1
Column number: 107
Source fragment:

Line 1: …@�흼��{���{���;�N'���?\fdl��J�ɞ!���?~|?"~�D�{<+.�i�5�g�EӦ�U�ؾ���꣣�8��{<�?�����o�����o��…
--------------------------------------------------------^
Line 2: …��ٲJ��������.��h��H�/�eD������������n?���~3]�\O��)��ܾ?y���v��`w�� �9?����`



Ошибка источника: 

Необработанное исключение при выполнении текущего веб-запроса. Информацию о происхождении и месте возникновения исключения можно получить, используя следующую трассировку стека исключений.

Трассировка стека: 


[MarkupMinificationException: Category: HTML_PARSING_ERROR
Message: During parsing of HTML-code error has occurred.
File: /DocShellWeb.Lk/IndentificationCenterAgent/GetTariffExtendings?tariffCode=b296dc66-43ae-4249-93e9-b86294d625d1
Line number: 1
Column number: 107
Source fragment:

Line 1: …@�흼��{���{���;�N'���?\fdl��J�ɞ!���?~|?"~�D�{<+.�i�5�g�EӦ�U�ؾ���꣣�8��{<�?�����o�����o��…
--------------------------------------------------------^
Line 2: …��ٲJ��������.��h��H�/�eD������������n?���~3]�\O��)��ܾ?y���v��`w�� �9?����`

]
   WebMarkupMin.Core.Loggers.ThrowExceptionLogger.Error(String category, String message, String filePath, Int32 lineNumber, Int32 columnNumber, String sourceFragment) +746
   WebMarkupMin.Core.Minifiers.GenericHtmlMinifier.Minify(String content, String fileContext, Encoding encoding, Boolean generateStatistics) +1305
   WebMarkupMin.Web.Filters.MarkupMinificationFilterStreamBase`1.Close() +158
   System.Web.HttpWriter.FilterIntegrated(Boolean finalFiltering, IIS7WorkerRequest wr) +701
   System.Web.HttpResponse.FilterOutput() +118
   System.Web.CallFilterExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +62
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +92

Modex wrote Apr 18, 2016 at 1:49 PM

Trying different combinations found interesting:

Action for opening page
[MinifyHtml, CompressContent]
public ActionResult CreateRequestAgent(int idClient)
{
    var model = ... loading parent page model

    return View(model);
}
On this page with AJAX-request loading partial.
If I add to GetTariffExtendings action [CompressContent] attribute all loaded without errors!

Taritsyn wrote Apr 18, 2016 at 1:57 PM

It is difficult to determine cause of this error. Try turning off HTTP compression.

P.S.: Remove your example, because it contains confidential information.

Taritsyn wrote Apr 18, 2016 at 3:04 PM

If I add to GetTariffExtendings action [CompressContent] attribute all loaded without errors!
It is possible, that you have HTTP compression on IIS level.

Taritsyn wrote Apr 18, 2016 at 5:27 PM

I made an example of using @Ajax.ActionLink and everything working (in all combinations).

Modex wrote Apr 19, 2016 at 5:45 AM

Yes I have in web.config:
<httpCompression directory="%TEMP%\iisexpress\IIS Temporary Compressed Files">
    <scheme name="gzip" dll="%IIS_BIN%\gzip.dll" />
    <dynamicTypes>
        <add mimeType="text/*" enabled="true" />
        <add mimeType="message/*" enabled="true" />
        <add mimeType="application/x-javascript" enabled="true" />
        <add mimeType="*/*" enabled="false" />
    </dynamicTypes>
    <staticTypes>
        <add mimeType="text/*" enabled="true" />
        <add mimeType="message/*" enabled="true" />
        <add mimeType="application/x-javascript" enabled="true" />
        <add mimeType="application/atom+xml" enabled="true" />
        <add mimeType="application/xaml+xml" enabled="true" />
        <add mimeType="*/*" enabled="false" />
    </staticTypes>
</httpCompression>
<urlCompression doDynamicCompression="true" doStaticCompression="true" dynamicCompressionBeforeCache="true" />
Is it interfere with WebMarkupMin? Maybe I misunderstand a bit? Is this "turn on and use gzip somewhat you want" or "turn on and IIS will compress everything"

Modex wrote Apr 19, 2016 at 5:47 AM

I'm loading using jquery get-method:
$.get('@Url.Action("GetTariffExtendings")', function(html){
    $('#response').html(html);
});

Modex wrote Apr 19, 2016 at 5:56 AM

But how CompressContent can affect... View loaded with compressing, from view raised separated AJAX-request to action and handler to answer... Where parsing error started? WebMarkupMin trying to gzip response which always compressed by IIS?

Modex wrote Apr 19, 2016 at 6:00 AM

When comment httpCompression and urlCompression sections in web.config — no errors

Modex wrote Apr 19, 2016 at 6:07 AM

Interesting... Action for open page work with both attributes, but the same HTML_PARSIN_ERROR if leave only [MinifyHtml]
[MinifyHtml, CompressContent]
public ActionResult CreateRequestAgent(int idClient)
{
    var model = ... loading parent page model

    return View(model);
}

Taritsyn wrote Apr 19, 2016 at 11:58 AM

Line 1: …@�흼��{���{���;�N'���?\fdl��J�ɞ!���?~|?"~�D�{<+.�i�5�g�EӦ�U�ؾ���꣣�8��{<�?�����o�����o��…
--------------------------------------------------------^
Line 2: …��ٲJ��������.��h��H�/�eD������������n?���~3]�\O��)��ܾ?y���v��`w�� �9?����`
These strange symbols mean only one thing, that the WebMarkupMin tries to minify contents are compressed by GZip/Deflate. This behavior causes the following code:
<urlCompression ... dynamicCompressionBeforeCache="true" />
True value in dynamicCompressionBeforeCache attribute causes early compression of content. Using of [CompressContent] attribute prevents early compression.

Modex wrote Apr 19, 2016 at 12:23 PM

And as I understand there are 2 ways:
  1. Using dynamicCompressionBeforeCache in web.config and not using anywhere [CompressContent]. Compressing will be everywhere.
  2. Disable dynamic compression and use [CompressContent] only where need
Is it right?

Taritsyn wrote Apr 19, 2016 at 1:47 PM

1) Using dynamicCompressionBeforeCache in web.config and not using anywhere [CompressContent]. Compressing will be everywhere.
This variant is technically infeasible. On the contrary, in this case it is necessary everywhere where [MinifyHtml] attribute is used, also use a [CompressContent] attribute.
2) Disable dynamic compression and use [CompressContent] only where need
Is the best variant.

There is a third variant: set to dynamicCompressionBeforeCache attribute value equals to false.

Modex wrote Apr 20, 2016 at 5:39 AM

Thanks!

Modex wrote Apr 20, 2016 at 6:03 AM

May be necessary to add this information to documentation?

Taritsyn wrote Apr 20, 2016 at 8:10 AM

I will add this to the documentation, when I get free time.