Skip to content

Add MemberAccessException and MissingMethodException - #316

Merged
josesimoes merged 2 commits into
nanoframework:developfrom
josesimoes:add-member-access-exceptions
Nov 25, 2026
Merged

josesimoes merged 2 commits into
nanoframework:developfrom
josesimoes:add-member-access-exceptions

Conversation

@josesimoes

@josesimoes josesimoes commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

Description

  • Added MemberAccessException, MissingMemberException and MissingMethodException to mscorlib (reflection build), with the .NET hierarchy.
  • Activator.CreateInstance<T>() throws MissingMethodException for abstract types, interfaces and types without a public parameterless constructor, as .NET.
  • Updated the Activator unit tests to the new exception.
  • Added unit tests for the public constructor lookup, abstract and open generic types, and casts at and over the generic limits.

Motivation and Context

  • nanoCLR was throwing NotSupportedException where .NET throws these exceptions; the types didn't exist.
  • They are also used by the nanoCLR for ConstructorInfo.Invoke of abstract and open generic types (MemberAccessException).
  • Behaviour change: code catching NotSupportedException from Activator.CreateInstance<T>() has to catch MissingMethodException.
  • Related with Support for generics <T> Home#782.

How Has This Been Tested?

Screenshots

Types of changes

  • Improvement (non-breaking change that improves a feature, code or algorithm)
  • Bug fix (non-breaking change which fixes an issue with code or algorithm)
  • New feature (non-breaking change which adds functionality to code)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Config and build (change in the configuration and build system, has no impact on code or features)
  • Dependencies (update dependencies and changes associated, has no impact on code or features)
  • Unit Tests (add new Unit Test(s) or improved existing one(s), has no impact on code or features)
  • Documentation (changes or updates in the documentation, has no impact on code or features)

Checklist:

  • My code follows the code style of this project (only if there are changes in source code).
  • My changes require an update to the documentation (there are changes that require the docs website to be updated).
  • I have updated the documentation accordingly (the changes require an update on the docs in this repo).
  • I have read the CONTRIBUTING document.
  • I have tested everything locally and all new and existing tests passed (only if there are changes in source code).
  • I have added new tests to cover my changes.

@nfbot nfbot left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

✅ The PR template looks good now. Thanks!

@coderabbitai

coderabbitai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Explain Change →

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Central YAML; Path: .coderabbit.yaml
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 85fc5a4b-96b7-4ab5-8775-a0e5a50c1b1e

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • New Features
    • Added standard member-access and missing-member exception types for reflection-enabled applications.
  • Bug Fixes
    • Activator.CreateInstance<T>() now throws MissingMethodException when the type is abstract or has no public parameterless constructor.

The change adds three reflection exception types and updates Activator.CreateInstance<T>() to throw MissingMethodException when a type is abstract or lacks a public parameterless constructor. The related test expectations also change.

Changes: Activator Exception Update

Layer / File(s) Summary
Add reflection exception types
nanoFramework.CoreLibrary/System/MemberAccessException.cs, nanoFramework.CoreLibrary/System/MissingMemberException.cs, nanoFramework.CoreLibrary/System/MissingMethodException.cs, nanoFramework.CoreLibrary/CoreLibrary.nfproj
Adds the reflection exception hierarchy and includes its source files in the project.
Update Activator exception behavior
nanoFramework.CoreLibrary/System/Activator.cs, Tests/NFUnitTestSystemLibReflection3/UnitTestActivatorTests.cs
Activator.CreateInstance<T>() documents and throws MissingMethodException for the described construction failures. The tests now expect that exception.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Feature

Possibly related PRs

Merge Risk: Minimal · previous review f94c7

This adds standard reflection exception types and changes Activator.CreateInstance to throw MissingMethodException instead of NotSupportedException. Callers that catch NotSupportedException will need to catch the new type. The change looks safe to merge.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "Add MemberAccessException and MissingMethodException" names the main change: two new exception types added to the reflection build. It does not mention the Activator.CreateInstance() beh…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description check Passed The description is on-topic. It states that MemberAccessException, MissingMemberException and MissingMethodException are added to the reflection build of mscorlib. It states that Activator.CreateInsta…
Full details: Title check

Explanation

The title "Add MemberAccessException and MissingMethodException" names the main change: two new exception types added to the reflection build. It does not mention the Activator.CreateInstance<T>() behavior change or the test updates, but it refers to a real and central part of the changeset.

Full details: Description check

Explanation

The description is on-topic. It states that MemberAccessException, MissingMemberException and MissingMethodException are added to the reflection build of mscorlib. It states that Activator.CreateInstance<T>() now throws MissingMethodException for abstract types, interfaces, and types without a public parameterless constructor. It also lists the updated Activator unit tests, the new tests, and the behaviour change for callers that catch NotSupportedException. These points match the changeset and the PR objectives.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Central YAML; Path: .coderabbit.yaml
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: cc39fcb6-2d74-48a4-b9a2-035040fa7222
Commits

Reviewing files that changed from the base of the PR and between 71a7ccb and f94c797.

Files selected for processing: 6

  • Tests/NFUnitTestSystemLibReflection3/UnitTestActivatorTests.cs
  • nanoFramework.CoreLibrary/CoreLibrary.nfproj
  • nanoFramework.CoreLibrary/System/Activator.cs
  • nanoFramework.CoreLibrary/System/MemberAccessException.cs
  • nanoFramework.CoreLibrary/System/MissingMemberException.cs
  • nanoFramework.CoreLibrary/System/MissingMethodException.cs

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@josesimoes

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@nfbot

nfbot commented Nov 25, 2026

Copy link
Copy Markdown
Member

⚠️ Native declaration update required!

The native contract hash of nanoFramework.CoreLibrary has changed. The native declaration in nf-interpreter must be updated before this package can be released.

Previously published This build
Native contract hash 0x940E6E23 0x272B0DC7

👉 Tracking issue: nanoframework/Home#1957

The issue contains a link to the stubs artifact from this build and instructions for GitHub Copilot to perform the update.

@josesimoes
josesimoes force-pushed the add-member-access-exceptions branch from f94c797 to 22de530 Compare November 25, 2026 14:19
@josesimoes

Copy link
Copy Markdown
Member Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

@josesimoes
josesimoes force-pushed the add-member-access-exceptions branch from e414401 to 6746115 Compare November 25, 2026 15:25
@josesimoes
josesimoes force-pushed the add-member-access-exceptions branch from 6746115 to 3ded1c0 Compare November 25, 2026 15:30
@josesimoes
josesimoes force-pushed the add-member-access-exceptions branch 3 times, most recently from 7078283 to 41deba7 Compare November 25, 2026 17:37
josesimoes and others added 2 commits November 25, 2026 17:47
- Add MemberAccessException, MissingMemberException and MissingMethodException.
- Activator.CreateInstance<T> throws MissingMethodException.
- Update tests.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
- Add tests for the public constructor lookup and for abstract and open generic types.
- Add tests for casts at and over the generic node and nesting limits.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@josesimoes
josesimoes force-pushed the add-member-access-exceptions branch from 41deba7 to 82ed4f1 Compare November 25, 2026 17:47
@sonarqubecloud

Copy link
Copy Markdown

@josesimoes
josesimoes merged commit c676bc9 into nanoframework:develop Nov 25, 2026
6 checks passed
@josesimoes
josesimoes deleted the add-member-access-exceptions branch November 25, 2026 18:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants