Bug 55693 - AppKit.NSLayoutAnchor missing in release build
Summary: AppKit.NSLayoutAnchor missing in release build
Status: VERIFIED FIXED
Alias: None
Product: Xamarin.Mac
Classification: Desktop
Component: mmp ()
Version: 3.4.0 (15.2)
Hardware: Macintosh Mac OS
: High normal
Target Milestone: 15.3
Assignee: Sebastien Pouliot
URL:
Depends on:
Blocks:
 
Reported: 2017-04-27 15:59 UTC by Bernhard Straub
Modified: 2017-06-28 06:59 UTC (History)
4 users (show)

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


Attachments
VSfM Logs (23.58 KB, application/zip)
2017-05-31 10:23 UTC, Neha Kharbade
Details


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:
Status:
VERIFIED FIXED

Description Bernhard Straub 2017-04-27 15:59:19 UTC
Adding a simple layout constraint is working for debug builds but not for release builds.

public override void ViewDidLoad()
{
   base.ViewDidLoad();
   var textView = new NSTextView();
   View.AddSubview(textView);

  textView.TranslatesAutoresizingMaskIntoConstraints = false;

  textView.HeightAnchor.ConstraintEqualToAnchor(View.HeightAnchor).Active = true;
  textView.WidthAnchor.ConstraintEqualToAnchor(View.WidthAnchor).Active = true;
}

debug build OK
release build => System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.TypeInitializationException: The type initializer for 'AppKit.NSLayoutAnchor`1' threw an exception. ---> System.MissingFieldException: Field 'AppKit.NSLayoutAnchor`1<AnchorType_REF>.selConstraintEqualToAnchor_Handle' not found.


Stack Trace:

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.TypeInitializationException: The type initializer for 'AppKit.NSLayoutAnchor`1' threw an exception. ---> System.MissingFieldException: Field 'AppKit.NSLayoutAnchor`1<AnchorType_REF>.selConstraintEqualToAnchor_Handle' not found.
  --- End of inner exception stack trace ---
  at AppKit.NSLayoutDimension..ctor (System.IntPtr handle) [0x00000] in /Users/builder/data/lanes/4691/675645b0/source/xamarin-macios/src/build/mac/mobile/AppKit/NSLayoutDimension.g.cs:93
  at at (wrapper managed-to-native) System.Reflection.MonoCMethod:InternalInvoke (System.Reflection.MonoCMethod,object,object[],System.Exception&)
  at System.Reflection.MonoCMethod.InternalInvoke (System.Object obj, System.Object[] parameters) [0x00002] in /Library/Frameworks/Xamarin.Mac.framework/Versions/3.4.0.21/src/mono/mcs/class/corlib/System.Reflection/MonoMethod.cs:661
  --- End of inner exception stack trace ---
  at System.Reflection.MonoCMethod.InternalInvoke (System.Object obj, System.Object[] parameters) [0x00012] in /Library/Frameworks/Xamarin.Mac.framework/Versions/3.4.0.21/src/mono/mcs/class/corlib/System.Reflection/MonoMethod.cs:667
  at System.Reflection.MonoCMethod.DoInvoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x0007a] in /Library/Frameworks/Xamarin.Mac.framework/Versions/3.4.0.21/src/mono/mcs/class/corlib/System.Reflection/MonoMethod.cs:652
  at System.Reflection.MonoCMethod.Invoke (System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in /Library/Frameworks/Xamarin.Mac.framework/Versions/3.4.0.21/src/mono/mcs/class/corlib/System.Reflection/MonoMethod.cs:680
  at System.Reflection.ConstructorInfo.Invoke (System.Object[] parameters) [0x00000] in /Library/Frameworks/Xamarin.Mac.framework/Versions/3.4.0.21/src/mono/mcs/class/corlib/System.Reflection/ConstructorInfo.cs:62
  at ObjCRuntime.Runtime.ConstructNSObject[T] (System.IntPtr ptr, System.Type type, ObjCRuntime.Runtime+MissingCtorResolution missingCtorResolution) [0x00055] in /Users/builder/data/lanes/4691/675645b0/source/xamarin-macios/src/ObjCRuntime/Runtime.cs:951
  at ObjCRuntime.Runtime.GetNSObject[T] (System.IntPtr ptr) [0x000fe] in /Users/builder/data/lanes/4691/675645b0/source/xamarin-macios/src/ObjCRuntime/Runtime.cs:1078
  at AppKit.NSView.get_HeightAnchor () [0x00022] in /Users/builder/data/lanes/4691/675645b0/source/xamarin-macios/src/build/mac/mobile/AppKit/NSView.g.cs:9476
  at LayoutTest.ViewController.ViewDidLoad () [0x00023] in /Users/berni/Projects/LayoutTest/LayoutTest/ViewController.cs:22
  at at (wrapper managed-to-native) AppKit.NSApplication:NSApplicationMain (int,string[])
  at AppKit.NSApplication.Main (System.String[] args) [0x00041] in /Users/builder/data/lanes/4691/675645b0/source/xamarin-macios/src/AppKit/NSApplication.cs:99
  at LayoutTest.MainClass.Main (System.String[] args) [0x00007] in /Users/berni/Projects/LayoutTest/LayoutTest/Main.cs:10
Comment 1 Chris Hamons 2017-04-27 16:04:30 UTC
Do you have linking enabled? Could you provide a sample showing this issue?

The two major things enabled in Release configuration is linking and static registrar (--registrar:dynamic in mmp args to flip that off).

AppKit.NSLayoutAnchor`1' threw an exception. ---> System.MissingFieldException: Field 'AppKit.NSLayoutAnchor`1<AnchorType_REF>.selConstraintEqualToAnchor_Handle' not found.
Comment 2 Bernhard Straub 2017-04-27 17:57:39 UTC
Switching off linkage will solve the issue (defaults to "Link Frameworks SDKs only").

Can you reproduce by just creating a simple project and pasting the ViewDidLoad code from above.

Visual Studio for Mac lastest update...

Visual Studio for Mac Preview
Version Preview 9 (7.0 build 2943)
Mono 5.0.0.78 (2017-02/ba317ed) (64-bit)
GTK+ 2.24.23 (Raleigh theme)
Xamarin.Mac
Version: 3.4.0.21 (Visual Studio Enterprise)

New Mac App + ViewDidLoad code from above.
Comment 3 Chris Hamons 2017-04-27 18:13:49 UTC
My bad. I misread the bug report and did not see that.

With that I completely reproduce your issue.
Comment 4 Chris Hamons 2017-04-28 21:13:14 UTC
I did some poking around and it appears to be RemoveSelectors that's breaking things.

XI does not do that step, and equivalent code works there.

I was hoping to generate a linker XML script to work around this, but for technical reasons it won't be that easy.

You could enable SDK linking and add --linkskip=Xamarin.Mac to your mmp arguments to just skip Xamarin.Mac.
Comment 5 Sebastien Pouliot 2017-05-18 01:14:15 UTC
PR https://github.com/xamarin/xamarin-macios/pull/2104
Comment 7 Neha Kharbade 2017-05-31 10:20:24 UTC
Verified this bug with following steps:

1. Created Mac app project.
2. Add following code as:


public override void ViewDidLoad()
{
   base.ViewDidLoad();
   var textView = new NSTextView();
   View.AddSubview(textView);

  textView.TranslatesAutoresizingMaskIntoConstraints = false;

  textView.HeightAnchor.ConstraintEqualToAnchor(View.HeightAnchor).Active = true;
  textView.WidthAnchor.ConstraintEqualToAnchor(View.WidthAnchor).Active = true;
}


3. Build project in release mode & deployed.
     Its was build & deployed successfully.


Screencast version:
http://www.screencast.com/t/Z7UY6sXZD
Gist version:
https://gist.github.com/nehaKh/e9e5909e376e055e220e8d9055b6f85a


As steps were not given please correct my understanding if its wrong. Provide me steps for any other scenario need to verified.

Also kindly confirm if above build & steps were correct, shall we mark this bug as verified.
Comment 8 Neha Kharbade 2017-05-31 10:23:00 UTC
Created attachment 22581 [details]
VSfM Logs