fix(dism): reload imaging session when needed #460
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When DISM API returns
DISMAPI_S_RELOAD_IMAGE_SESSION_REQUIRED (0x00000001)
the session should automatically be reloaded. I looked at how the .NET library handles this, and have oriented the code to it:https://github.com/jeffkl/ManagedDism/blob/main/src/Microsoft.Dism/DismUtilities.cs#L304-L315
with the reload just closing the old and opening a new session without calling
DismInitialize
again: https://github.com/jeffkl/ManagedDism/blob/main/src/Microsoft.Dism/DismSession.cs#L57-L72To support this here, I needed to extend the session struct and also change the Handle to a pointer so that the call
defer dismSession.Close()
on the caller side doesn't close the initial handle again (already closed if a session reload happend) but instead closes the new handle (the new one created by the reload).This fixes #459 and it now works on Windows Server 2019/2022 and also Windows 10.
cc: @ItsMattL