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

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
Labels

Comments

@mroskamp
Copy link
Contributor

mroskamp commented Jan 4, 2024

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 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:

  1. In an IConfigureOptions<ResourceManagementOptions>, register a new resource. For example, a script called "MyScript". Don't specify a version.
  2. 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".
  3. Require the resource. For example, in Layout.cshtml, use the script tag helper to require "MyScript" and don't specify a version.
  4. 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.

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