我最近使用 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
uj5u.com熱心網友回復:
如果您查看正在使用的函式多載的檔案RegistryKey.OpenSubKey,您會看到通過提供true您試圖以寫訪問權限打開它的引數。您還將看到,如果您無權寫入該密鑰,它將拋出SecurityException您所看到的內容。
由于您的代碼只是讀取密鑰,而不是嘗試寫入它,因此請嘗試提供false作為引數。或者嘗試查看其他多載之一。
此外,using陳述句應該使您不必顯式呼叫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);
}
}
}
uj5u.com熱心網友回復:
問題是我在CheckBox.IsChecked == true;
下面放了InitializeComponent();
我還為 Checkbox 設定了 Checked 和 Unchecked 的事件觸發器,因此我收到了錯誤。為了解決這個問題,我為復選框設定了 Click 事件處理程式,而不是 Checked 和 Unchecked。這是我在“點擊事件處理程式”中添加的內容:
private void Disable_Xbox_Services_Click(object sender, RoutedEventArgs e)
{
string[] keys = {
@"SYSTEM\CurrentControlSet\Services\XblGameSave",
@"SYSTEM\CurrentControlSet\Services\XboxNetApiSvc",
@"SYSTEM\CurrentControlSet\Services\XboxGipSvc",
@"SYSTEM\CurrentControlSet\Services\XblAuthManager",
};
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)
{
}
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/521344.html
標籤:C#。网wpf点击一次
