dotnet "PublishSingleFile" Errors (IL3000) in CI
Single-file publish (PublishSingleFile) bundles the app into one executable. Code that assumes files exist on disk - Assembly.Location, AppContext.BaseDirectory for embedded assets - breaks, and publish needs a RID. IL3000 flags the unsafe patterns.
What this error means
Publish fails (or warns under warnings-as-errors) with IL3000 about Assembly.Location being empty in a single-file app, or errors that single-file requires a RuntimeIdentifier. A normal publish works; only the single-file pipeline fails.
error IL3000: 'System.Reflection.Assembly.Location' always returns an empty string
for assemblies embedded in a single-file app.Common causes
Code assumes assemblies live on disk
In a single-file app the assemblies are embedded, so Assembly.Location is empty and path-based asset loading fails. IL3000 warns about exactly these calls.
Single-file publish without a RID / self-contained setting
PublishSingleFile needs a RuntimeIdentifier (and usually SelfContained). Without them, publish errors before producing the single file.
How to fix it
Avoid disk-path assumptions
Use AppContext.BaseDirectory only for files you explicitly copy alongside, and embed resources via the manifest instead of reading Assembly.Location.
// embedded resource instead of Assembly.Location path
using var s = typeof(Program).Assembly
.GetManifestResourceStream("MyApp.Resources.config.json");Publish single-file with a RID
Provide the runtime identifier (and self-contained) the single-file publish needs.
dotnet publish -c Release -r linux-x64 --self-contained true \
-p:PublishSingleFile=trueHow to prevent it
- Design asset loading around embedded resources or copied content, not
Assembly.Location. - Always pass a RID for single-file publish and test it in CI.
- Treat IL3000 warnings as real single-file hazards, not noise to suppress.