【问题标题】:My C# WPF app runs on my pc but not on other pc?我的 C# WPF 应用程序在我的电脑上运行,但不在其他电脑上?
【发布时间】:2022-10-25 00:38:00
【问题描述】:

我最近使用 ClickOnce 发布了我的 C# 应用程序。当我在使用 Windows 10 的 PC 上运行我的应用程序时,它运行良好,但是当我尝试使用也安装了 Windows 10 的另一台 PC 时,它无法打开。我尝试使用兼容性疑难解答程序,它向我推荐了 win 8 的设置,并且在应用其推荐的设置后,我的应用程序在我的另一台电脑上运行良好。请告诉我为什么会发生这个问题?我知道当我们使用疑难解答时它会解决,但我会分发这个应用程序,这会给用户带来困难 手动打开它。我的源代码在这里可用:https://github.com/Yuvaan17/KrakenZ_Tweaker

我检查了事件查看器,这里是调试详细信息-
这是第一条错误消息:

     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()

这是第二条错误消息:

 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:
\\?\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

【问题讨论】:

  • 发布问题时,该论坛通常希望您发布导致问题的实际代码,而不是指向它的链接。这使用户不必为了理解问题而点击链接)

标签: c# .net wpf clickonce


【解决方案1】:

如果您查看您正在使用的RegistryKey.OpenSubKey 函数的重载的the documentation,您将看到通过提供true 作为您试图以写访问权限打开它的参数。您还将看到,如果您没有写入该密钥的权限,它将抛出您所看到的 SecurityException

由于您的代码只是读取密钥,而不是尝试写入密钥,因此请尝试提供 false 作为参数。或者尝试查看其他重载之一。

using statement 也可以让您不必在注册表项对象上显式调用 Dispose

编辑:你说即使在这之后它也不起作用。我假设您无法在任何客户端计算机上进行调试。是这样吗?

如果是这样,您需要某种日志记录来注销异常的文本。一个简单的事实是,您需要能够看到异常的内容。如果您的应用程序中还没有某种记录器,请添加它。恐怕这只是调试 101。除此之外,我对你没有任何帮助。

我已经重写了你的 UserControl2 类的第 76 到 95 行

  • 我输入了一个 using 语句。这将为您调用 Dispose
  • 我去掉了不必要的finally 子句和dict2.Remove 调用。
  • 我添加了一行来记录消息文本(带有注释“SOMETHING LIKE THIS”)

这是代码

foreach (var key in keys1)
{
    using var rkey = Registry.LocalMachine.OpenSubKey(key, false)
    {
        try
        {
            // If the GetValue call throws, nothing is added to "dict2"

            dict2.Add(key, Convert.ToUInt32(rkey.GetValue("Start", RegistryValueKind.DWord)));
        }
        catch (Exception ex)
        {
            Log.WriteLine(ex.Message()); // SOMETHING LIKE THIS
            dict2.Add(key, 0);
        }
    }
}

【讨论】:

  • 我按照你说的做了,之后我的应用程序仍然无法运行。它给出了一个不同的例外,该例外在问题中进行了更新。
  • 我编辑了我的回复。这就是我所拥有的一切我害怕
  • 嘿,对于像你一样使用 using 语句,它说它不支持 c# 版本 7.3,并且至少需要 8.0。我无法在 .net 框架中真正更新它。
  • 哦,对不起,在那种情况下,你可以使用旧的方式来做。这应该适用于 C# 7.3 我发布的方式只是更现代的方式。我已经编辑了我的帖子给你看。
  • 它仍然不起作用。
【解决方案2】:

问题是我放了CheckBox.IsChecked == true; 就在InitializeComponent();下方 我还为 Checkbox 设置了 Checked 和 Unchecked 的事件触发器,因此我收到了错误。为了解决这个问题,我为复选框设置了 Click 事件处理程序,而不是 Checked 和 Unchecked。这是我在“点击事件处理程序”中添加的内容:

private void Disable_Xbox_Services_Click(object sender, RoutedEventArgs e)
        {
            string[] keys = {
       @"SYSTEMCurrentControlSetServicesXblGameSave",
       @"SYSTEMCurrentControlSetServicesXboxNetApiSvc",
       @"SYSTEMCurrentControlSetServicesXboxGipSvc",
       @"SYSTEMCurrentControlSetServicesXblAuthManager",

                            };

            if (Disable_Xbox_Services.IsChecked==true)
            {
               

                foreach (string key in keys)
                {

                    try
                    {
                        RegistryKey newKey = Registry.LocalMachine.OpenSubKey(key, true);
                        newKey.SetValue("Start", 4, RegistryValueKind.DWord);
                    }
                    catch (Exception)
                    {
                    }

                }
            }
            else
            {
                foreach (string key in keys)
                {

                    try
                    {
                        RegistryKey newKey = Registry.LocalMachine.OpenSubKey(key, true);
                        newKey.SetValue("Start", 3, RegistryValueKind.DWord);
                    }
                    catch (Exception)
                    {
                    }
}


    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-12-22
    • 1970-01-01
    • 2020-10-09
    • 2014-09-18
    • 2018-05-02
    • 1970-01-01
    • 1970-01-01
    • 2015-08-04
    相关资源
    最近更新 更多