Skip to content

fix: 载体程序集装进核心所在的装载上下文 - #40

Merged
residua1 merged 2 commits into
mainfrom
fix/carrier-assembly-context
Nov 19, 2026
Merged

residua1 merged 2 commits into
mainfrom
fix/carrier-assembly-context

Conversation

@residua1

Copy link
Copy Markdown
Contributor

真机验收抓到的缺陷:载体包声明 carrier.bootstrap 时,Endstone 载体启动即失败,日志报「载体引导 … 不是带公开无参构造的 ICarrierServicesConfigurator」。

两处原因都在装载上下文与装配方式:

  • 原生宿主经 hostfxr 的组件方式起核心,核心落在 IsolatedComponentLoadContext;Hosihikari.Plugin.Abstractions 这些依赖只在那张表上。按路径装程序集却走默认上下文,bootstrap 的类型因此解析不到它的依赖——GetType(..., throwOnError: false) 把 FileNotFoundException 吞成 null,报出来就成了"不是配置器"。
  • 原先用 Assembly.LoadFrom:它挂的是包目录探测,会把上下文里已经有的契约再装一份,同名类型于是有两个类型对象,ICarrierServicesConfigurator 转型失败。

改法:CarrierStartup.ResolveAssembly 在核心自己所在的上下文里装,并先按简单名认已装的那份;StartComponents 的组件解析走同一条规则,不再各写一遍。

验证

  • 管理器宿主断言 98/98 通过(含 A58、A61、A62、A63、A64、A65、A66、A67、A68、A69)。
  • 实机:BDS 26.60.6 + Endstone 0.11.15,整包 14 个共享程序集 + 3 个组件 + bootstrap 起来;插件载入、reload 复用核心、退出干净。日志见 PR 讨论。

宿主断言跑在默认上下文,复现不出这条;守它的是实机验收。

真机验收抓到的:Endstone 载体带 bootstrap 时启动即失败——配置器类型取不到。
两处原因都在装载上下文与装配方式:

- 原生宿主经 hostfxr 的组件方式起核心,核心落在 IsolatedComponentLoadContext,
  Hosihikari.Plugin.Abstractions 这类依赖只在那个上下文里;按路径装程序集却用
  的是默认上下文,bootstrap 的类型因此解析不到它的依赖(GetType 抛
  FileNotFoundException,被 throwOnError:false 吞成 null)。
- 原先走 Assembly.LoadFrom:它挂的是包目录探测,会把上下文里已经有的契约再装
  一份,同名类型于是有两个类型对象,ICarrierServicesConfigurator 转型失败。

改为在核心自己所在的上下文里装,并先按简单名认已装的那份;组件的解析也走同
一条规则,不再各写一遍。宿主断言跑在默认上下文,复现不出这条,靠实机验收守。
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-18T09:10:26.938098Z e9d3f88 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a564e9d765

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/CarrierStartup.cs
return File.Exists(path)
? Assembly.LoadFrom(path)
: Assembly.Load(new AssemblyName(Path.GetFileNameWithoutExtension(fileName)));
? context.LoadFromAssemblyPath(Path.GetFullPath(path))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve package-local dependency probing in the core context

When a carrier bootstrap or component references a private DLL shipped beside it but absent from the core's dependency graph and carrier.sharedAssemblies, switching from Assembly.LoadFrom to LoadFromAssemblyPath removes the sibling-directory dependency probing. Loading the entry assembly succeeds, but resolving or executing its types can now throw FileNotFoundException, causing TryConfigure or StartComponents to reject the carrier. These packages are supported by Packager.ValidateCarrier, which resolves against all package DLLs, and the packer copies those dependencies into the package. Keep loading into the core context, but add package-local dependency resolution that reuses already-loaded contracts.

Useful? React with 👍 / 👎.

按路径装载不挂包目录探测,包里只住在载体目录、又不在共享层清单里的私有
DLL 会解析不到(Codex 评审在 #40 上指出)。在核心所在的上下文上补一个
Resolving 解析器:只有正常解析失败才轮到它,命中包内文件才装;已装着的
契约仍是一份,不会装出第二个类型对象。
@residua1

Copy link
Copy Markdown
Contributor Author

Codex 的 P2 已修(e9d3f88):EnsurePackageResolver 在核心所在的上下文上挂一个 Resolving 解析器,正常解析失败才轮到它,命中包内文件才装。已经装着的契约仍走上下文自己的解析、只有一份,所以既恢复了包目录的依赖探测,也不会回到同名类型装两份。宿主断言 98/98 通过。

@residua1
residua1 merged commit 32ec031 into main Nov 19, 2026
5 checks passed
@residua1
residua1 deleted the fix/carrier-assembly-context branch November 19, 2026 01:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants