System.AccessViolationException when calling LsaOpenPolicy with a remote machine name
See original GitHub issueDescribe the bug When calling the overload of AdvApi32.LsaOpenPolicy take takes a computer name parameter, and access violation is thrown. Passing null as the computer name, or using the overload without the computer name parameter does not throw an exception.
What code is involved
AdvApi32.LSA_OBJECT_ATTRIBUTES lsaObjectAttributes = new AdvApi32.LSA_OBJECT_ATTRIBUTES();
var result = AdvApi32.LsaOpenPolicy(server, lsaObjectAttributes, AdvApi32.LsaPolicyRights.POLICY_VIEW_LOCAL_INFORMATION, out AdvApi32.SafeLSA_HANDLE pPolicyHandle);
result.ThrowIfFailed("LsaOpenPolicy failed");
Expected behavior The API call should succeed.
Screenshots If applicable, add screenshots to help explain your problem.
Issue Analytics
- State:
- Created 3 years ago
- Comments:10 (6 by maintainers)
Top Results From Across the Web
LsaOpenPolicy : Attempted to read or write protected memory
I'm trying to call LsaOpenPolicy, but get the error 'System.AccessViolationException'. ... As soon as I add a remote machine name though, it
Read more >c# - Programs randomly getting System. ...
Go to the System properties (Win8: WinKey+X, select 'System', Win7: Open 'Properties' from my computer); Advanced System Settings ...
Read more >AccessViolationException Class (System)
An access violation occurs in unmanaged or unsafe code when the code attempts to read or write to memory that has not been...
Read more >Error: Remote machine does not appear in a ...
Common causes for this error The remote debugger is not running on the remote machine. To fix this, start the remote debugger. The...
Read more >AccessViolationException, IIS - windows server 2008 r2
Exception type: HttpException Exception message: The remote host closed the connection. The error code is 0x80070057.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I think I found the problem. Under X64, the LSA_UNICODE_STRING struct aligns in memory differently. In my custom marshaler, I assume the X86 layout. I’ve corrected and am testing now.
Thank you. It’s for comments like yours that I keep doing it.