Skip to content

bug: fix 500 on Post create/edit (null-deref in DetailPostDto.TagNames) - #28

Open
devin-ai-integration[bot] wants to merge 1 commit into
devin/1784175515-aspnetcore-net10-migrationfrom
devin/net10-fix-post-create-tagnames
Open

bug: fix 500 on Post create/edit (null-deref in DetailPostDto.TagNames)#28
devin-ai-integration[bot] wants to merge 1 commit into
devin/1784175515-aspnetcore-net10-migrationfrom
devin/net10-fix-post-create-tagnames

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Jul 16, 2026

Copy link
Copy Markdown

Summary

Fixes an unhandled HTTP 500 when saving a Post via /Posts/Create, /Posts/Edit, /PostsAsync/Create, /PostsAsync/Edit on the migrated .NET 10 app. Found during end-to-end testing of the merged web-migration (PR #25).

Root cause — behavior difference between MVC5 and ASP.NET Core model validation. ASP.NET Core's ValidationVisitor walks the posted model graph and evaluates computed getters. DetailPostDto/DetailPostDtoAsync expose a display-only:

public string TagNames { get { return string.Join(", ", Tags.Select(x => x.Name)); } }

but Tags is [ScaffoldColumn(false)], is never model-bound on POST, and isn't initialized in the ctor → it's null when the visitor invokes the getter → ArgumentNullException: Value cannot be null. (Parameter 'source') thrown before the controller action runs. Classic MVC5's validator never invoked this getter, so the bug was latent.

Fix — make the display-only getter null-safe (sync + async DTOs):

public string TagNames { get { return Tags == null ? string.Empty : string.Join(", ", Tags.Select(x => x.Name)); } }

Minimal by design: no ctor/mapping changes, no controller changes, purely guards the getter.

Scope note

This touches ServiceLayer (2 files), which was migrated in a sibling subsession — but it's a genuine web-blocking runtime bug with no viable fix in the web project (the DTO is the validated model, and [ValidateNever] isn't available without pulling an ASP.NET Core MVC reference into the service layer). No DataLayer/BizLayer/Tests changes.

Verification

dotnet build SampleWebApp/SampleWebApp.csproj succeeds on net10.0. Re-testing Post create/edit end-to-end against SQL Server; results posted as a PR comment.

Link to Devin session: https://app.devin.ai/sessions/395506e0330e4a789b2aec401bd66cf7


Devin Review

Status Commit
⚪ Not started

Run Devin Review

Open in Devin Review (Staging)

…Names

ASP.NET Core's validation visitor evaluates the computed TagNames getter on
the posted DTO, but Tags is [ScaffoldColumn(false)], never model-bound, and
null at that point -> ArgumentNullException before the controller runs.
Make the display-only getter null-safe (affects sync + async DTOs).

Co-Authored-By: Parker Duff <pwjduff@gmail.com>
@devin-ai-integration

Copy link
Copy Markdown
Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

@devin-ai-integration

Copy link
Copy Markdown
Author

✅ Re-test: Post create/edit 500 is fixed (via Devin session)

Checked out devin/net10-fix-post-create-tagnames, rebuilt, reran against SQL Server 2022, and re-tested the previously-failing flows through the UI. The null-safe TagNames getter resolves the ArgumentNullExceptionall pass.

Flow Result
/Posts/Create valid post ✅ Saved ("Successfully created the post.")
/Posts/Edit ✅ Saved ("Successfully updated the post.")
/PostsAsync/Create ✅ Saved
/PostsAsync/Edit ✅ Saved
Empty-form client validation ✅ Still blocks submit
Posts index lists new posts ✅ (ids 35 & 36)

Re-test recording:

re-test recording

Sync Post created (was a 500 before):

Post created

Async create + edit evidence

Async created
Async edited

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.

0 participants