Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error with .NET Core 2.1 and Razor Pages #36

Open
scearces opened this issue Jul 10, 2018 · 13 comments
Open

Error with .NET Core 2.1 and Razor Pages #36

scearces opened this issue Jul 10, 2018 · 13 comments

Comments

@scearces
Copy link

scearces commented Jul 10, 2018

My configuration: localhost, Windows 10, Visual Studio 2017, ASP.NET Core 2.1, Razor Pages. The WebEssentials.AspNetCore.PWA package injects 2 lines into _Layout.cshtml. The first line, in the head, should be link rel="manifest" href="/manifest.webmanifest" /. Instead, in my configuration it generates link rel="manifest" href=" ~ /manifest.webmanifest" /. See the extra tilde . This causes chrome to fail to locate the manifest.webmanifest. The second line it injects, in html region, should be script nws-csp-add-nonce='true'>'serviceWorker' in navigator && navigator.serviceWorker.register('/serviceworker') /script. Instead it is injecting script nws-csp-add-nonce='true' 'serviceWorker'in navigator&&navigator.serviceWorker.register('~/serviceworker') /script>. Again, see the tilde. This cause the service worker registration to fail be cause Chrome can't locate it. My question is what do I need to do to make it generate the code correctly? Is it because I am using .NET Core 2.1 instead of .NET Core 2.0 or is there something else I need to change? Thanks.

@bpepe
Copy link

bpepe commented Jul 12, 2018

Same problem here. I believe the 'Update Constants.cs #29' commit is the issue.

@under3415
Copy link

Going back to 1.0.33 fixed the issue, it's working again!

@HaraldMuehlhoffCC
Copy link

Same problem here. Going back to 1.0.33 fixed the issue for me also.

@jpisano
Copy link

jpisano commented Jul 31, 2018

I know it's not ideal but if you disable registering both the service worker and manifest:

services.AddProgressiveWebApp(new PwaOptions
{
	RegisterServiceWorker = false,
	RegisterWebmanifest = false,
	OfflineRoute = "offline"
});

You can then manually add both back to your layout:

<meta name="theme-color" content="#FFFFFF" />
<link rel="manifest" href="/manifest.webmanifest" />

and

<script>'serviceWorker' in navigator && navigator.serviceWorker.register('/serviceworker')</script>

@TanmaySM
Copy link

TanmaySM commented Aug 7, 2018

Facing same issue. Using other way around by setting RegisterServiceWorker and RegisterWebmanifest to false and adding both file manually as mentioned by @jpisano

@JudahGabriel
Copy link
Contributor

@madskristensen It appears the latest WebEssentials.AspNetCore.SPA NuGet package doesn't work with .NET Core 2.1 because of the tilde, as described in the first post in this thread.

@acr21
Copy link

acr21 commented Aug 14, 2018

Having the same issue.

@braegelno5
Copy link

the last nuget package Version=1.0.42.0 has also again this error the master branch source are
public const string ServiceworkerRoute = "/serviceworker";
the reflected one is "~/serviceworker" with dll Version=1.0.42.0

@rahulsjoshi
Copy link

Same issue with .NET Core 2.1

@justechvn
Copy link

Thanks!

@Ghosts
Copy link

Ghosts commented Feb 6, 2019

I was wondering if anyone has the status on this issue? Found a couple potential workarounds but if there's a plan to push a NuGet update for a fix I'd be fine waiting for that.

Thanks for any update.

@scearces
Copy link
Author

scearces commented Feb 6, 2019 via email

@GetTaxSolutions
Copy link

GetTaxSolutions commented Apr 3, 2019

May be is a similar issue and that is the reason to ask here.
I have follow code which is using RazorViewEngine to return compiled string when apply the model:

using (var output = new StringWriter())
            {
                var viewContext = new ViewContext(
                    actionContext,
                    view,
                    new ViewDataDictionary<TModel>(
                        metadataProvider: new EmptyModelMetadataProvider(),
                        modelState: new ModelStateDictionary())
                    {
                        Model = model
                    },
                    new TempDataDictionary(
                        actionContext.HttpContext,
                        _tempDataProvider),
                    output,
                    new HtmlHelperOptions());

                await view.RenderAsync(viewContext);

                return output.ToString();
            }

All parameters are correct and it is working perfect when services.AddProgressiveWebApp() is not applied. But when you add it:

Unhandled Exception: System.AggregateException: One or more errors occurred. (Object reference not set to an instance of an object.) ---> System.NullReferenceException: Object reference not set to an instance of an object.
at WebEssentials.AspNetCore.Pwa.ServiceWorkerTagHelperComponent.Process(TagHelperContext context, TagHelperOutput output)
at Microsoft.AspNetCore.Razor.TagHelpers.TagHelperComponent.ProcessAsync(TagHelperContext context, TagHelperOutput output)
at Microsoft.AspNetCore.Mvc.Razor.TagHelpers.TagHelperComponentTagHelper.ProcessAsync(TagHelperContext context, TagHelperOutput output)
at Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperRunner.RunAsync(TagHelperExecutionContext executionContext)
at AspNetCore._Views__EmailLayout.ExecuteAsync()
at Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderPageCoreAsync(IRazorPage page, ViewContext context)
at Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderPageAsync(IRazorPage page, ViewContext context, Boolean invokeViewStarts)
at Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderLayoutAsync(ViewContext context, ViewBufferTextWriter bodyWriter)
at Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderAsync(ViewContext context)
at Mvc.RenderViewToString.RazorViewToStringRenderer.RenderViewToStringAsync[TModel](String viewName, TModel model) in D:\Projects\TFS\GetTaxSolutions\Tools\MailKit Client\SendMailKit\TazorToString\RazorViewToStringRenderer.cs:line 58
--- End of inner exception stack trace ---
at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
at Mvc.RenderViewToString.Program.Main() in D:\Projects\TFS\GetTaxSolutions\Tools\MailKit Client\SendMailKit\TazorToString\Program.cs:line 24
Press any key to continue . . .

I tried to apply PWA options to:

            RegisterServiceWorker = false,
            RegisterWebmanifest = false,

It's working but is not good solution for me. Is there some better solution to resolve this issue? Are you planning to fix it in next version?

AspNetCore version: 2.2
Pwa: 1.0.49
Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests