Bug 55857 - Code that works in DEBUG; System.NotSupportedException in RELEASE
Summary: Code that works in DEBUG; System.NotSupportedException in RELEASE
Alias: None
Product: Xamarin.Mac
Classification: Desktop
Component: mmp ()
Version: 3.4.0 (15.2)
Hardware: Macintosh Mac OS
: Normal normal
Target Milestone: 15.3
Assignee: Rolf Bjarne Kvinge [MSFT]
Depends on:
Reported: 2017-05-01 14:36 UTC by Gilles Dignard
Modified: 2017-05-10 08:10 UTC (History)
6 users (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Gilles Dignard 2017-05-01 14:36:04 UTC
Posted this to the Xamarin forums; Chris asked that I post the issue here

Problem is code involving a Generic class which works fine in DEBUG but where it throws a System.NotSupportedException when run in RELEASE.

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

            _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;

        private class DataSourceClass : NSGeneralTableDataSource<T> { }

The failure happens on the line 

 _dataSource = new NSGeneralTableDataSource<T>();

The stack trace given is

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&amp; exception_gchandle) [0x00005] in &lt;223ccc77178f474cb3428fd6ae894e8b&gt;: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 &lt;223ccc77178f474cb3428fd6ae894e8b&gt;:0 
  at AppKit.NSTableView.set_DataSource (AppKit.INSTableViewDataSource value) [0x0002f] in &lt;223ccc77178f474cb3428fd6ae894e8b&gt;:0 
  at TBS.MacOSKit.NSGeneralSingleSelectionTableView`1[T]..ctor (TBS.MacOSKit.NSGeneralTableSpecification`1[T] tableSpec) [0x0005a] in &lt;092d2c96c98743ad886f86b7e91d0f00&gt;:0 
  at TBS.MacViewOutstanding.PlayerListWindowView.InstantiateSubviews () [0x00007] in &lt;092d2c96c98743ad886f86b7e91d0f00&gt;:0 
  at TBS.MacViewOutstanding.PlayerListWindowView.InitializeLayout () [0x00000] in &lt;092d2c96c98743ad886f86b7e91d0f00&gt;:0 
  at TBS.MacViewOutstanding.PlayerListWindowView..ctor (CoreGraphics.CGRect frame) [0x0000d] in &lt;092d2c96c98743ad886f86b7e91d0f00&gt;:0 
  at TBS.MacViewOutstanding.PlayerListWindowController..ctor (ReportBuilderDataManager dataManager) [0x0005b] in &lt;092d2c96c98743ad886f86b7e91d0f00&gt;:0 
  at TBS.MacViewOutstanding.AppDelegate.DidFinishLaunching (Foundation.NSNotification notification) [0x00074] in &lt;092d2c96c98743ad886f86b7e91d0f00&gt;:0 
  at (wrapper managed-to-native) AppKit.NSApplication:NSApplicationMain (int,string[])
  at AppKit.NSApplication.Main (System.String[] args) [0x0003d] in &lt;223ccc77178f474cb3428fd6ae894e8b&gt;:0 
  at TBS.MacViewOutstanding.MainClass.Main (System.String[] args) [0x0000a] in &lt;092d2c96c98743ad886f86b7e91d0f00&gt;:0
Comment 1 Chris Hamons 2017-05-03 16:24:37 UTC
This is the forum thread in question: https://forums.xamarin.com/discussion/94357/works-in-debug-system-notsupportedexception-in-release#latest

This is related to the registrar default changes made in 3.2:


Adding  "--registrar:dynamic" to the release configuration "fixed" things.
Comment 2 Chris Hamons 2017-05-03 16:25:08 UTC
Thanks for the report!
Comment 3 Rolf Bjarne Kvinge [MSFT] 2017-05-04 04:27:44 UTC
This explains it: https://github.com/xamarin/xamarin-macios/blob/834d169/src/ObjCRuntime/Runtime.cs#L579
Comment 4 Rolf Bjarne Kvinge [MSFT] 2017-05-09 13:34:56 UTC
master: https://github.com/xamarin/xamarin-macios/pull/2076
Comment 5 Rolf Bjarne Kvinge [MSFT] 2017-05-10 08:10:28 UTC
fixed (master): https://github.com/xamarin/xamarin-macios/commit/469133a8fd414958959f29bf25be0c5418d3fbc5