Orchardcore: @T[] Format error

Created on 9 Oct 2018  Â·  30Comments  Â·  Source: OrchardCMS/OrchardCore

When I try to edit a Text fields form ContentType (or ContentParts ) , click save button . then the page was not response.

the path like this : /Admin/ContentParts/Blockquote/Fields/Quote/Edit

debug in chrome devtools:
the page response status: Failed to load resource: net::ERR_CONNECTION_RESET

Has anyone encountered this situation?

P0 bug localization

All 30 comments

Reproduce this problem:

Set debug at : C:\Users\hyzx8\Source\Repos\OrchardCore\src\OrchardCore.Modules\OrchardCore.DynamicCache\EventHandlers\DynamicCacheShapeDisplayEvents.cs line 72

I was add try for this line:
try { context.ChildContent.WriteTo(sw, HtmlEncoder.Default); } catch (System.Exception ex) { System.Console.WriteLine(ex); // set stop point here }
the code will stop at

System.Console.WriteLine(ex);

now ,the sw.ToString() result is
`

<fieldset class="form-group">
    <div class="row col-md">
        <label for="HTProject_ProjectStatus_TextFieldPredefinedListEditorSettingsDriver_Options">Options</label>
        <textarea rows="8" class="form-control" id="HTProject_ProjectStatus_TextFieldPredefinedListEditorSettingsDriver_Options" name="HTProject.ProjectStatus.TextFieldPredefinedListEditorSettingsDriver.Options">

[]
`

compare with the source file :
OrchardCore\src\OrchardCore.Modules\OrchardCore.ContentFields\Views\TextFieldPredefinedListEditorSettings.Edit.cshtml

`

<fieldset class="form-group">
    <div class="row col-md">
        <label asp-for="Options">@T["Options"]</label>
        <textarea asp-for="Options" rows="8" class="form-control"></textarea>
        <span class="hint">@T["A JSON representation of the allowed values, e.g. {0}", "[ { name: 'First option', value: 'option1' }, { name: 'Second option', value: 'option2' } ]"]</span>
    </div>
</fieldset>

<fieldset class="form-group">
    <div class="row col">
        <label asp-for="DefaultValue">@T["Default value"]</label>
        <input asp-for="DefaultValue" class="form-control" type="text" />
        <span class="hint">@T["(Optional) The default to assign to the text field."]</span>
    </div>
</fieldset>

`

Contrast found that the code before the last T[] method is out, the problem may be here。
so ,in my project I was remove the T[] method at here.

My page can open now.

but the content still end of <span class="hint">...

the problem code:
@T["A JSON representation of the allowed values, e.g. {0}", "[ { name: 'First option', value: 'option1' }, { name: 'Second option', value: 'option2' } ]"]

{System.FormatException: Input string was not in a correct format.
at System.Text.StringBuilder.FormatError()
at System.Text.StringBuilder.AppendFormatHelper(IFormatProvider provider, String format, ParamsArray args)
at System.String.FormatHelper(IFormatProvider provider, String format, ParamsArray args)
at System.String.Format(IFormatProvider provider, String format, Object[] args)
at Microsoft.AspNetCore.Html.HtmlFormattableString.WriteTo(TextWriter writer, HtmlEncoder encoder)
at Microsoft.AspNetCore.Mvc.ViewFeatures.Internal.ViewBuffer.WriteTo(TextWriter writer, HtmlEncoder encoder)
at OrchardCore.DynamicCache.EventHandlers.DynamicCacheShapeDisplayEvents.DisplayedAsync(ShapeDisplayContext context) in C:\Users\hyzx8\Source\Repos\OrchardCore\src\OrchardCore.Modules\OrchardCore.DynamicCache\EventHandlers\DynamicCacheShapeDisplayEvents.cs:line 74}

I had the exact same issue when updating to the newest version. When I check I came to the same conclusion.

The strange thing is, on the same host, a new tenant don't have this issue.

I had the exact same issue when updating to the newest version. When I check I came to the same conclusion.

The strange thing is, on the same host, a new tenant don't have this issue.

Yes , a new environment or new tenant is ok, but just broke again in a moment

Must be an issue with the JSON in the textarea field. I would be really surprised that this is related to T[].
If you submit non conform JSON data it will fail when reloading that page. Though my PR should fix this issue soon.

I am not really sure it is T[]. I haven't used the predefined lists yet. I was trying to edit a pre existing text field to use the new feature. Then discover that I cannot edit any text field after update.

I'll try to repro and tell you what I find.

@Skrypt

the problem code in file OrchardCore\src\OrchardCore.Modules\OrchardCore.ContentFields\Views\TextFieldPredefinedListEditorSettings.Edit.cshtml :

@T["A JSON representation of the allowed values, e.g. {0}", "[ { name: 'First option', value: 'option1' }, { name: 'Second option', value: 'option2' } ]"]

This bug may not happen every time.

Your json is probably malformed. Keeping this open until we merge the new editor.

@hyzx86 Can you test this back on a fresh install?

@Skrypt OK ,wait a moment .

@Skrypt Great experience, thank you!

@hyzx86 Can I close this issue?

@Skrypt

Is this PR published to nuget?

My project is refference from nuget. when I create a new text field it's still report this error.

GET https://localhost:44300/Admin/ContentParts/HTProject/Fields/ProjectName/Edit net::ERR_SPDY_PROTOCOL_ERROR 200

https://www.itechgyan.com/err_spdy_protocol_error/

Basically it tells that you should try to clean your browser cache completely.

@Skrypt that's a format error

Is this a version merge error? #2536

Comment out that line of code, this problem will fix.

···
onnection id "0HLHLFHQL02JF", Request id "0HLHLFHQL02JF:00000004": An unhandled exception was thrown by the application. System.FormatException: Input string was not in a correct format.
at System.Text.StringBuilder.FormatError()
at System.Text.StringBuilder.AppendFormatHelper(IFormatProvider provider, String format, ParamsArray args)
at System.String.FormatHelper(IFormatProvider provider, String format, ParamsArray args)
at System.String.Format(IFormatProvider provider, String format, Object[] args)
at Microsoft.AspNetCore.Html.HtmlFormattableString.WriteTo(TextWriter writer, HtmlEncoder encoder)
at Microsoft.AspNetCore.Mvc.ViewFeatures.Internal.ViewBuffer.WriteTo(TextWriter writer, HtmlEncoder encoder)
at OrchardCore.DisplayManagement.PositionWrapper.WriteTo(TextWriter writer, HtmlEncoder encoder) in C:\projects\orchard2\src\OrchardCore\OrchardCore.DisplayManagement\PositionWrapper.cs:line 37
at Microsoft.AspNetCore.Mvc.ViewFeatures.Internal.ViewBuffer.WriteToAsync(TextWriter writer, HtmlEncoder encoder)
at Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderLayoutAsync(ViewContext context, ViewBufferTextWriter bodyWriter)
at Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderAsync(ViewContext context)
at Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor.ExecuteAsync(ViewContext viewContext, String contentType, Nullable1 statusCode) at Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor.ExecuteAsync(ActionContext actionContext, IView view, ViewDataDictionary viewData, ITempDataDictionary tempData, String contentType, Nullable1 statusCode)
at Microsoft.AspNetCore.Mvc.ViewFeatures.ViewResultExecutor.ExecuteAsync(ActionContext context, ViewResult result)
at Microsoft.AspNetCore.Mvc.ViewResult.ExecuteResultAsync(ActionContext context)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeResultAsync(IActionResult result)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextResultFilterAsyncTFilter,TFilterAsync
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResultExecutedContext context)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.ResultNextTFilter,TFilterAsync
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeResultFilters()
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextResourceFilter()
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResourceExecutedContext context)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeFilterPipelineAsync()
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeAsync()
at Microsoft.AspNetCore.Builder.RouterMiddleware.Invoke(HttpContext httpContext)
at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context)
at SixLabors.ImageSharp.Web.Middleware.ImageSharpMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Localization.RequestLocalizationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Diagnostics.StatusCodePagesMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context)
at OrchardCore.Modules.ModularTenantRouterMiddleware.Invoke(HttpContext httpContext) in C:\projects\orchard2\src\OrchardCore\OrchardCore\Modules\ModularTenantRouterMiddleware.cs:line 76
at OrchardCore.Modules.ModularTenantContainerMiddleware.Invoke(HttpContext httpContext) in C:\projects\orchard2\src\OrchardCore\OrchardCore\Modules\ModularTenantContainerMiddleware.cs:line 100
at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Server.IISIntegration.IISMiddleware.Invoke(HttpContext httpContext)
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequestsTContext
at Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor.ExecuteAsync(ActionContext actionContext, IView view, ViewDataDictionary viewData, ITempDataDictionary tempData, String contentType, Nullable1 statusCode) at Microsoft.AspNetCore.Mvc.ViewFeatures.ViewResultExecutor.ExecuteAsync(ActionContext context, ViewResult result) at Microsoft.AspNetCore.Mvc.ViewResult.ExecuteResultAsync(ActionContext context) at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeResultAsync(IActionResult result) at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextResultFilterAsync[TFilter,TFilterAsync]() at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResultExecutedContext context) at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.ResultNext[TFilter,TFilterAsync](State& next, Scope& scope, Object& state, Boolean& isCompleted) at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeResultFilters() at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextResourceFilter() at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResourceExecutedContext context) at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted) at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeFilterPipelineAsync() at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeAsync() at Microsoft.AspNetCore.Builder.RouterMiddleware.Invoke(HttpContext httpContext) at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context) at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context) at SixLabors.ImageSharp.Web.Middleware.ImageSharpMiddleware.Invoke(HttpContext context) at Microsoft.AspNetCore.Localization.RequestLocalizationMiddleware.Invoke(HttpContext context) at Microsoft.AspNetCore.Diagnostics.StatusCodePagesMiddleware.Invoke(HttpContext context) at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context) at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context) at OrchardCore.Modules.ModularTenantRouterMiddleware.Invoke(HttpContext httpContext) in C:\projects\orchard2\src\OrchardCore\OrchardCore\Modules\ModularTenantRouterMiddleware.cs:line 76 at OrchardCore.Modules.ModularTenantContainerMiddleware.Invoke(HttpContext httpContext) in C:\projects\orchard2\src\OrchardCore\OrchardCore\Modules\ModularTenantContainerMiddleware.cs:line 100 at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context) at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context) at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context) at Microsoft.AspNetCore.Server.IISIntegration.IISMiddleware.Invoke(HttpContext httpContext) at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication1 application)

