73 days ago · Tech · hide · Fediverse post

I was reviewing some code and I saw this class I had no idea existed: NativeLibrary. In my case, I had a demo using different libraries that were doing similar things: parsing PostgreSQL code. However, some of them were wrapping the native pg_query library and were using different versions of it. The result were weird errors depending on which library was overwriting the file last. Solution: use NativeLibrary.SetDllImportResolver, which worked nicely. But what is this strange class? Introduced in .NET Core 3, NativeLibrary has several methods: Load and TryLoad - loading native libraries GetMainProgramHandle - get a handle to resolve exports from the entry point module GetExport and TryGetExport - get the address of an exported symbol Free - free a loaded native library SetDllImportResolver - sets a callback for resolving native library imports from an assembly In order to use a native library, you would do this in C#: [DllImport("libraryName", ... some optional stuff..., EntryPoint =…

Commenting on Bubbles has been removed. Why? If you want to talk about this post, write to the author, use the comments on their blog if it has them, or reply with a "RE:" post on your own blog. Suggestions? feedback@bubbles.town