question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

System.AccessViolationException when calling LsaOpenPolicy with a remote machine name

See original GitHub issue

Describe 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. image

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
dahallcommented, Sep 14, 2020

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.

0reactions
dahallcommented, Sep 15, 2020

Thank you. It’s for comments like yours that I keep doing it.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found