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

Custom marshalers cannot be used on fields of structures. #471

Closed
jcljb opened this issue Jul 10, 2024 · 1 comment
Closed

Custom marshalers cannot be used on fields of structures. #471

jcljb opened this issue Jul 10, 2024 · 1 comment

Comments

@jcljb
Copy link

jcljb commented Jul 10, 2024

When use Vanara.PInvoke.Shell32.SHFileOperation(SHFILEOPSTRUCT& lpFileOp) (target .NET 6.0)

got a System.TypeLoadException with
Message = "Cannot marshal field 'pFrom' of type 'SHFILEOPSTRUCT': Custom marshalers cannot be used on fields of structures."

What's wrong ?
Regards
JC

@dahall
Copy link
Owner

dahall commented Jul 10, 2024

You were correct, the definition of SHFILEOPSTRUCT was defined to use custom marshalers that aren't supported on structures. I have corrected it and supplied a test case to show its proper use.

using var from = SafeCoTaskMemHandle.CreateFromStringList([TestCaseSources.WordDoc, TestCaseSources.SmallFile]);
using var to = SafeCoTaskMemHandle.CreateFromStringList([TestCaseSources.TempChildDir]);
SHFILEOPSTRUCT shop = new() { wFunc = ShellFileOperation.FO_COPY, pFrom = from, pTo = to, fFlags = FILEOP_FLAGS.FOF_NOCONFIRMATION };
Win32Error.ThrowLastErrorIf(SHFileOperation(ref shop), i => i != 0);

You should be able to pull v4.0.3 from AppVeyor (see README) shortly and I'll release to NuGet in the next 2 weeks.

@dahall dahall closed this as completed Jul 10, 2024
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

2 participants