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

C# WPF应用ClickOnce发布后本地Win10正常,其他Win10设备启动失败求助

ClickOnce发布的WPF应用在Windows10部分机器启动失败,Win8兼容模式可运行

问题详情

用ClickOnce发布C# WPF应用后,自身Windows10设备运行正常,但另一台同系统设备无法启动。通过兼容性疑难解答设置为Windows8模式后应用可正常运行,需找到根本原因以避免用户手动操作。

事件查看器错误日志

错误信息1

at System.ThrowHelper.ThrowSecurityException(System.ExceptionResource)
   at Microsoft.Win32.RegistryKey.OpenSubKey(System.String, Boolean)
   at KrakenZ_Tweaker.UserControls.UserControl2.Disable_Xbox_Services_Checked(System.Object, System.Windows.RoutedEventArgs)
   at System.Windows.RoutedEventHandlerInfo.InvokeHandler(System.Object, System.Windows.RoutedEventArgs)
   at System.Windows.EventRoute.InvokeHandlersImpl(System.Object, System.Windows.RoutedEventArgs, Boolean)
   at System.Windows.UIElement.RaiseEventImpl(System.Windows.DependencyObject, System.Windows.RoutedEventArgs)
   at System.Windows.UIElement.RaiseEvent(System.Windows.RoutedEventArgs)
   at System.Windows.Controls.Primitives.ToggleButton.OnChecked(System.Windows.RoutedEventArgs)
   at System.Windows.Controls.Primitives.ToggleButton.OnIsCheckedChanged(System.Windows.DependencyObject, System.Windows.DependencyPropertyChangedEventArgs)
   at System.Windows.DependencyObject.OnPropertyChanged(System.Windows.DependencyPropertyChangedEventArgs)
   at System.Windows.FrameworkElement.OnPropertyChanged(System.Windows.DependencyPropertyChangedEventArgs)
   at System.Windows.DependencyObject.NotifyPropertyChange(System.Windows.DependencyPropertyChangedEventArgs)
   at System.Windows.DependencyObject.UpdateEffectiveValue(System.Windows.EntryIndex, System.Windows.DependencyProperty, System.Windows.PropertyMetadata, System.Windows.EffectiveValueEntry, System.Windows.EffectiveValueEntry ByRef, Boolean, Boolean, System.Windows.OperationType)
   at System.Windows.DependencyObject.SetValueCommon(System.Windows.DependencyProperty, System.Object, System.Windows.PropertyMetadata, Boolean, Boolean, System.Windows.OperationType, Boolean)
   at System.Windows.Controls.Primitives.ToggleButton.set_IsChecked(System.Nullable`1<Boolean>)
   at KrakenZ_Tweaker.UserControls.UserControl2..ctor()
   at KrakenZ_Tweaker.MainWindow..ctor()

Exception Info: System.Reflection.TargetInvocationException
   at System.RuntimeTypeHandle.CreateInstance(System.RuntimeType, Boolean, Boolean, Boolean ByRef, System.RuntimeMethodHandleInternal ByRef, Boolean ByRef)
   at System.RuntimeType.CreateInstanceSlow(Boolean, Boolean, Boolean, System.Threading.StackCrawlMark ByRef)
   at System.RuntimeType.CreateInstanceDefaultCtor(Boolean, Boolean, Boolean, System.Threading.StackCrawlMark ByRef)
   at System.Activator.CreateInstance(System.Type, Boolean)
   at System.RuntimeType.CreateInstanceImpl(System.Reflection.BindingFlags, System.Reflection.Binder, System.Object[], System.Globalization.CultureInfo, System.Object[], System.Threading.StackCrawlMark ByRef)
   at System.Activator.CreateInstance(System.Type, System.Reflection.BindingFlags, System.Reflection.Binder, System.Object[], System.Globalization.CultureInfo, System.Object[])
   at System.Activator.CreateInstance(System.Type, System.Object[])
   at System.Xaml.Schema.SafeReflectionInvoker.CreateInstanceCritical(System.Type, System.Object[])
   at System.Xaml.Schema.SafeReflectionInvoker.CreateInstance(System.Type, System.Object[])
   at System.Xaml.Schema.XamlTypeInvoker.CreateInstance(System.Object[])
   at MS.Internal.Xaml.Runtime.ClrObjectRuntime.CreateInstanceWithCtor(System.Xaml.XamlType, System.Object[])
   at MS.Internal.Xaml.Runtime.ClrObjectRuntime.CreateInstance(System.Xaml.XamlType, System.Object[])
   at System.Xaml.XamlObjectWriter.Logic_CreateAndAssignToParentStart(MS.Internal.Xaml.Context.ObjectWriterContext)
   at System.Xaml.XamlObjectWriter.WriteStartMember(System.Xaml.XamlMember)
   at System.Xaml.XamlWriter.WriteNode(System.Xaml.XamlReader)
   at System.Windows.Markup.WpfXamlLoader.TransformNodes(System.Xaml.XamlReader, System.Xaml.XamlObjectWriter, Boolean, Boolean, Boolean, System.Xaml.IXamlLineInfo, System.Xaml.IXamlLineInfoConsumer, MS.Internal.Xaml.Context.XamlContextStack`1<System.Windows.Markup.WpfXamlFrame>, System.Windows.Markup.IStyleConnector)
   at System.Windows.Markup.WpfXamlLoader.Load(System.Xaml.XamlReader, System.Xaml.IXamlObjectWriterFactory, Boolean, System.Object, System.Xaml.XamlObjectWriterSettings, System.Uri)
   at System.Windows.Markup.WpfXamlLoader.LoadBaml(System.Xaml.XamlReader, Boolean, System.Object, System.Xaml.Permissions.XamlAccessLevel, System.Uri)
   at System.Windows.Markup.XamlReader.LoadBaml(System.IO.Stream, System.Windows.Markup.ParserContext, System.Object, Boolean)
   at System.Windows.Application.LoadBamlStreamWithSyncInfo(System.IO.Stream, System.Windows.Markup.ParserContext)
   at System.Windows.Application.LoadComponent(System.Uri, Boolean)
   at System.Windows.Application.DoStartup()
   at System.Windows.Application.<.ctor>b__1_0(System.Object)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate)
   at System.Windows.Threading.DispatcherOperation.InvokeImpl()
   at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(System.Object)
   at MS.Internal.CulturePreservingExecutionContext.CallbackWrapper(System.Object)
   at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
   at MS.Internal.CulturePreservingExecutionContext.Run(MS.Internal.CulturePreservingExecutionContext, System.Threading.ContextCallback, System.Object)
   at System.Windows.Threading.DispatcherOperation.Invoke()
   at System.Windows.Threading.Dispatcher.ProcessQueue()
   at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef)
   at MS.Win32.HwndWrapper.WndProc(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef)
   at MS.Win32.HwndSubclass.DispatcherCallbackOperation(System.Object)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate)
   at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority, System.TimeSpan, System.Delegate, System.Object, Int32)
   at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr, Int32, IntPtr, IntPtr)
   at MS.Win32.UnsafeNativeMethods.DispatchMessage(System.Windows.Interop.MSG ByRef)
   at System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame)
   at System.Windows.Threading.Dispatcher.PushFrame(System.Windows.Threading.DispatcherFrame)
   at System.Windows.Application.RunDispatcher(System.Object)
   at System.Windows.Application.RunInternal(System.Windows.Window)
   at System.Windows.Application.Run(System.Windows.Window)
   at KrakenZ_Tweaker.App.Main()

