You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
ArgumentNullException from ResourceManager.FindMatchingResource when multiple resources are defined with the same name and at least one doesn't specify a version.
#14991
Closed
mroskamp opened this issue
Jan 4, 2024
· 0 comments
· Fixed by #14992
I have 2 scripts defined. A "default" version that doesn't specify a version. In another module, I define an override of that resource by defining a resource with the same name and specifying a version number. When I run the site, the script resources fail to load due to an ArgumentNullException.
The issue lies in ResourceManager.FindMatchingResource, because when evaluating the second match, resource.Version is null, which causes new Version(resource.Version) to throw the ArgumentNullException. Note that earlier in the method, the code takes care to avoid the ArgumentNullException by checking for null.
A work around for this issue is to just make sure that all resources specify a version, but since the version is not required by the API, it should handle null gracefully.
To Reproduce
Steps to reproduce the behavior:
In an IConfigureOptions<ResourceManagementOptions>, register a new resource. For example, a script called "MyScript". Don't specify a version.
Additionally, register a second resource with the same name and this time also call SetVersion with a valid version number. For example, "MyScript" with a version of "1.0.0".
Require the resource. For example, in Layout.cshtml, use the script tag helper to require "MyScript" and don't specify a version.
Run the site and notice that the script doesn't load (in fact, no scripts load). Also notice that you receive the following error in the log:
2024-01-04T14:01:25.6549337-05:00|Local|0HN0DATOGCGSU:00000007|OrchardCore.ResourceManagement.TagHelpers.ResourcesTagHelper|ERR|An error occurred while rendering "HeadScript" resource.
System.ArgumentNullException: Value cannot be null. (Parameter 'input')
at System.ArgumentNullException.Throw(String paramName)
at System.Version.Parse(String input)
at System.Version..ctor(String version)
at OrchardCore.ResourceManagement.ResourceManager.FindMatchingResource(IEnumerable`1 stream, RequireSettings settings, String name)
at OrchardCore.ResourceManagement.ResourceManager.FindResource(RequireSettings settings, Boolean resolveInlineDefinitions)
at OrchardCore.ResourceManagement.ResourceManager.FindResource(RequireSettings settings)
at OrchardCore.ResourceManagement.ResourceManager.DoGetRequiredResources(String resourceType)
at OrchardCore.ResourceManagement.ResourceManager.RenderHeadScript(TextWriter writer)
at OrchardCore.ResourceManagement.TagHelpers.ResourcesTagHelper.Process(TagHelperContext tagHelperContext, TagHelperOutput output)
2024-01-04T14:01:25.7205291-05:00|Local|0HN0DATOGCGSU:00000007|OrchardCore.ResourceManagement.TagHelpers.ResourcesTagHelper|ERR|An error occurred while rendering "FootScript" resource.
System.ArgumentNullException: Value cannot be null. (Parameter 'input')
at System.ArgumentNullException.Throw(String paramName)
at System.Version.Parse(String input)
at System.Version..ctor(String version)
at OrchardCore.ResourceManagement.ResourceManager.FindMatchingResource(IEnumerable`1 stream, RequireSettings settings, String name)
at OrchardCore.ResourceManagement.ResourceManager.FindResource(RequireSettings settings, Boolean resolveInlineDefinitions)
at OrchardCore.ResourceManagement.ResourceManager.FindResource(RequireSettings settings)
at OrchardCore.ResourceManagement.ResourceManager.DoGetRequiredResources(String resourceType)
at OrchardCore.ResourceManagement.ResourceManager.RenderFootScript(TextWriter writer)
Expected behavior
I would expect version 1.0.0 of the resource to be loaded on the page (winning out over the one without a version, and not throwing an error).
Screenshots
If applicable, add screenshots to help explain your problem.
The text was updated successfully, but these errors were encountered:
Describe the bug
I have 2 scripts defined. A "default" version that doesn't specify a version. In another module, I define an override of that resource by defining a resource with the same name and specifying a version number. When I run the site, the script resources fail to load due to an ArgumentNullException.
The issue lies in ResourceManager.FindMatchingResource, because when evaluating the second match,
resource.Version
is null, which causesnew Version(resource.Version)
to throw the ArgumentNullException. Note that earlier in the method, the code takes care to avoid the ArgumentNullException by checking for null.A work around for this issue is to just make sure that all resources specify a version, but since the version is not required by the API, it should handle null gracefully.
To Reproduce
Steps to reproduce the behavior:
IConfigureOptions<ResourceManagementOptions>
, register a new resource. For example, a script called "MyScript". Don't specify a version.SetVersion
with a valid version number. For example, "MyScript" with a version of "1.0.0".Layout.cshtml
, use the script tag helper to require "MyScript" and don't specify a version.Expected behavior
I would expect version 1.0.0 of the resource to be loaded on the page (winning out over the one without a version, and not throwing an error).
Screenshots
If applicable, add screenshots to help explain your problem.
The text was updated successfully, but these errors were encountered: