Skip to content

Validate manually-configured ErrorMessageResourceType+Name against the specified resource type#6

Draft
Copilot wants to merge 2 commits into
masterfrom
copilot/add-unit-test-for-issue
Draft

Validate manually-configured ErrorMessageResourceType+Name against the specified resource type#6
Copilot wants to merge 2 commits into
masterfrom
copilot/add-unit-test-for-issue

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 15, 2026

When a user explicitly sets both ErrorMessageResourceType and ErrorMessageResourceName on a validation attribute, the weaver silently skipped all validation — meaning a missing resource key would not be caught at build time. Any validation that did occur would have checked against the global resource type rather than the specified one.

Changes

  • ModuleWeaver.cs: ScanMember now also collects attributes that have both ErrorMessageResourceType (non-null) and ErrorMessageResourceName explicitly set. ProcessClasses validates these manually-configured pairs against their specified type (grouped by TypeReference.FullName) rather than the global type. Attributes with ErrorMessage set are still skipped.

  • WeaverExecutor.cs: Added optional additionalEmbeddedResourceFiles parameter (IReadOnlyDictionary<string, IEnumerable<KeyValuePair<string, string?>>>) to support embedding multiple resource files in test assemblies.

  • AutoLocalizeValidationAttributesAttributeTests.cs: Two new tests covering the scenario with a non-global OtherStrings resource type:

    • Resource name exists in specified type → no error
    • Resource name missing from specified type → error referencing UnitTest.OtherStrings, not UnitTest.AppStrings
// Previously: silently skipped, missing key only caught at runtime
// Now: weaver validates "OtherStrings_Required" exists in UnitTest.OtherStrings.resources
[Required(
    ErrorMessageResourceType = typeof(UnitTest.OtherStrings),
    ErrorMessageResourceName = "OtherStrings_Required")]
public string Name { get; set; }

📱 Kick off Copilot coding agent tasks wherever you are with GitHub Mobile, available on iOS and Android.

…ame against specified resource type

Co-authored-by: mrpmorris <[email protected]>
Copilot AI changed the title [WIP] Fix issue and add unit test Validate manually-configured ErrorMessageResourceType+Name against the specified resource type Mar 15, 2026
Copilot AI requested a review from mrpmorris March 15, 2026 17:36
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

Successfully merging this pull request may close these issues.

2 participants