Particular / ServiceControl

Backend for ServiceInsight and ServicePulse
https://docs.particular.net/servicecontrol/
Other
52 stars 47 forks source link

`NullReferenceException` in LicenseDialog makes it impossible to install license #628

Closed danielmarbach closed 8 years ago

danielmarbach commented 8 years ago

Who's affected

When the Details of a DetectedLicense instance are null the LicenseViewModel throws a NullReferenceException and makes it impossible to properly install the license over the license dialog.

Analysis

The root cause is probably how DetectedLicense constructs itself. If we call the constructor of DetectedLicense with the path and the license text and the validations in the constructor fail then a half initialized DetectedLicense instance is returned (whose Details are null). Since the LINQ statement in the LicenseViewModel always accesses the details in the lambda such a half initialized object throws a NullReferenceException inside p.Details.Valid.

Stack Trace

 ServiceControl.Config.UI.License.LicenseViewModel+<>c.<RefreshLicenseInfo>b__23_0(DetectedLicense p) in C:\BuildAgent\work\7189a56f9f44affc\src\ServiceControl.Config\UI\License\LicenseViewModel.cs:43
    System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source, Func`2 predicate):44
    ServiceControl.Config.UI.License.LicenseViewModel.RefreshLicenseInfo() in C:\BuildAgent\work\7189a56f9f44affc\src\ServiceControl.Config\UI\License\LicenseViewModel.cs:43
    ServiceControl.Config.UI.License.LicenseViewModel.OnActivate() in C:\BuildAgent\work\7189a56f9f44affc\src\ServiceControl.Config\UI\License\LicenseViewModel.cs:24
    ServiceControl.Config.Framework.Rx.RxScreen.Caliburn.Micro.IActivate.Activate() in C:\BuildAgent\work\7189a56f9f44affc\src\ServiceControl.Config\Framework\Rx\RxScreen.cs:75
    Caliburn.Micro.WindowManager+WindowConductor..ctor(Object model, Window view):30
    Caliburn.Micro.WindowManager.CreateWindow(Object rootModel, Boolean isDialog, Object context, IDictionary`2 settings):101
    Caliburn.Micro.WindowManager.ShowDialog(Object rootModel, Object context, IDictionary`2 settings):0
    ServiceControl.Config.Commands.OpenViewModelCommand`1.Execute(Object obj) in C:\BuildAgent\work\7189a56f9f44affc\src\ServiceControl.Config\Commands\OpenViewModelCommand.cs:19
    ServiceControl.Config.Framework.Commands.AbstractCommand`1.ServiceControl.Config.Framework.Commands.ICommand<T>.Execute(T obj) in C:\BuildAgent\work\7189a56f9f44affc\src\ServiceControl.Config\Framework\Commands\AbstractCommand.cs:22
    ServiceControl.Config.Framework.Commands.AbstractCommand`1.System.Windows.Input.ICommand.Execute(Object parameter) in C:\BuildAgent\work\7189a56f9f44affc\src\ServiceControl.Config\Framework\Commands\AbstractCommand.cs:28
    MS.Internal.Commands.CommandHelpers.CriticalExecuteCommandSource(ICommandSource commandSource, Boolean userInitiated):74
    System.Windows.Controls.Primitives.ButtonBase.OnClick():19
    System.Windows.Controls.Button.OnClick():26
    System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e):68
    System.Windows.UIElement.OnMouseLeftButtonUpThunk(Object sender, MouseButtonEventArgs e):29
    System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget):0
    System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target):7
    System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs):48
    System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised):230
    System.Windows.UIElement.ReRaiseEventAs(DependencyObject sender, RoutedEventArgs args, RoutedEvent newEvent):101
    System.Windows.UIElement.OnMouseUpThunk(Object sender, MouseButtonEventArgs e):58
    System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget):0
    System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target):7
    System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs):48
    System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised):230
    System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args):87
    System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args):20
    System.Windows.Input.InputManager.ProcessStagingArea():479
    System.Windows.Input.InputManager.ProcessInput(InputEventArgs input):36
    System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport):53
    System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel):524
    System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, WindowMessage msg, IntPtr wParam, IntPtr lParam, Boolean& handled):1378
    System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled):74
    MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled):8
    MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o):54
    System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs):119
    System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler):2

Potential fix

gbiellem commented 8 years ago

So I've made SC management work but this still begs the question why do so many users have invalid license files or reg entries for the license? Something seems off here,

johnsimons commented 8 years ago

Time to talk to users :scream:

gbiellem commented 8 years ago

@danielmarbach I assume this came from a desk case. Can you ask how they added their old license?

danielmarbach commented 8 years ago

@gbiellem They where using latest license format. We even generated a new file but it still failed. Can we offer a workaround somehow?

danielmarbach commented 8 years ago

@Particular/servicecontrol-maintainers thoughts?

gbiellem commented 8 years ago

@danielmarbach

The workaround would be to import the license as covered in the docs here - http://docs.particular.net/nservicebus/licensing/license-management.

The fix to the SC management tool will ship in 1.8.4 which should go out tomorrow.

But the bug highlights a problem The fault only occurs if the tool tries to read an already installed license that does not parse correctly. So my concern is that we have fixed the tool but masked a problem with the way licenses are applied. That's why I wanted to know about how they applied the previous license.

gbiellem commented 8 years ago

Make that 1.9 not 1.8.4 - we've updated depedencies to address the TTBR https://github.com/Particular/ServiceControl/issues/624