InvalidCastException When Using Tag Helper
Rabadash8820 opened this issue · 3 comments
I am trying to use the asp-subresource-integrity-src
tag helper in my _Layout page. I did not use the Boilerplate project template because, for now, I am only taking advantage of the SRI features. My _ViewImports.cshtml file looks like this:
@using MyApp
@using Boilerplate.AspNetCore.TagHelpers
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@addTagHelper *, Boilerplate.AspNetCore.TagHelpers
and my _Layout.cshtml file includes <script>
elements like the following:
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js"
asp-subresource-integrity-src="~/lib/bootstrap/dist/js/bootstrap.min.js"
asp-fallback-src="~/lib/bootstrap/dist/js/bootstrap.min.js"
asp-fallback-test="window.jQuery && window.jQuery.fn && window.jQuery.fn.modal">
</script>
Unfortunately, when I run the application from the command line with dotnet MyApp.dll
and navigate to localhost:5000
, I get the following stack trace:
fail: Microsoft.AspNetCore.Server.Kestrel[13]
Connection id "0HL5SP6T01RHV": An unhandled exception was thrown by the application.
System.InvalidCastException: Unable to cast object of type '<GetFlags>d__19' to type 'System.Collections.Generic.IEnumerable`1[Boilerplate.AspNetCore.TagHelpers.SubresourceIntegrityHashAlgorithm]'.
at Boilerplate.AspNetCore.TagHelpers.SubresourceIntegrityTagHelper.GetSpaceDelimetedSri(Byte[] bytes, SubresourceIntegrityHashAlgorithm hashAlgorithms)
at Boilerplate.AspNetCore.TagHelpers.SubresourceIntegrityTagHelper.<ProcessAsync>d__17.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperRunner.<RunAsync>d__0.MoveNext()
. . .
A ton more ExceptionDispatchInfo.Throw() blocks similar to the above, from various Microsoft.AspNetCore.Mvc locations.
. . .
It looks like Boilerplate is having some kind of trouble parsing my SubresourceIntegrityHashAlgorithm values since I didn't provide any. But according to this post from @RehanSaeed's blog, I shouldn't need to provide any algorithms explicitly. I'm guessing that I just forgot a @using
statement or something, but I'm at a loss. Any help would be appreciated!
That's a very strange exception and I'm also not sure what could be causing it. I'll have to debug it when I get a chance.
2.3.3 of the package which is currently building in AppVeyor will fix this problem. Thanks for raising this to my attention 👍
Wow, that was an incredibly fast turn-around, thank you! I'm still having 500 errors with my site, but I don't believe that they are related to Boilerplate anymore. Thanks again for your help!