You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

.NET Core 6部署后单台机器无法加载BeginCollectionItemCore程序集求助

.NET Core 6应用部署异常:BeginCollectionItemCore程序集加载失败

问题背景

在.NET Core 6应用中使用v1.1.0版本的BeginCollectionItemCore,通过@using HtmlHelpers.BeginCollectionItemCore调用该程序集。应用发布后部署到本地IIS及多台Windows 10、Windows Server机器均正常,但其中一台机器抛出System.IO.FileNotFoundException,提示无法加载BeginCollectionItemCore程序集。报错堆栈指向Program.cs第22行的builder.Services.AddControllersWithViews(),但该行并非实际错误点。已在该机器安装dotnet-hosting-6.0.16-win.exe,且检查过IIS版本与设置,怀疑是IIS或系统问题,请求协助解决。

相关代码

@using HtmlHelpers.BeginCollectionItemCore
@using (Html.BeginCollectionItem("GiftCardInfos"))
{
<td>
    <input type="hidden" asp-for="Id">
    <input type="hidden" asp-for="GCNumber">
    <input type="hidden" asp-for="ActiveStatus" class="ActiveStatus">
    @Model.GCNumber
</td>
<td>
    <input type="hidden" asp-for="BuyingPrice">
    @Model.BuyingPrice
</td>
<td>
    <input type="hidden" asp-for="Quantity">
    @Model.Quantity
</td>
    <td>
        <input type="hidden" asp-for="AcquiredPrice">
        @Model.AcquiredPrice
    </td>
}

报错信息

Application: w3wp.exe
CoreCLR Version: 6.0.1623.17311
.NET Version: 6.0.16
Description: The process was terminated due to an unhandled exception.
Exception Info: System.IO.FileNotFoundException: Could not load file or assembly 'BeginCollectionItemCore, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.
File name: 'BeginCollectionItemCore, Culture=neutral, PublicKeyToken=null'
at System.Reflection.RuntimeAssembly.InternalLoad(ObjectHandleOnStack assemblyName, ObjectHandleOnStack requestingAssembly, StackCrawlMarkHandle stackMark, Boolean throwOnFileNotFound, ObjectHandleOnStack assemblyLoadContext, ObjectHandleOnStack retAssembly)
at System.Reflection.RuntimeAssembly.InternalLoad(AssemblyName assemblyName, RuntimeAssembly requestingAssembly, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, AssemblyLoadContext assemblyLoadContext)
at System.Reflection.Assembly.Load(String assemblyString)
at Microsoft.AspNetCore.Mvc.ApplicationParts.ApplicationPartManager.<>c.b__8_0(ApplicationPartAttribute name)
at System.Linq.Enumerable.SelectArrayIterator2.ToArray() at System.Linq.Buffer1..ctor(IEnumerable1 source) at System.Linq.OrderedEnumerable1.GetEnumerator()+MoveNext()
at System.Linq.Enumerable.SelectManySingleSelectorIterator2.MoveNext() at System.Linq.Enumerable.ConcatIterator1.MoveNext()
at Microsoft.AspNetCore.Mvc.ApplicationParts.ApplicationPartManager.PopulateDefaultParts(String entryAssemblyName)
at Microsoft.Extensions.DependencyInjection.MvcCoreServiceCollectionExtensions.GetApplicationPartManager(IServiceCollection services, IWebHostEnvironment environment)
at Microsoft.Extensions.DependencyInjection.MvcCoreServiceCollectionExtensions.AddMvcCore(IServiceCollection services)
at Microsoft.Extensions.DependencyInjection.MvcServiceCollectionExtensions.AddControllersCore(IServiceCollection services)
at Microsoft.Extensions.DependencyInjection.MvcServiceCollectionExtensions.AddControllersWithViewsCore(IServiceCollection services)
at Microsoft.Extensions.DependencyInjection.MvcServiceCollectionExtensions.AddControllersWithViews(IServiceCollection services)
at Program.

$(String[] args) in D:...\Program.cs:line 22

排查与解决步骤

  • 检查部署目录程序集:登录异常机器,找到IIS站点物理路径,确认BeginCollectionItemCore.dll存在且版本为v1.1.0。若缺失,重新发布并确保文件复制完整;若存在,右键文件→属性→常规,解除可能的“阻止”标记。
  • 验证依赖与运行时:本地用dotnet list package确认BeginCollectionItemCore依赖完整性;异常机器执行dotnet --info,确认.NET Core 6.0.16运行时正确安装(注意x86/x64架构与应用发布版本匹配)。可临时启用程序集加载日志:添加系统环境变量CORECLR_ENABLE_PROFILING=1、CORECLR_PROFILER={36032161-FFC0-4B61-B559-F6C5D41BAE5A}、CORECLR_PROFILER_PATH=C:\Windows\System32\mscorwks.dll,重启IIS后查看加载日志定位原因,排查完成后删除变量。
  • 检查IIS应用池配置:确认应用池.NET CLR版本设为“无托管代码”;检查应用池身份权限,可临时改为LocalSystem测试是否是权限问题;确认应用池32位模式开关与应用发布架构匹配(x64发布则禁用32位模式)。
  • 清理重新部署:删除部署目录所有文件,重新复制完整发布包;执行iisreset命令重启IIS,清除应用池缓存。
  • 排查系统冲突:用dotnet --list-runtimes查看已安装运行时,确保6.0.16优先级正常;临时关闭杀毒软件或安全工具,排查是否存在文件拦截。

内容的提问来源于stack exchange,提问作者Mohammed Sabbir

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.20 00:33:12