Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sparse Package sample does not show how to uninstall the sparse package #17

Open
mikebmcl opened this issue Mar 13, 2021 · 0 comments
Open

Comments

@mikebmcl
Copy link

The sample uses a magic string in its Startup.removeSparsePackage method rather than obtaining the package's full name so that it can be uninstalled. It also defines the P/Invoke for kernel32.dll's GetCurrentPackageFullName function in the ExecuteMode class incorrectly.

The sample defines the StringBuilder parameter for GetCurrentPackageFullName using ref, which causes an HRESULT 0x80004003 "Attempted to read or write protected memory. This is often an indication that other memory is corrupt." when trying to use it to actually get the package name (in the sample it never attempts to write to the StringBuilder's memory when it calls it so the problem never surfaces). Removing ref solves the problem because the .NET marshaler handles StringBuilder specially. All that needs to be done is ensure it has the minimum required capacity, pass it in without using ref, and the marshaler will write the string directly to the StringBuilder's internal memory.

Fixing that makes it possible to modify Startup.removeSparsePackage to get the actual package name and use that to remove the package. I resolved these issues and will be sending a pull request with the fixes.

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

No branches or pull requests

1 participant