···

Look at your JSON data for that field. The issue is probably there. Remove it completely and you will see. We need to still validate JSON data before posting it to the database to make sure this doesn't happen.

@Skrypt Could you tell me witch screenshot tool you used ? Can generate a GIF. Later I make a GIF to show you the reason for the error on my project

ScreenToGif app

Oh, just for infos i had this issue while demoing distributed services to sebastien ;) I was not able to add a text field to the article type (dyn cache enabled).

In the meantime i have merged dev, just tried i can't repro but in the dev branch there is not the line of code specified by @hyzx86. But in the master branch this line is there.

Didn't tried yet on the master branch, time to sleep for me.

Update: For infos, just tried on the master branch, i was not able to repro.

Issue is that I can't repro locally at all. I'm using dev branch and I've never had this issue. I could try and make the JSON fail to see what I'd get. Though, from where it fails on the code the issue seems lower in the DisplayManagement code. If we could at least define if the issue happens because of the data itself that would make a great improvement on what we are searching to fix. It could be also a DB migration issue from when we broke the fields type names.

Only way to fix this would be to debug it directly on @hyzx86 computer; unless he could provide repro steps and data sample.

@Skrypt
t error

{



<h1>"项目简介" settings for "HTProject"</h1>

<form action="/Admin/ContentParts/HTProject/Fields/Description/Edit" method="post">
    <div class="validation-summary-valid" data-valmsg-summary="true"><ul><li style="display:none"></li>
</ul></div>
    <fieldset class="form-group">
        <div class="row col-md">
            <label for="DisplayName">Display Name</label>
            <input autofocus class="form-control" type="text" data-val="true" data-val-required="The DisplayName field is required." id="DisplayName" name="DisplayName" value="&#x9879;&#x76EE;&#x7B80;&#x4ECB;" />
            <span class="hint">Name of the field as it will be displayed in screens.</span>
        </div>
    </fieldset>

    <fieldset class="form-group">
        <div class="row col-sm">
            <label for="Name">Technical Name</label>
            <input class="form-control" readonly type="text" id="Name" name="Name" value="Description" />
            <span class="hint">Technical name of the field.</span>
        </div>
    </fieldset>

    <fieldset class="form-group">

<fieldset class="form-group">
    <div class="custom-control custom-checkbox">
        <input type="checkbox" type="checkbox" class="custom-control-input" checked="checked" data-val="true" data-val-required="The Required field is required." id="HTProject_Description_TextFieldSettingsDriver_Required" name="HTProject.Description.TextFieldSettingsDriver.Required" value="true">
        <label class="custom-control-label" for="HTProject_Description_TextFieldSettingsDriver_Required">Check if the field is required.</label>
    </div>
</fieldset>

<fieldset class="form-group">
    <div class="row col-sm-6">
        <label for="HTProject_Description_TextFieldSettingsDriver_Hint">Hint</label>
        <textarea rows="2" class="form-control" id="HTProject_Description_TextFieldSettingsDriver_Hint" name="HTProject.Description.TextFieldSettingsDriver.Hint">
</textarea>
        <span class="hint">The hint text to display for this field on the editor.</span>
    </div>
</fieldset>

    </fieldset>
    <div class="row">
        <fieldset class="form-group col-sm-6">
            <label for="Editor">What type of editor should be used?</label>
            <select class="form-control" id="field-editor-select" name="Editor">
<option value="IconPicker">Icon picker</option>
<option value="PredefinedList">Predefined List</option>
<option value="TextArea" selected="selected">Multi-line</option>
<option value="">Standard</option>
            </select>
        </fieldset>
    </div>
    <fieldset id="field-editor-container" class="form-group" style="display: none">









<script type="text/x-template" id="options-table">
    <table class="table table-bordered table-sm options-table">
        <thead class="thead-light">
            <tr>
                <th scope="col">Option Label</th>
                <th scope="col">Value</th>
                <th scope="col" colspan="3">Default?</th>
            </tr>
        </thead>
        <draggable v-model="data.options" :element="'tbody'">
            <tr v-for="(option, index) in data.options" :key="index" class="ui-sortable-handle">
                <td>
                    <input type="text" class="form-control" v-model="option.name" placeholder="Enter a name" />
                </td>
                <td>
                    <input type="text" class="form-control courrier" v-model="option.value" placeholder="Enter a value" />
                </td>
                <td class="text-center">
                    <div class="custom-control custom-radio ml-2">
                        <input type="radio" class="custom-control-input" :id="'customRadio_' + index" name="HTProject.Description.TextFieldPredefinedListEditorSettingsDriver.DefaultValue" v-bind:value="option.value" v-model="data.selected" v-on:click="uncheck(index)">
                        <label class="custom-control-label" title="Set as default" v-bind:for="'customRadio_' + index"></label>
                    </div>
                </td>
                <td class="text-center">
                    <a v-on:click="remove(index)" title="Remove element from list" class="btn" style="background-color:transparent;">
                        <i class="fas fa-times"></i>
                    </a>
                </td>
                <td class="text-center"><div class="btn ui-sortable-handle"><i class="fas fa-arrows-alt"></i></div></td>
            </tr>
        </draggable>
        <tfoot>
            <tr>
                <td class="col-sm-12 text-center" colspan="5">
                    <a v-on:click="add()" class="btn btn-light w-100 btn-sm"><i class="fas fa-plus small"></i> Add an option</a>
                    <input class="form-control" id="HTProject_Description_TextFieldPredefinedListEditorSettingsDriver_Options" name="HTProject.Description.TextFieldPredefinedListEditorSettingsDriver.Options" type="hidden" v-bind:value="getOptionsFormattedList()" />
                </td>
            </tr>
        </tfoot>
    </table>
</script>

<script type="text/x-template" id="options-modal">
    <div class="modal fade HTProject_Description_TextFieldPredefinedListEditorSettingsDriver-ModalBody text-left" role="dialog" aria-hidden="true">
        <div class="modal-dialog modal-dialog-centered" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title">Edit Data</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                <div class="modal-body">
                    <fieldset class="form-group">
                        <label for="options-textarea">Options</label>
                        <textarea id="options-textarea" name="options-textarea" rows="8" class="form-control" v-bind:value="JSON.stringify(data.options)" v-on:input="data.options = JSON.parse($event.target.value)"></textarea>
                        <span class="hint">}

