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

Windows Forms应用部署后加载System.Buffers 4.0.3.0失败求助

Windows Forms应用部署后加载System.Buffers失败问题

本地开发及安装包构建均无错误,运行一切正常,但将安装包部署到其他机器启动软件时,抛出以下异常:

See the end of this message for details on invoking 
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.TypeInitializationException: The type initializer for 'MySqlConnector.Core.ConnectionPool' threw an exception. ---> System.BadImageFormatException: Could not load file or assembly 'System.Buffers, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. Reference assemblies should not be loaded for execution.  They can only be loaded in the Reflection-only loader context. (Exception from HRESULT: 0x80131058) ---> System.BadImageFormatException: Cannot load a reference assembly for execution.
   --- End of inner exception stack trace ---
   at System.Text.ValueStringBuilder.Dispose()
   at System.Text.ValueStringBuilder.ToString()
   at Microsoft.Extensions.Logging.LogValuesFormatter..ctor(String format)
   at Microsoft.Extensions.Logging.LoggerMessage.CreateLogValuesFormatter(String formatString, Int32 expectedNamedParameterCount)
   at Microsoft.Extensions.Logging.LoggerMessage.Define[T1,T2](LogLevel logLevel, EventId eventId, String formatString, LogDefineOptions options)
   at Microsoft.Extensions.Logging.LoggerMessage.Define[T1,T2](LogLevel logLevel, EventId eventId, String formatString)
   at MySqlConnector.Core.ConnectionPool..cctor() in /_/src/MySqlConnector/Core/ConnectionPool.cs:line 816
   --- End of inner exception stack trace ---
   at MySqlConnector.Core.ConnectionPool.GetPool(String connectionString, MySqlConnectorLoggingConfiguration loggingConfiguration, Boolean createIfNotFound)
   at MySqlConnector.MySqlConnection.<OpenAsync>d__28.MoveNext() in /_/src/MySqlConnector/MySqlConnection.cs:line 399
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at MySqlConnector.MySqlConnection.Open() in /_/src/MySqlConnector/MySqlConnection.cs:line 381
   at DigitalSigner.DigitalSigner.Main.Main_Load(Object sender, EventArgs e)
   at System.EventHandler.Invoke(Object sender, EventArgs e)
   at System.Windows.Forms.Form.OnLoad(EventArgs e)
   at System.Windows.Forms.Form.OnCreateControl()
   at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
   at System.Windows.Forms.Control.CreateControl()
   at System.Windows.Forms.Control.WmShowWindow(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
   at System.Windows.Forms.Form.WmShowWindow(Message& m)
   at System.Windows.Forms.Form.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


************** Loaded Assemblies **************
mscorlib
    Assembly Version: 4.0.0.0
    Win32 Version: 4.8.4515.0 built by: NET48REL1LAST_C
    CodeBase: file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/mscorlib.dll
----------------------------------------
DigitalSigner
    Assembly Version: 18.6.0.0
    Win32 Version: 18.6.0.0
    CodeBase: file:///C:/Program%20Files%20(x86)/Pulkitsoft/Digital%20Signer/DigitalSigner.exe
----------------------------------------
Microsoft.VisualBasic
    Assembly Version: 10.0.0.0
    Win32 Version: 14.8.4084.0 built by: NET48REL1
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/Microsoft.VisualBasic/v4.0_10.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualBasic.dll
----------------------------------------
System
    Assembly Version: 4.0.0.0
    Win32 Version: 4.8.4536.0 built by: NET48REL1LAST_C
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Core
    Assembly Version: 4.0.0.0
    Win32 Version: 4.8.4536.0 built by: NET48REL1LAST_C
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Core/v4.0_4.0.0.0__b77a5c561934e089/System.Core.dll
----------------------------------------
System.Windows.Forms
    Assembly Version: 4.0.0.0
    Win32 Version: 4.8.4550.0 built by: NET48REL1LAST_C
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms/v4.0_4.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System.Drawing
    Assembly Version: 4.0.0.0
    Win32 Version: 4.8.4390.0 built by: NET48REL1LAST_C
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Drawing/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
System.Configuration
    Assembly Version: 4.0.0.0
    Win32 Version: 4.8.4190.0 built by: NET48REL1LAST_B
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Configuration/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
----------------------------------------
System.Xml
    Assembly Version: 4.0.0.0
    Win32 Version: 4.8.4084.0 built by: NET48REL1
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Xml/v4.0_4.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------
System.Runtime.Remoting
    Assembly Version: 4.0.0.0
    Win32 Version: 4.8.4084.0 built by: NET48REL1
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Runtime.Remoting/v4.0_4.0.0.0__b77a5c561934e089/System.Runtime.Remoting.dll
----------------------------------------
itextsharp
    Assembly Version: 5.5.13.2
    Win32 Version: 5.5.13.2
    CodeBase: file:///C:/Program%20Files%20(x86)/Pulkitsoft/Digital%20Signer/itextsharp.DLL
----------------------------------------
MySqlConnector
    Assembly Version: 2.0.0.0
    Win32 Version: 2.3.5.0
    CodeBase: file:///C:/Program%20Files%20(x86)/Pulkitsoft/Digital%20Signer/MySqlConnector.DLL
----------------------------------------
System.Data
    Assembly Version: 4.0.0.0
    Win32 Version: 4.8.4536.0 built by: NET48REL1LAST_C
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_32/System.Data/v4.0_4.0.0.0__b77a5c561934e089/System.Data.dll
----------------------------------------
System.Transactions
    Assembly Version: 4.0.0.0
    Win32 Version: 4.8.4084.0 built by: NET48REL1
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_32/System.Transactions/v4.0_4.0.0.0__b77a5c561934e089/System.Transactions.dll
----------------------------------------
Microsoft.Extensions.Logging.Abstractions
    Assembly Version: 7.0.0.1
    Win32 Version: 7.0.723.27404
    CodeBase: file:///C:/Program%20Files%20(x86)/Pulkitsoft/Digital%20Signer/Microsoft.Extensions.Logging.Abstractions.DLL
----------------------------------------
AutoUpdater.NET
    Assembly Version: 1.6.4.0
    Win32 Version: 1.6.4.0
    CodeBase: file:///C:/Program%20Files%20(x86)/Pulkitsoft/Digital%20Signer/AutoUpdater.NET.DLL
----------------------------------------
CustomMarshalers
    Assembly Version: 4.0.0.0
    Win32 Version: 4.8.4084.0 built by: NET48REL1
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_32/CustomMarshalers/v4.0_4.0.0.0__b03f5f7f11d50a3a/CustomMarshalers.dll
----------------------------------------
System.Threading.Tasks.Extensions
    Assembly Version: 4.2.0.1
    Win32 Version: 4.6.28619.01
    CodeBase: file:///C:/Program%20Files%20(x86)/Pulkitsoft/Digital%20Signer/System.Threading.Tasks.Extensions.DLL
----------------------------------------
System.Memory
    Assembly Version: 4.0.1.2
    Win32 Version: 4.6.31308.01
    CodeBase: file:///C:/Program%20Files%20(x86)/Pulkitsoft/Digital%20Signer/System.Memory.DLL
----------------------------------------
System.Diagnostics.DiagnosticSource
    Assembly Version: 7.0.0.2
    Win32 Version: 7.0.423.11508
    CodeBase: file:///C:/Program%20Files%20(x86)/Pulkitsoft/Digital%20Signer/System.Diagnostics.DiagnosticSource.DLL
----------------------------------------
System.Runtime.CompilerServices.Unsafe
    Assembly Version: 6.0.0.0
    Win32 Version: 6.0.21.52210
    CodeBase: file:///C:/Program%20Files%20(x86)/Pulkitsoft/Digital%20Signer/System.Runtime.CompilerServices.Unsafe.DLL
----------------------------------------

************** JIT Debugging **************
To enable just-in-time (JIT) debugging, the .config file for this
application or computer (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.

For example:

<configuration>
    <system.windows.forms jitDebugging="true" />
</configuration>

When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the computer
rather than be handled by this dialog box.

已尝试的方案

在app.config中添加程序集绑定重定向配置,但问题未解决:

<runtime>
      <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
        <dependentAssembly>
          <assemblyIdentity name="System.Buffers" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
          <bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
        </dependentAssembly>
      </assemblyBinding>
    </runtime>

解决建议

  • 检查System.Buffers程序集部署情况:确认安装包输出目录中存在System.Buffers.dll,且该文件是运行时程序集(而非引用程序集)。引用程序集通常位于Reference Assemblies目录,运行时程序集可从NuGet包的lib文件夹获取。同时在项目引用属性中设置复制本地为True,确保构建时将其复制到输出目录。
  • 统一平台目标:检查项目的平台目标设置(如x86/x64/Any CPU),确保与部署机器的架构匹配。若本地是x64,部署到x86机器可能导致加载错误;若使用Any CPU,取消勾选“首选32位”选项再重新构建。
  • 调整绑定重定向配置:扩大版本范围或指定部署机器上实际存在的版本。例如:
    <runtime>
      <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
        <dependentAssembly>
          <assemblyIdentity name="System.Buffers" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
          <bindingRedirect oldVersion="0.0.0.0-4.0.4.0" newVersion="4.0.4.0" />
        </dependentAssembly>
      </assemblyBinding>
    </runtime>
    
    同时确保DigitalSigner.exe.config文件包含该配置,且随安装包部署到目标机器。
  • 验证MySqlConnector兼容性:当前使用的MySqlConnector 2.3.5可能与System.Buffers版本存在依赖冲突。尝试升级或降级MySqlConnector到稳定版本,确保其依赖的System.Buffers版本与项目中安装的一致。
  • 清理重建项目:删除项目的bin和obj目录,重新构建安装包,避免旧的引用程序集被错误包含。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.29 20:07:01