Migrating from [DllImport] to [LibraryImport] is sold as a performance story β ahead-of-time-friendly marshalling, no IL stub generated at runtime, trim-safe. There is a quieter consequence that matters just as much if you obfuscate: the source generator changes where the native entry-point name lives , and in doing so it turns P/Invoke from one of the most rename-hostile surfaces in .NET into one of the safest.
The real question
A native call has exactly one string that must survive: the export name the operating system loader looks up. With classic [DllImport] , that string is often your method's own name. Write [DllImport("user32.dll")] static extern int MessageBoxW(...) with no EntryPoint , and the runtime uses the managed name MessageBoxW as the export to resolve. Rename the method and you have renamed the lookup key β the call throws EntryPointNotFoundException at runtime, with nothing wrong at build time.β¦