fix: match main assembly by PackageId metadata instead of AssemblyName

This commit is contained in:
jkdevito 2026-07-07 17:20:22 -05:00
parent 1e63b10aa4
commit c323c872fc

View file

@ -77,14 +77,15 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers
essentials.Version = Global.AssemblyVersion;
// The main program assembly (AssemblyName/PackageId "PepperDashEssentials") is what's
// actually published to NuGet, but this handler lives in PepperDash.Essentials.Core, which
// can't reference that project's types directly (Essentials -> Core, not the reverse).
// PluginLoader.EssentialsAssembly.Assembly is unreliable (often left null - see
// PluginLoader.SetEssentialsAssembly), so look it up directly from the loaded AppDomain,
// falling back to this handler's own (Core) assembly if it can't be found.
// The main program assembly (PackageId "PepperDashEssentials") is what's actually published
// to NuGet, but this handler lives in PepperDash.Essentials.Core, which can't reference that
// project's types directly (Essentials -> Core, not the reverse). PluginLoader.EssentialsAssembly.Assembly
// is unreliable (often left null - see PluginLoader.SetEssentialsAssembly), so look it up
// directly from the loaded AppDomain by its Directory.Build.props-embedded PackageId metadata
// (every project's .csproj sets its own PackageId explicitly), falling back to this handler's
// own (Core) assembly if it can't be found.
var essentialsAssembly = AppDomain.CurrentDomain.GetAssemblies()
.FirstOrDefault(a => string.Equals(a.GetName().Name, "PepperDashEssentials", StringComparison.OrdinalIgnoreCase))
.FirstOrDefault(a => string.Equals(GetAssemblyMetadataValue(a, "PackageId"), "PepperDashEssentials", StringComparison.OrdinalIgnoreCase))
?? typeof(GetPackageManifestRequestHandler).Assembly;
var repoUrl = TrimTrailingGit(GetAssemblyMetadataValue(essentialsAssembly, "RepositoryUrl"));