Assembly-related API behavior changes for single-file publishing format
Multiple APIs related to an assembly's file location have behavior changes when they're invoked in a single-file publishing format.
In single-file publishing for .NET 5 and later versions, bundled assemblies are loaded from memory instead of extracted to disk. For single-file published apps, this means that certain location-related APIs return different values on .NET 5 and later than on previous versions of .NET. The changes are as follows:
|API||Previous versions||.NET 5 and later|
|Assembly.Location||Returns extracted DLL file path||Returns empty string for bundled assemblies|
|Assembly.CodeBase||Returns extracted DLL file path||Throws exception for bundled assemblies|
||Throws exception for bundled assemblies|
||Value is the name of the entry point DLL||Value is the name of the host executable|
|AppContext.BaseDirectory||Value is the temporary extraction directory||Value is the containing directory of the host executable|
Avoid dependencies on the file location of assemblies when publishing as a single file.