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

Assembly.GetTypes() problem #103

Open
fbordignon opened this issue Jul 19, 2021 · 2 comments
Open

Assembly.GetTypes() problem #103

fbordignon opened this issue Jul 19, 2021 · 2 comments

Comments

@fbordignon
Copy link

fbordignon commented Jul 19, 2021

Hi guys, I am using managedCuda as part of a dll that is loaded as plugin for another C# software.
To package the plugin, an application provided by the software vendor runs the following piece of code:

private static IEnumerable<Type> GetPluginsFromAssembly(Assembly assembly) => ((IEnumerable<Type>) 
                                    assembly.GetTypes()).Where<Type>((Func<Type, bool>)
                                       (p => typeof (Plugin).IsAssignableFrom(p) && p.IsPublic && !p.IsAbstract));

From what I gather it is listing all types inside the .dll that I've built and its dependencies to search for plugins.
But when it gets to the managedCuda.dll it crashes with the following exception:

[0]	{"Could not load type 'ManagedCuda.BasicTypes.CudaExternalMemoryHandleDesc' from assembly 
'ManagedCuda, Version=11.0.43.0, Culture=neutral, PublicKeyToken=242d898828717aa0'
 because it contains an object field at 
offset 4 that is incorrectly aligned or overlapped by a non-object 
 field.":"ManagedCuda.BasicTypes.CUDA_EXTERNAL_MEMORY_HANDLE_DESC"}	
System.Exception {System.TypeLoadException}

Do you happen to know why this is happennig and if I can compile managedCuda in such a way to prevent this?

I've tried to compile managedCuda in 64bit only with no success. Aligning the fields to 8 bits offsets can solve this?

@kunzmi
Copy link
Owner

kunzmi commented Jul 19, 2021

Hi,

I was fighting a lot with ManagedCuda.BasicTypes.CudaExternalMemoryHandleDesc to get the fields aligned as in the original C struct (C# and C-unions don't go well together), and NVidia also changed it for the newer versions...
I'm not totally sure if the current layout actually works for all cases, so far no one seems to have ever used it (it is only used for the new graphics API interop replacing the older OpenGL/DirectX interfaces). And your DLL-loader mechanism seems to check stronger than the actual compiler. So just delete the two struct members that are aligned to FieldOffset 4 and it should run smoothly.

Cheers
Michael

@fbordignon
Copy link
Author

Hey Michael, removing the two fields with offset 4 does the trick!
Me and a teammate were battling this one for the good part of the last week thinking it was something with the vendor's software because we had issues before.
Anyways, I own you a beer or a beverage of choice 🤣

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