Home > Net >  My C# WPF app runs on my pc but not on other pc?
My C# WPF app runs on my pc but not on other pc?

Time:10-25

I have recently published my C# app using ClickOnce. When I run my app on my PC which uses windows 10, it runs fine but when I try using my other pc which too has windows 10 installed, it doesn't open. I tried using compatibility troubleshooter which recommended me the setting for win 8 and after applying its recommended settings, my app just works fine on my other pc. Pls tell me why is this issue happening? I know it resolves when we use the troubleshooter, but I would be distributing this app and it will make it difficult for users to manually turn it on. My source code is available here: https://github.com/Yuvaan17/KrakenZ_Tweaker

I had checked the event viewer and here are the debugging details-
Here is the first error message:

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

Here is the second error message:

 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: 

Here is the 3rd:

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

CodePudding user response:

If you look at the documentation of the overload of RegistryKey.OpenSubKey function you are using, you will see that by supplying true as the argument you are trying to open it with write access. You will also see that if you do not have permission to write to that key, it will throw the very SecurityException you are seeing.

Since your code is only reading the key, not attempting to write to it, try supplying false as the argument instead. Or try looking at one of the other overloads.

Also a using statement should save you from having to explicitly call Dispose on the registry key object

EDIT: You say even after this it does not work. I am assuming you are unable to debug on any client machine. Is that so?

If so, you need some kind of logging to log out the text of the exception. The simple fact is, You need to be able to see what the exception says. If you don't yet have some kind of logger in your app, add it. This is just Debugging 101, I'm afraid. I don't have any help for you beyond this.

I have rewritten lines 76 to 95 of your UserControl2 class

  • I put in a using statement. This will call Dispose for you
  • I got rid of the unnecessary finally clause and dict2.Remove call.
  • I added a line to log the message text (with comment "SOMETHING LIKE THIS")

Here's the code

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);
        }
    }
}

CodePudding user response:

The issue was that I had put CheckBox.IsChecked == true; just below InitializeComponent(); I also did set event triggers for Checked and Unchecked for the Checkbox due to which I was getting the error. To resolve this, I have set Click event handlers for the checkboxes instead of Checked and Unchecked. Here is the what I added in the 'Click event handler':

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)
                    {
                    }
}


    }
  • Related