Skip to content

Conversation

JonRobidus
Copy link
Contributor

@JonRobidus JonRobidus commented Jul 18, 2025

Fix: "A concurrent update was performed on this collection and corrupted its state."

Don't share XmlNamespaceManager kept in a singleton with request scoped objects that modify it to avoid state corruption.

XmlNamespaceManager Is not thread safe!

…ed objects that modify it to avoid state corruption.
@JonRobidus JonRobidus changed the title Don't share XmlNamespaceManager kept in a singleton with request scop… Fix: "A concurrent update was performed on this collection and corrupted its state." Jul 19, 2025
@nevsnirG
Copy link

Perhaps a cleaner fix would be to make the middleware factory based instead of singleton. We had the same bug and wrote our own middleware wrapper which would instantiate and invoke an instance of the SoapCoreMiddleware per request. If the middleware would just be registered as transient then this issue would also be resolved.

@janv97
Copy link

janv97 commented Aug 20, 2025

I get the same error message. Did you guys already implemented a work around or are you still waiting on the merge request to be merged?

@JonRobidus
Copy link
Contributor Author

We implemented a workaround. See issue #743.
This PR is still waiting for approval.

@andersjonsson
Copy link
Collaborator

Thank you for this PR! Looks good!

This bug was most likely introduced by the caching that I added in #1123 so the cleanest fix would be to simply remove that, but I prefer this PR since we get to keep the perf benefits of caching.

It would be fairly easy to implement a custom XmlNamespaceManager that uses a ConcurrentDictionary instead of a Dictionary, but that could become a mess if Microsoft ever changes the implementation of XmlNamespaceManager.

So I'll get this PR merged now. Thanks again!

@andersjonsson andersjonsson merged commit 7266d6c into DigDes:develop Aug 21, 2025
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.

4 participants