locked
Works in DEBUG; System.NotSupportedException in RELEASE RRS feed

  • Question

  • User18245 posted

    Visual Studio Preview 9 (7.0 build 2943) Xcode 8.3.2 (8E2002)

    I have a set of generic classes which encapsulate a bunch of NSTable code

    For example, there's a NSGeneralSingleSelectionTableView which displays a collection of T and allows the selection of a single item, for which there's

    public event EventHandler SelectionChanged;

    The code NSGeneralSingleSelectionTableView is pretty simple (the entire thing appears below).

    In debug mode, this works exactly as I expect.

    When I built in release mode, though, I get a System.NotSupportedException on the line this.DataSource = _dataSource; (exception output also included below)

    Suggestions?

        public class NSGeneralSingleSelectionTableView<T> : NSTableView where T : class
        {
            private readonly NSGeneralTableSpecification<T> TableSpecification;
    
            private IReadOnlyList<T> _dataset;
            private NSGeneralTableDataSource<T> _dataSource;
            private NSGeneralTableDelegate<T> _tableDelegate;
    
            public NSGeneralSingleSelectionTableView(NSGeneralTableSpecification<T> tableSpec)
            {
                this.TableSpecification = tableSpec;
    
                foreach (NSTableColumn column in this.TableSpecification.ColumnSpecifications) {
                    this.AddColumn(column);
                }
    
                _dataset = null;
                _dataSource = new NSGeneralTableDataSource<T>();
                _tableDelegate = new NSGeneralTableDelegate<T>(this.TableSpecification.SetCellContent);
    
                this.DataSource = _dataSource;
                this.Delegate = _tableDelegate;
                this.SelectionHighlightStyle = NSTableViewSelectionHighlightStyle.None;
                this.AllowsColumnResizing = true;
                this.AllowsColumnSelection = false;
                this.AllowsMultipleSelection = false;
    
                this.DoubleClick += (sender, e) => {
                    this.DoubleClicked?.Invoke(this, this.CurrentSelection);
                };
                _tableDelegate.SelectionChanged += (sender, e) => {
                    this.SelectionChanged?.Invoke(this, this.CurrentSelection);
                };
            }
    
            public event EventHandler<T> DoubleClicked;
            public event EventHandler<T> SelectionChanged;
    
            private T CurrentSelection
            {
                get { return (_dataset == null ? null : _dataset[(int)(this.SelectedRow)]); }
            }
    
            public void SetDataset(IReadOnlyList<T> dataset)
            {
                _dataset = dataset;
                _dataSource.SetDataset(_dataset);
                _tableDelegate.SetDataset(_dataset);
                this.ReloadData();
            }
    
            private class DataSourceClass : NSGeneralTableDataSource<T> { }
        }
    

    And the exception thrown:

    Unhandled Exception:
    System.NotSupportedException: Specified method is not supported.
      at ObjCRuntime.Runtime.get_generic_method_from_token (System.IntPtr obj, System.UInt32 token_ref, System.Int32& exception_gchandle) [0x00005] in <223ccc77178f474cb3428fd6ae894e8b>:0 
    --- End of stack trace from previous location where exception was thrown ---
      at (wrapper managed-to-native) ObjCRuntime.Messaging:void_objc_msgSendSuper_IntPtr (intptr,intptr,intptr)
      at AppKit.NSTableView.set_WeakDataSource (Foundation.NSObject value) [0x0005c] in <223ccc77178f474cb3428fd6ae894e8b>:0 
      at AppKit.NSTableView.set_DataSource (AppKit.INSTableViewDataSource value) [0x0002f] in <223ccc77178f474cb3428fd6ae894e8b>:0 
      at TBS.MacOSKit.NSGeneralSingleSelectionTableView`1[T]..ctor (TBS.MacOSKit.NSGeneralTableSpecification`1[T] tableSpec) [0x0005a] in <092d2c96c98743ad886f86b7e91d0f00>:0 
      at TBS.MacViewOutstanding.PlayerListWindowView.InstantiateSubviews () [0x00007] in <092d2c96c98743ad886f86b7e91d0f00>:0 
      at TBS.MacViewOutstanding.PlayerListWindowView.InitializeLayout () [0x00000] in <092d2c96c98743ad886f86b7e91d0f00>:0 
      at TBS.MacViewOutstanding.PlayerListWindowView..ctor (CoreGraphics.CGRect frame) [0x0000d] in <092d2c96c98743ad886f86b7e91d0f00>:0 
      at TBS.MacViewOutstanding.PlayerListWindowController..ctor (ReportBuilderDataManager dataManager) [0x0005b] in <092d2c96c98743ad886f86b7e91d0f00>:0 
      at TBS.MacViewOutstanding.AppDelegate.DidFinishLaunching (Foundation.NSNotification notification) [0x00074] in <092d2c96c98743ad886f86b7e91d0f00>:0 
      at (wrapper managed-to-native) AppKit.NSApplication:NSApplicationMain (int,string[])
      at AppKit.NSApplication.Main (System.String[] args) [0x0003d] in <223ccc77178f474cb3428fd6ae894e8b>:0 
      at TBS.MacViewOutstanding.MainClass.Main (System.String[] args) [0x0000a] in <092d2c96c98743ad886f86b7e91d0f00>:0 
    
    Friday, April 28, 2017 6:54 PM

Answers

  • User35201 posted

    Try adding --registar:dynamic to your additional mmp arguments in Project Options -> Mac Build -> Additional MMP Arguments.

    If that fixes it please file a bug here with a sample showing it: https://bugzilla.xamarin.com/index.cgi

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Monday, May 1, 2017 2:03 PM

All replies

  • User35201 posted

    Try adding --registar:dynamic to your additional mmp arguments in Project Options -> Mac Build -> Additional MMP Arguments.

    If that fixes it please file a bug here with a sample showing it: https://bugzilla.xamarin.com/index.cgi

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Monday, May 1, 2017 2:03 PM
  • User18245 posted

    Chris - After adding the mmp argument it started working; thanks. I'll file a bug...

    Note to anyone who follows in these footsteps: There is a small typo, it's "--registrar:dynamic"

    Monday, May 1, 2017 2:25 PM
  • User35201 posted

    That's what happens when I try to do work before my first cup of coffee is gone...

    Monday, May 1, 2017 2:26 PM