Can not unsubscribe from LogEntriesChanged event. #478

Closed
opened 2025-12-29 15:24:46 +01:00 by adam · 5 comments
Owner

Originally created by @IamHF on GitHub (Jan 4, 2023).

Originally assigned to: @StefH on GitHub.

Describe the bug

Cannot unsubscribe from "LogEntriesChanged" event handler because a new delegate is created inside the add method of the event.

Expected behavior:

You should be able to unsubscribe from "LogEntriesChanged" with the same event handler that is used to subscribe to the event.

Test to reproduce

``

public event NotifyCollectionChangedEventHandler LogEntriesChanged { add { _options.LogEntries.CollectionChanged += (sender, eventRecordArgs) => { try { value(sender, eventRecordArgs); } catch (Exception exception) { _options.Logger.Error("Error calling the LogEntriesChanged event handler: {0}", exception.Message); } }; } remove => _options.LogEntries.CollectionChanged -= value; }
https://github.com/WireMock-Net/WireMock.Net/blob/master/src/WireMock.Net/Server/WireMockServer.LogEntries.cs

Originally created by @IamHF on GitHub (Jan 4, 2023). Originally assigned to: @StefH on GitHub. ### Describe the bug Cannot unsubscribe from "LogEntriesChanged" event handler because a new delegate is created inside the add method of the event. ### Expected behavior: You should be able to unsubscribe from "LogEntriesChanged" with the same event handler that is used to subscribe to the event. ### Test to reproduce `` ### Other related info `public event NotifyCollectionChangedEventHandler LogEntriesChanged { add { _options.LogEntries.CollectionChanged += (sender, eventRecordArgs) => { try { value(sender, eventRecordArgs); } catch (Exception exception) { _options.Logger.Error("Error calling the LogEntriesChanged event handler: {0}", exception.Message); } }; } remove => _options.LogEntries.CollectionChanged -= value; }` [https://github.com/WireMock-Net/WireMock.Net/blob/master/src/WireMock.Net/Server/WireMockServer.LogEntries.cs](url)
adam added the bug label 2025-12-29 15:24:46 +01:00
adam closed this issue 2025-12-29 15:24:46 +01:00
Author
Owner

@StefH commented on GitHub (Jan 6, 2023):

@IamHF
Can you try preview version: 1.5.13-ci-16909

https://github.com/WireMock-Net/WireMock.Net/wiki/MyGet-preview-versions

@StefH commented on GitHub (Jan 6, 2023): @IamHF Can you try preview version: `1.5.13-ci-16909` https://github.com/WireMock-Net/WireMock.Net/wiki/MyGet-preview-versions
Author
Owner

@StefH commented on GitHub (Jan 6, 2023):

https://github.com/WireMock-Net/WireMock.Net/issues/870

@StefH commented on GitHub (Jan 6, 2023): https://github.com/WireMock-Net/WireMock.Net/issues/870
Author
Owner

@StefH commented on GitHub (Jan 11, 2023):

@IamHF Can you please test that preview version?

@StefH commented on GitHub (Jan 11, 2023): @IamHF Can you please test that preview version?
Author
Owner

@StefH commented on GitHub (Jan 15, 2023):

@IamHF
Can you please verify if that preview NuGet fixes your problem?

@StefH commented on GitHub (Jan 15, 2023): @IamHF Can you please verify if that preview NuGet fixes your problem?
Author
Owner

@StefH commented on GitHub (Jan 19, 2023):

Code merged

@StefH commented on GitHub (Jan 19, 2023): Code merged
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net-wiremock#478