Skip to content

Commit 587d43a

Browse files
author
Alex J Lennon
committed
Fix VersionInfo.cs for single-file app builds
Fix IL3000 error: Assembly.Location returns empty string in single-file apps. Check if Location is empty and return "Unknown" instead of trying to access file info. This allows the code to compile for single-file deployments. The build date should come from assembly metadata anyway, so this fallback is rarely needed.
1 parent 5590ef2 commit 587d43a

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/VersionInfo.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,17 @@ private static string GetBuildDate()
3838
}
3939
}
4040

41-
// Fallback: use file write time
41+
// Fallback: use file write time (not available in single-file apps)
4242
try
4343
{
44-
var fileInfo = new FileInfo(assembly.Location);
44+
var location = assembly.Location;
45+
// In single-file apps, Location is empty - use AppContext.BaseDirectory instead
46+
if (string.IsNullOrEmpty(location))
47+
{
48+
// Single-file app - can't get file write time, return Unknown
49+
return "Unknown";
50+
}
51+
var fileInfo = new FileInfo(location);
4552
return fileInfo.LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss UTC");
4653
}
4754
catch

0 commit comments

Comments
 (0)