错误信息2

Faulting application name: KrakenZ Tweaker.exe, version: 1.0.0.0, time stamp: 0xb3f073bc
Faulting module name: KERNELBASE.dll, version: 10.0.19041.1288, time stamp: 0x3e55bd0b
Exception code: 0xe0434352
Fault offset: 0x0012b5b2
Faulting process id: 0x130
Faulting application start time: 0x01d8e3095e6e54e8
Faulting application path: C:\Users\nevat\AppData\Local\Apps\2.0\YW14JZH9.DZ8\WQ9TP99E.PRA\krak..tion_f4f8753dddbedea6_0001.0000_7a77a162166539c7\KrakenZ Tweaker.exe
Faulting module path: C:\Windows\System32\KERNELBASE.dll
Report Id: 9912415b-acac-4a3d-bedb-24d07417ebb2
Faulting package full name: 
Faulting package-relative application ID: 

错误信息3

Fault bucket 2059872029189490063, type 5
Event Name: CLR20r3
Response: Not available
Cab Id: 0

Problem signature:
P1: KrakenZ Tweaker.exe
P2: 1.0.0.0
P3: de4d2f9f
P4: mscorlib
P5: 4.8.4515.0
P6: 624cf315
P7: 340
P8: 10
P9: N3CTRYE2KN3C34SGL4ZQYRBFTE4M13NB
P10: 

Attached files:\n\\?\C:\ProgramData\Microsoft\Windows\WER\Temp\WERCBE7.tmp.dmp
\\?\C:\ProgramData\Microsoft\Windows\WER\Temp\WERCDFB.tmp.WERInternalMetadata.xml
\\?\C:\ProgramData\Microsoft\Windows\WER\Temp\WERCE3A.tmp.xml

These files may be available here:
\\?\C:\ProgramData\Microsoft\Windows\WER\ReportArchive\AppCrash_KrakenZ Tweaker._829d1d36f9ea56e8517d64b3be67bf83e37261_780215cd_c5b1fb2f-51d2-4d41-b1b7-3ff3c56dfd8c

Analysis symbol: 
Rechecking for solution: 0
Report Id: 80bb5e81-84c9-4e03-b56a-a8e65a2a558c
Report Status: 268435456
Hashed bucket: c5259aa8925522deac9622b2669a458f
Cab Guid: 0

原因分析

从错误栈可以明确,崩溃的核心是权限不足导致的SecurityException:

  1. 应用启动时,UserControl2的构造函数会设置ToggleButton的IsChecked属性,触发Disable_Xbox_Services_Checked事件。
  2. 该事件方法尝试调用RegistryKey.OpenSubKey访问系统注册表,但ClickOnce默认的部分信任权限集不允许此类操作。
  3. Windows8兼容模式会调整UAC权限检查策略,降低注册表访问的限制,因此应用能正常运行。

解决方案

  1. 调整ClickOnce权限配置:
    • 打开项目属性→安全性选项卡,勾选“启用ClickOnce安全设置”,将权限级别改为“完全信任应用程序”,重新发布。完全信任模式下应用拥有足够权限访问系统注册表。
  2. 优化注册表访问逻辑:
    • 避免在控件构造函数、初始化阶段触发注册表操作,将这类逻辑移到用户主动交互时(比如用户点击开关按钮)。
    • 对注册表访问代码添加异常捕获,当权限不足时给出明确提示,引导用户以管理员身份运行应用。
  3. 适配Win10原生权限模型:
    • 如果应用需要修改系统级注册表,可在应用清单中添加requestedExecutionLevel节点,设置为requireAdministrator(注意ClickOnce应用启用管理员权限会有发布限制,可能需要改用传统安装包方式)。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.15 16:45:44