Generating the page's HTML code was interrupted, the HTML code above is an incomplete code, it ended before this code :

@T[" A JSON representation of the allowed values, e.g. {0} ", "[{name: 'First option, the value:' option1}, {name: 'the Second option', value: 'option2}]"]

https://github.com/OrchardCMS/OrchardCore/issues/2477#issuecomment-428786618

It is a Razor engine error?
I can provide the dump file , If necessary .

@Skrypt @hyzx86 okay i was able to repro, even with the last dev.

In fact, to repro you need to enable OC.Localization which is not enabled by default with the blog theme. That's why i was not able to repro. But when i had this issue while testing distributed services, i first run a saas recipe and then a blog recipe through the admin, and the saas recipe has OC.Localization.

Try to disable OC.Localization to see if it works and if we are talking about the same things ;)

Maybe in PortableObjectHtmlLocalizer line 31 we have more things to do, i will see tomorrow.

That said, i could get it working by using double curly braces (only one is rendered), you can check it also. Hmm, maybe the string argument itself was parsed as a formattable string because of the single braces, and then with no arguments, i will see tomorrow more in depth.

@T["A JSON representation of the allowed values, e.g. {0}", "[ {{ name: 'First option', value: 'option1' }}, {{ name: 'Second option', value: 'option2' }} ]"].

@sebastienros @Skrypt i think we can re-open this issue.

Good catch; I would not have found it just like that. It's a localization string issue then. Has nothing to do directly with the option editors.

Reopened

@Skrypt

Yes not directly, it just showed up an issue when the already formatted string also contains curly braces.

Then in this case a second formatting was done. Using double braces is a workaround but better to not do the 1st formatting as when using default localizers. The singularity is that, even we don't format the string, we still need arguments for plural localization.

I did a PR.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

szilardcsere89 picture szilardcsere89  Â·  3Comments

aghili371 picture aghili371  Â·  3Comments

webmedia1012 picture webmedia1012  Â·  4Comments

khoshroomahdi picture khoshroomahdi  Â·  4Comments

cbadger360 picture cbadger360  Â·  4Comments