1 hour ago · Tech · hide · 0 comments

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 =…

No comments yet. Log in to reply on the Fediverse. Comments will appear here.