question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Angular 9+ & ASP.NET Core Engine Not working with IVY

See original GitHub issue

So I am working with .NET CORE version 2.2 and Angular version ~10.0.6 and I read angular documentation and have found that when Angular 8 is updated to Angular 9. A new compiler is added to Angular project that is Ivy, when we do SSR without IVY OR with Angular below 9 , No exception or error is coming from the below code, but when working with Ivy, it is causing problem.

Please let me know if you know any solution to this.

🐞 Bug report

What modules are related to this issue?

  • aspnetcore-engine
  • builders
  • common
  • express-engine
  • hapi-engine

Is this a regression?

✍️Yes, the previous version in which this bug was not present was: Angular 8 and below It works perfectly below Angular 9 since this error is coming from Angular Ivy, This needs to be properly documented and resolved. Mostly errors I have seen related to Angular Universal V9 is due to IVY, Guide me if there is any way to look the code of ngAspnetCoreEngine() so that we can check the point from which issue is generating.

Description

🔥 Line on Which exception is taking place



export default createServerRenderer((params) => {
  //console.log("=============================================")
  //console.log("Working");
  //console.log("=============================================")
  // Platform-server provider configuration
  const setupOptions: IEngineOptions = {
    appSelector: '<app-root></app-root>',
    ngModule: AppServerModule,
    request: params,
    providers: [
      // Optional - Any other Server providers you want to pass
      // (remember you'll have to provide them for the Browser as well)
    ]
  };

  //console.log("=============================================")
  //console.log("Working");
  //console.log("=============================================")
    return ngAspnetCoreEngine(setupOptions) // App Crashing in Promise return 
      .then(response => {

        //console.log("=============================================")
        //console.log("App is crashed in above return of Promise, build file which breaks code is attached below");
        //console.log("=============================================")

        return ({
          html: response.html
        });
      })
      .catch(e => {
        return ({
          html: "App is crashing, caught in catch method of createServerRenderer()"
        });
      })
});


🔥 build file code that is breaking exception


class R3Injector {
      destroy() {  // This function is called when using IVY compiler, and this throw below exception
// If we remove this 5 lines code, It works perfectly fine. but cant remove directly after every build so we need permanent solution 
          this.assertNotDestroyed(), this._destroyed = !0;
          try {
           this.onDestroy.forEach(service => service.ngOnDestroy())
         } finally {
          this.records.clear(), this.onDestroy.clear(), this.injectorDefTypes.clear()
         }
}

A clear and concise description of the problem...

🔬 Minimal Reproduction

Before Exception Error Logs


Microsoft.AspNetCore.NodeServices:Information: What's our REQUEST Object look like?
Microsoft.AspNetCore.NodeServices:Information: The Request object only really exists on the Server, but on the Browser we can at least see Cookies
Microsoft.AspNetCore.NodeServices:Information: ==========================================
Microsoft.AspNetCore.NodeServices:Information: AppComponent Constructor is called!
Microsoft.AspNetCore.NodeServices:Information: ==========================================
Microsoft.AspNetCore.NodeServices:Information: ==========================================
Microsoft.AspNetCore.NodeServices:Information: AppComponent NgOninit is called!
Microsoft.AspNetCore.NodeServices:Information: ==========================================
Microsoft.AspNetCore.NodeServices:Information: ==========================================
Microsoft.AspNetCore.NodeServices:Information: AppComponent Destructor is called!
Microsoft.AspNetCore.NodeServices:Information: ==========================================
// Now this is the place where code is crashing
**Exception thrown: 'Microsoft.AspNetCore.NodeServices.HostingModels.NodeInvocationException' in System.Private.CoreLib.dll
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker:Information: Executed action method** WebApplicationBasic.Controllers.HomeController.Index (Angular-DotNetCore-SSr), returned result Microsoft.AspNetCore.Mvc.ViewResult in 432.0046ms.
Microsoft.AspNetCore.Mvc.ViewFeatures.ViewResultExecutor:Information: Executing ViewResult, running view Index.


🔥 Exception or Error




Injector has already been destroyed. Error: Injector has already been destroyed. at R3Injector.assertNotDestroyed 
(C:\Users\umer.hasan\source\repos\Angular-DotNetCore-SSr\Angular-DotNetCoreSSr\ClientApp\dist\ClientApp\server\main.js:1:352374) 
at R3Injector.get (C:\Users\umer.hasan\source\repos\Angular-DotNetCore-SSr\Angular-DotNetCore-SSr\ClientApp\dist\ClientApp\server\main.js:1:351120) at NgModuleRef$1.get (C:\Users\umer.hasan\source\repos\Angular-
DotNetCore-SSr\Angular-DotNetCore-SSr\ClientApp\dist\ClientApp\server\main.js:1:523603) at 
C:\Users\umer.hasan\source\repos\Angular-DotNetCore-SSr\Angular-DotNetCore-
SSr\ClientApp\dist\ClientApp\server\main.js:1:1516636 at Generator.next () at fulfilled 
(C:\Users\umer.hasan\source\repos\Angular-DotNetCore-SSr\Angular-DotNetCore-SSr\ClientApp\dist\ClientApp\server\main.js:1:2194411) at ZoneDelegate.invoke (C:\Users\umer.hasan\source\repos\Angular-
DotNetCore-SSr\Angular-DotNetCore-SSr\ClientApp\dist\ClientApp\server\main.js:1:1841674) at Zone.run 
(C:\Users\umer.hasan\source\repos\Angular-DotNetCore-SSr\Angular-DotNetCore-
SSr\ClientApp\dist\ClientApp\server\main.js:1:1834088) at C:\Users\umer.hasan\source\repos\Angular-DotNetCore-SSr\Angular-
DotNetCore-SSr\ClientApp\dist\ClientApp\server\main.js:1:1853185 at ZoneDelegate.invokeTask 
(C:\Users\umer.hasan\source\repos\Angular-DotNetCore-SSr\Angular-DotNetCore-SSr\ClientApp\dist\ClientApp\server\main.js:1:1842606)

🌍 Your Environment




PM> ng --version

     _                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / â–³ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/
    

Angular CLI: 10.0.6
Node: 12.18.3
OS: win32 x64

Angular: 10.0.9
... animations, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, platform-server
... router
Ivy Workspace: Yes

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.1000.6
@angular-devkit/build-angular     0.1000.6
@angular-devkit/build-optimizer   0.1000.6
@angular-devkit/build-webpack     0.1000.6
@angular-devkit/core              10.0.6
@angular-devkit/schematics        10.0.6
@angular/cli                      10.0.6
@ngtools/webpack                  10.0.6
@nguniversal/aspnetcore-engine    10.0.2
@nguniversal/builders             10.0.2
@nguniversal/common               10.0.2
@nguniversal/express-engine       10.0.2
@schematics/angular               10.0.6
@schematics/update                0.1000.6
rxjs                              6.5.5
typescript                        3.9.7
webpack                           4.43.0
    

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6

github_iconTop GitHub Comments

3reactions
alan-agius4commented, Jan 12, 2021

Bug confirmed and working on a fix.

More context: https://github.com/angular/angular/issues/37888#issuecomment-758859207

1reaction
alan-agius4commented, Jan 13, 2021

@patelhr, this seems a different issue. Mind opening a new issue with a reproduction? Thanks.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular 9 Support with Ivy in Kendo UI for Angular - Telerik
Hi,. We are currently working toward providing support for Ivy, and some of our packages are already compatible, but we will likely abstain ......
Read more >
Ivy: The Game Changer in Angular 9 | Syncfusion Blogs
This blog describes the highlights of the Ivy compiler that is available with Angular 9 and how it makes application development using ...
Read more >
All About Angular Engine Ivy in 5 mins
IVY is a rendering architecture that was first introduced with Version 8. In this article, we are sharing some insights on the features...
Read more >
A Detailed Guide on Angular Engine Ivy - iFour Technolab
Angular Ivy is the latest compiler for angular application and a pipeline of rendering and compilation of next generation.
Read more >
Will the Angular Ivy view engine have a public API?
From what I can tell, the new Ivy view engine has the potential to solve this without all that bloat. I see that...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found