Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 27, 2025

Proposed changes

BaseEventState.MemberwiseClone() throws an exception because it calls Activator.CreateInstance(GetType()) without passing the required parent argument. All BaseEventState inheritors (e.g., NonExclusiveLimitAlarmState, AlarmState) only have a constructor requiring NodeState parent.

Fix: Pass Parent to Activator.CreateInstance(), matching the correct pattern in BaseObjectState.MemberwiseClone():

// Before (broken)
var clone = (BaseEventState)Activator.CreateInstance(GetType());

// After (fixed)
var clone = (BaseEventState)Activator.CreateInstance(GetType(), Parent);

Added unit tests for BaseEventState and derived type cloning.

Related Issues

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • Enhancement (non-breaking change which adds functionality)
  • Test enhancement (non-breaking change to increase test coverage)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected, requires version increase of Nuget packages)
  • Documentation Update (if none of the other choices apply)

Checklist

  • I have read the CONTRIBUTING doc.
  • I have signed the CLA.
  • I ran tests locally with my changes, all passed.
  • I fixed all failing tests in the CI pipelines.
  • I fixed all introduced issues with CodeQL and LGTM.
  • I have added tests that prove my fix is effective or that my feature works and increased code coverage.
  • I have added necessary documentation (if appropriate).
  • Any dependent changes have been merged and published in downstream modules.

Further comments

N/A

Original prompt

This section details on the original issue you should resolve

<issue_title>BaseEventState.MemberwiseClone() has incorrect implementations</issue_title>
<issue_description>### Type of issue

  • Bug
  • Enhancement
  • Compliance
  • Question
  • Help wanted

Current Behavior

BaseEventState.MemberviseClone() throws exception.

Expected Behavior

call of MemberviseClone() on BaseEventState inheritor instances should creates deep clones.

Steps To Reproduce

Try to call MemberviseClone() on any AlarmState inheritor instance.

Environment

- OS: any
- Environment: any
- Runtime: any
- Nuget Version: 1.5.376.244
- Component: Opc.Ua.Core/Stack/State/

Anything else?

BaseEventState and inheritors do not have parameterless constructor but have a constructor with argument "parent". MemberwiseClone() for them doesn't take into account required argument "parent" of their constructor.

Sample for NonExclusiveLimitAlarmState and BaseEventState:
the only consructors:
public NonExclusiveLimitAlarmState(NodeState parent) : base(parent) { }
public BaseEventState(NodeState parent) : base(parent) { }

MemberwiseClone() have incorrect implementations defined in BaseEventState:
public new object MemberwiseClone() { BaseEventState clone = (BaseEventState)Activator.CreateInstance(this.GetType()); return CloneChildren(clone); }

In the same time more correct implementation should be like in BaseObjectState:
public new object MemberwiseClone() { BaseObjectState clone = (BaseObjectState)Activator.CreateInstance(this.GetType(), this.Parent); return CloneChildren(clone); }

I do not understand why special (incorrect) implementation of MemberwiseClone() is needed for BaseEventState and why base implementation from BaseObjectState is not used instead...
</issue_description>

<agent_instructions>Please fix this issue</agent_instructions>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

…teInstance

Co-authored-by: romanett <7413710+romanett@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix incorrect implementations of BaseEventState.MemberwiseClone() Fix BaseEventState.MemberwiseClone() to pass Parent to Activator.CreateInstance Nov 27, 2025
Copilot AI requested a review from romanett November 27, 2025 14:52
@romanett romanett requested review from salihgoncu and removed request for romanett November 27, 2025 15:00
@romanett romanett assigned salihgoncu and unassigned romanett Dec 1, 2025
@romanett romanett marked this pull request as ready for review December 4, 2025 05:33
@marcschier marcschier merged commit b8ed3cc into master Dec 4, 2025
129 of 130 checks passed
@romanett romanett deleted the copilot/fix-memberwise-clone-implementation branch December 4, 2025 14:40
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.

BaseEventState.MemberwiseClone() has incorrect implementations

5 participants