Skip to content

Conversation

@AaronRobinsonMSFT
Copy link
Member

This was an oversight from #102636.
Added tests.

Fixes #117838

This was an oversight from dotnet#102636.
Added tests.
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR enables Activator.CreateInstance<T>() to work with ByRefLike types (ref structs) that have constructors, which was previously blocked. The change allows generic activation of ref structs while maintaining the restriction that they cannot be boxed through non-generic activation methods.

Key changes:

  • Modified the validation logic to permit ByRefLike types in generic activation scenarios
  • Added comprehensive tests for ref struct activation with and without constructors
  • Updated existing tests to reflect the new capability

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/libraries/System.Private.CoreLib/src/System/Activator.RuntimeType.cs Minor comment typo fix
src/libraries/System.Runtime/tests/System.Runtime.Tests/System/ActivatorTests.cs Added test cases for ref struct activation and consolidated existing Span tests
src/coreclr/vm/runtimehandles.h Removed unused function declaration
src/coreclr/vm/reflectioninvocation.cpp Enhanced validation function to conditionally allow ByRefLike types
src/coreclr/System.Private.CoreLib/src/System/RuntimeType.CoreCLR.cs Added explicit ByRefLike checks in boxed activation paths

@AaronRobinsonMSFT AaronRobinsonMSFT requested a review from jkotas July 22, 2025 20:58
Copy link
Member

@jkotas jkotas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@AaronRobinsonMSFT
Copy link
Member Author

/ba-g Known timeouts

@AaronRobinsonMSFT AaronRobinsonMSFT merged commit b306971 into dotnet:main Jul 23, 2025
136 of 145 checks passed
@AaronRobinsonMSFT AaronRobinsonMSFT deleted the runtime_117838 branch July 23, 2025 03:41
@github-actions github-actions bot locked and limited conversation to collaborators Aug 22, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Activator.CreateInstance doesn't work for ref structs with explicit constructors

2 participants