0

When I try to run my C# application, it runs fine on my computer (from VS and when running the exe from the explorer). However, if I try to launch the application on any other computer, it crashes with two Errors, there is no message, these are from the Event Viewer Log. And I know what a null reference exception is, but MY computer runs the program, but other computers wont. I am asking WHAT is missing for the NullReferneceException to trigger!

First Log:

Application: FolderSearch.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.NullReferenceException
   at FolderSearch.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 MS.Internal.Xaml.Runtime.PartialTrustTolerantRuntime.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 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 FolderSearch.App.Main()

And the second Log:

Faulting application name: FolderSearch.exe, version: 1.0.0.0, time stamp: 0x59b7a459
Faulting module name: KERNELBASE.dll, version: 10.0.14393.1532, time stamp: 0x5965adf8
Exception code: 0xe0434352
Fault offset: 0x000da9f2
Faulting process id: 0x2f30
Faulting application start time: 0x01d32ba71864fe5a
Faulting application path: C:\temp\FolderSearchRelease\FolderSearch.exe
Faulting module path: C:\Windows\System32\KERNELBASE.dll
Report Id: 46e410b2-b20a-41c1-817a-883f64d01596
Faulting package full name: 
Faulting package-relative application ID: 

dotnet --info gives the following information:

.NET Command Line Tools (1.0.4)

Product Information:
 Version:            1.0.4
 Commit SHA-1 hash:  af1e6684fd

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.14393
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\PROGRAM FILES\DOTNET\sdk\1.0.4

My .Net Version is 4.6.01586, I targeted the application at 4.5.2 (Visual Studio defaulted to this) and I use VS 2017. It is a WPF program.

How can I fix this? There is no such thing as "..ctor()" in my program!

Heldenkrieger01
  • 338
  • 3
  • 16
  • 1
    `ctor()` denotes the (default) constructor of your `FolderSearch.MainWindow` class. – Filburt Sep 13 '17 at 12:12
  • how can I make it not being a NullReferenceException, since it's default? @Filburt – Heldenkrieger01 Sep 13 '17 at 12:33
  • 1
    This can only be answered seeing the code of MainWindow.xaml.cs. Default constructor doesn't mean there is no code - it just means it is the parameterless constructor for your MainWindow class. Most likely you are trying to initialize something related to a resource that doesn't exist on the target machine (like a file or folder path, etc.). – Filburt Sep 13 '17 at 12:41
  • The constructor only has one function call in it, InitializeComponent(), which is auto-generated code. I have now removed all code or calls in the MainWindow constructor, but it's still not working – Heldenkrieger01 Sep 13 '17 at 13:01
  • Next to check your MainWindow.xaml - any local references there? (pictures, icons, etc.) Any 3rd party control libraries? – Filburt Sep 13 '17 at 13:24
  • I reference /Pictures/icon.png as the Window Icon and /Pictures/xxxxx.png multiple times in the Window.Resources. the pictures are all set to "copy if newer". @Filburt – Heldenkrieger01 Sep 13 '17 at 13:56
  • Have you considered embedding your resources as described in [WPF image resources](https://stackoverflow.com/a/2416464/205233) instead? – Filburt Sep 13 '17 at 14:09
  • I moved all images as described in the answer and the pictures are indeed in the folder now, but the application still won't start (the Event Viewer shows the exact same error) @Filburt – Heldenkrieger01 Sep 13 '17 at 14:40
  • @Filburt the error was in this line: private bool _showPackageClone = (String.IsNullOrWhiteSpace(Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\WOW6432Node\\[company]\\[other application]", "Path", null).ToString())) ? false : true; It failed because I had null as the default return value. Thanks for your help tho, I am still going to keep the changes to my pictures :) – Heldenkrieger01 Sep 14 '17 at 06:17

0 Answers0