Skip to content
This repository was archived by the owner on Dec 19, 2018. It is now read-only.
This repository was archived by the owner on Dec 19, 2018. It is now read-only.

This extension method fails in RC2 - worked in RC1 - could use some help.. #795

@dazinator

Description

@dazinator

The following extension method is a simplified version of the one we actually use, to demonstrate the issue.


     public static HtmlString AddResource(this IHtmlHelper htmlHelper, Func<object, HelperResult> template)
        {       

                using (var writer = new StringWriter(CultureInfo.InvariantCulture))
                {
                    var content = template(null);
                    content.WriteTo(writer, HtmlEncoder.Default);
                    hash = writer.ToString().GetHashCode();
                }     

               // TODO: do some stuff with the content           

                return new HtmlString(String.Empty);
        }

In RC1 - I could use this within a razor view, such a a view for a ViewComponent, like so:


@Html.AddResource(
    @<script type="text/javascript">
        require(['jquery'], function (jquery) {           

            jquery(document).ready(function() {
               // do some stuff
            });

        });
    </script>
)

However in RC2, this line now throws a null ref exception:


 content.WriteTo(writer, HtmlEncoder.Default);

I'm really not sure how this all sits together to begin with, any ideas what changed and how I can fix this method to work in RC2?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions