Skip to content

[Bug]: Dnn 10.2.1 breaks 2sxc because of changes in DnnJsInclude #6902

@iJungleboy

Description

@iJungleboy

Is there an existing issue for this?

  • I have searched the existing issues

What happened?

Basically if 2sxc uses ClientDependency it crashes.
This started in 10.2.0 and got a fix in 10.2.1 but it not working properly.
The result is a full blown IIS crash, unhandled win32 exception

Image

Reason is that 2sxc creates a DnnJsInclude and adds it to the page. We will change our code to work around the problem, but anybody upgrading DNN with a current or older 2sxc will crash the entire IIS process - see 2sic/2sxc#3717.

Here's how our code works:

var include = new DnnJsInclude 
{
    ForceProvider = DnnProviderName(clientAsset.PosInPage), 
    Priority = clientAsset.Priority, 
    FilePath = clientAsset.Url, 
    AddTag = false
};

// direct dependency on ClientDependency.Core.dll (included in default DNN installation)
if (clientAsset.HtmlAttributes?.Count > 0)
{
    // not important for this issue
}
// THIS IS WHERE IT BLOWS
page.FindControl("ClientResourceIncludes")?.Controls.Add(include);

The problem is probably here:

[Obsolete("Deprecated in DotNetNuke 10.2.1. Use overload with IClientResourceController. Scheduled removal in v12.0.0.")]
public DnnJsInclude()
: this(null)
{
}
/// <summary>Initializes a new instance of the <see cref="DnnJsInclude"/> class with default settings.</summary>
/// <param name="clientResourceController">The client resources controller.</param>
public DnnJsInclude(IClientResourceController clientResourceController)
{
this.clientResourceController = clientResourceController ?? DependencyInjection.GetCurrentServiceProvider().GetRequiredService<IClientResourceController>();
this.ForceProvider = ClientResourceProviders.DefaultJsProvider;
this.DependencyType = ClientDependencyType.Javascript;
}
/// <inheritdoc cref="IScriptResource.Async" />
public bool Async { get; set; }
/// <inheritdoc cref="IScriptResource.Defer" />
public bool Defer { get; set; }
/// <inheritdoc cref="IScriptResource.NoModule" />
public bool NoModule { get; set; }
/// <inheritdoc/>
protected override void OnLoad(System.EventArgs e)
{
var script = this.clientResourceController.CreateScript(this.FilePath, this.PathNameAlias);

Basically an empty constructor was "added back" - which I guess was a great idea, but later on it expects a service which doesn't exist in the empty constructor scenario. My guess is that in certain cases, the empty constructor doesn't properly run this:

protected override void OnLoad(System.EventArgs e)
{
var script = this.clientResourceController.CreateScript(this.FilePath, this.PathNameAlias);
if (this.Async)
{
script = script.SetAsync();
}

I guess the problem is that this property

private readonly IClientResourceController clientResourceController;

My guess is as follows

  1. I think that the compiler adds another empty constructor (just a guess) to web controls
  2. ...and that we're probably calling that, instead of the new one but I'm just guessing. If my guess is correct, the this(null) would not be called. Or there is a problem that the built-in webcontrol base constructor is not called. again, just guessing.

So again: we'll create a 2sxc 21.0x soon to work around this, as we were only using this API to work around something, which was later added to DNN. But anybody upgrading DNN without previously upgrading 2sxc will run into problems.

My guess for a fix would be something like:

private IClientResourceController clientResourceController => field ??= DependencyInjection.GetCurrentServiceProvider().GetRequiredService<IClientResourceController>();

...might fix the problem - @donker

Steps to reproduce?

  1. install any 2sxc up to v21.00.01 on the latest DNN.
  2. Add a normal app or content-module, which wants to register JS dependencies.
  3. See IIS crash.

Current Behavior

see above

Expected Behavior

No response

Relevant log output

Anything else?

No response

Affected Versions

10.2.0 (latest v10 release)

What browsers are you seeing the problem on?

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions