Search code examples
c#wpfwinformsspreadsheetgear

SpreadsheetGear.Windows.Wpf Crashes when an invalid Workbook Name is used in a formula to reference a different Workbook in the WorkbookSet


When an invalid Workbook Name is used in a formula for referencing a different workbook in a WorkbookSet, the "Invalid Formula" message that shows up on WinForms, does not show up on the WPF version and instead just crashes the whole program with the following exception:

System.Windows.Markup.XamlParseException: 'Set property 'System.Windows.FrameworkElement.Name' threw an exception.'

Inner Exception
ArgumentException: '꒾' is not a valid value for property 'Name'.

This exception was originally thrown at this call stack:
    System.Windows.DependencyObject.SetValueCommon(System.Windows.DependencyProperty, object, System.Windows.PropertyMetadata, bool, bool, System.Windows.OperationType, bool)
    System.Windows.DependencyObject.SetValue(System.Windows.DependencyProperty, object)
    System.Windows.Baml2006.WpfKnownMemberInvoker.SetValue(object, object)
    MS.Internal.Xaml.Runtime.ClrObjectRuntime.SetValue(System.Xaml.XamlMember, object, object)
    MS.Internal.Xaml.Runtime.ClrObjectRuntime.SetValue(object, System.Xaml.XamlMember, object)

To reproduce it, use the official SpreadsheetGear sample Repo from GitHub: https://github.com/SpreadsheetGear/SpreadsheetGearExplorerSamples
In any of the examples, just set any cell to a be a reference to a sheet+cell that doesn't exist =Death!A1.

I'm using VS2022 with "Just My Code" debugging disabled, I end up in some obfuscated file but I can see that it crashes on the last line of this function here.

[GeneratedCode("PresentationBuildTasks", "8.0.6.0")]
[DebuggerNonUserCode]
public void InitializeComponent()
{
    if (!_꤆)
    {
        _꤆ = true;
        Uri resourceLocator = new Uri("/SpreadsheetGear.Windows.Wpf;component/sg.windows.xaml/messagedialog.xaml", UriKind.Relative);
        Application.LoadComponent(this, resourceLocator);
    }
}

I assume that this is a problem with SpreadsheetGear, but it could just be that I am missing some sort of check that I have to setup on my side to validate that a formula will evaluate correctly before some other calculate event happens?

Any help is appreciated because I am currently migrating our WinForms app to WPF and this road block is very important to figure out since we will have customers interfacing with the sheets regularly and if they make a typo, it is unacceptable to hard crash.


Solution

  • This issue was due to obfuscation software used by SpreadsheetGear, which was obfuscating certain properties using characters that didn't work well with XAML.

    Version 9.3.3 was just released, which addresses this. You should see this new version when checking NuGet for updates for the SpreadsheetGear.Windows package (the "SpreadsheetGear for Windows" product). Thank you for bringing this to our attention!