ManagedDism icon indicating copy to clipboard operation
ManagedDism copied to clipboard

Commit Image error the value of '102' is not valid for 'value'

Open i2i8 opened this issue 3 years ago • 7 comments

When I commit install.wim, it cannot unmount normally DismApi.UnmountImage(mountedImageInfo.MountPath, commitChanges: true, progressCallback: ImageProgressCallback); the error is as follows:

System. Argumentoutofrangeexception: the value of '102' is not valid for 'value'. 'value' should be between'minimum'and'maximum'. (Parameter 'value')

When I discard install.wim, it can unmount normally DismApi.UnmountImage(mountedImageInfo.MountPath, commitChanges: false, progressCallback: ImageProgressCallback);

i2i8 avatar Jul 11 '22 17:07 i2i8

Does ImageProgressCallback do something special? Is the managed DISM API here on the callstack for the exception?

jeffkl avatar Jul 11 '22 18:07 jeffkl

This line is probably throwing:

MoHelper.ProgressBar.Value = progress.Current;

I'm not sure why but the DISMAPI value for progress.Current is not always 0-100. If you want to safely calculate progress by percent, you'll need to probably use Total and divide by Current?

The documentation doesn't specify what values to expect: https://docs.microsoft.com/en-us/windows-hardware/manufacture/desktop/dism/dismprogresscallback?view=windows-11

jeffkl avatar Jul 11 '22 18:07 jeffkl

I didn't fully understand the instructions in the link above. Can you give some examples?

i2i8 avatar Jul 11 '22 18:07 i2i8

Like this? MoHelper.ProgressBar.Value = progress.Total / progress.Current;

i2i8 avatar Jul 11 '22 18:07 i2i8

Like this? If it looks like this, the error is as follows: System.DivideByZeroException: Attempted to divide by zero.

i2i8 avatar Jul 11 '22 18:07 i2i8

From the above code, you can get a sense of what I want to achieve. I am not sure if the code I wrote is elegant, can you give me an elegant implementation of MountImage or UnMountImage saving method?

i2i8 avatar Jul 11 '22 19:07 i2i8