Skip to content

Conversation

@sandermvanvliet
Copy link

When using the library when targeting net6.0 saving a credential will throw an exception:

System.TypeLoadException: Cannot marshal field 'LastWritten' of type 'WindowsCredentialManager.Win32.Types.CREDENTIALW': Structures marked with [StructLayout(LayoutKind.Auto)] cannot be marshaled.
   at WindowsCredentialManager.Win32.UnsafeNativeApi.CredWriteW(CREDENTIALW& credential, Int32 flags)
   at WindowsCredentialManager.Credential.Save()

This is because the LastWritten field on the CREDENTIALW type is set to be a DateTimeOffset which (in net6.0) has an attribute LayoutKind.Auto.

The CREDENTIALW win32 type defines that field as a FILETIME which has a .net equivalent through System.Runtime.Interop (see here)

Even though the LastWritten field is always ignored when writing, Marshaling still fails at this point because of the StructLayoutKind.Auto on DateTimeOffset.

This PR changes the type of LastWritten in the CREDENTIALW struct to be a FILETIME so that saving a credential works on net6.0.

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

Successfully merging this pull request may close these issues.

1 participant