The code from MainWindowController
...
```
public override void AwakeFromNib()
{
base.AwakeFromNib();
NSButton aButton = new NSButton(new CoreGraphics.CGRect(20, 20, 100, 100));
aButton.Activated += AButton_Activated;
aButton.Title = "Press Me";
this.Window.ContentView.AddSubview(aButton);
}
void AButton_Activated(object sender, EventArgs e)
{
NSAlert alert = new NSAlert();
alert.AddButton("OK");
alert.MessageText = "Message";
alert.InformativeText = "Informative";
alert.RunModal();
}
..
### Expected Behaviour
NSAlert Should Appear showing Text and Button
<img width="761" alt="screenshot 2018-09-20 at 10 53 31" src="https://user-images.githubusercontent.com/12064448/45809693-1fa2a000-bcc9-11e8-8749-2726c9514224.png">
### Actual Behavior
NSAlert Frame only appears but the content is blank. Please note this is inconsistent as if you close the alert with escape or enter and press the button again it will show
<img width="1158" alt="screenshot 2018-09-20 at 10 53 10" src="https://user-images.githubusercontent.com/12064448/45809686-1addec00-bcc9-11e8-91f0-31f846819a39.png">
### Environment
<!--
1.
Visual Studio: Help > About Microsoft Visual Studio > Copy Info [button]
Visual Studio for Mac: Visual Studio > About Visual Studio > Show Details > Copy Information [button]
2. Paste into the code block below (between ```)
-->
=== Visual Studio Community 2017 for Mac ===
Version 7.6.6 (build 17)
Installation UUID: 3f2abab7-67ae-4505-b2bf-7d93f8fd8513
Runtime:
Mono 5.12.0.301 (2018-02/4fe3280bba1) (64-bit)
GTK+ 2.24.23 (Raleigh theme)
Xamarin.Mac 4.4.1.178 (master / eeaeb7e6)
Package version: 512000301
=== NuGet ===
Version: 4.3.1.4445
=== .NET Core ===
Runtime: /usr/local/share/dotnet/dotnet
Runtime Versions:
2.1.2
2.1.1
2.0.5
SDK: /usr/local/share/dotnet/sdk/2.1.302/Sdks
SDK Versions:
2.1.302
2.1.301
2.1.4
MSBuild SDKs: /Library/Frameworks/Mono.framework/Versions/5.12.0/lib/mono/msbuild/15.0/bin/Sdks
=== Xamarin.Profiler ===
Version: 1.6.3
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler
=== Xamarin.Android ===
Not Installed
=== Apple Developer Tools ===
Xcode 10.0 (14320.24)
Build 10A254a
=== Xamarin.Mac ===
Version: 4.6.0.14 (Visual Studio Community)
Hash: 1a6e2786
Branch:
Build date: 2018-08-28 00:12:06-0400
=== Xamarin.iOS ===
Version: 12.0.0.15 (Visual Studio Community)
Hash: 84552a46
Branch: xcode10
Build date: 2018-09-17 21:54:33-0400
=== Xamarin Inspector ===
Version: 1.4.3
Hash: db27525
Branch: 1.4-release
Build date: Mon, 09 Jul 2018 21:20:18 GMT
Client compatibility: 1
=== Build Information ===
Release ID: 706060017
Git revision: 822323b5f6295b271d4c9bfaca4129f90ec41f38
Build date: 2018-09-18 20:19:40+00
Build branch: release-7.6-xcode10
Xamarin extensions: a83eb4b7ad9174ac2e705f2c4257ecd15688ba97
=== Operating System ===
Mac OS X 10.14.0
Darwin 18.0.0 Darwin Kernel Version 18.0.0
Wed Aug 22 20:13:40 PDT 2018
root:xnu-4903.201.2~1/RELEASE_X86_64 x86_64
=== Enabled user installed extensions ===
Internet of Things (IoT) development (Preview) 7.5.3
```
Also tested against Xcode 10 Preview Channel Which has the version Xamarin.Mac 4.99.3.741 which also showed the NSAlertView with empty frame
This might be related to #4509.
Created Swift Clone to ensure it was not Apple Problem. The swift version appears to work fine.
I have this problem with my Xamarin.mac app.
Only on mojave, never had it on macos sierra or high sierra.
It's the same with Xcode 10 Preview, the problem is there !
Important note :
I have the same phenome with some view with PresentViewController. they appear empty then sometimes, they are normal, ...
I have noticed this with anything modal, Presenting Windows Modally, Presenting Windows as Sheets Modally. My hunch is the more complex the Modal the more likely it is to be displayed. As the worst offender is the sample test I have produced.
Glad you saw the problem because I do not understand anything.
I have really weird problems since Mojave
Following @chamons on the thread on #4509
I just tried add the following
NSAlert alert = new NSAlert();
alert.AddButton("OK");
alert.MessageText = "Message";
alert.InformativeText = "Informative";
alert.Window.ContentView.WantsLayer = true;
alert.Window.ContentView.Layer.BackgroundColor = NSColor.Yellow.CGColor;
alert.Window.ContentView.UpdateLayer();
alert.RunModal();
Unfortunately I don't seem any improvement
I test the problems that I encounter and do, I realize that the problems come from the modal box problem.
Example:
I display an image and then hide this image and then I display an alertview.
If I do that, the image is not hiding. She remains visible while I told her before being hidden.
If I do not put the alertview, I do not have the problem. The image is well hidden.
Ps also tried Window.ContentView.Superview.WantsLayer = true; with no such luck either
I tried this and my viewcontroller already has the layer checked in the Xib file.
I also put the line of code to try but it does not change anything.
Looks like there is something blocking after the display of the alertview and nothing else happens properly
Does anyone take care of this problem ?
Using the fix suggested by @lemonmojo in #4509 of calling NSApplicationLoad appears to fix my issues. I cannot find much documentation on this, Xamarin and @chamons do you recommend this ?
@Rogister Perhaps you could try it out too ?
@Lemonmojo Thanks for your hardwork finding this.
`
[DllImport("/System/Library/Frameworks/Cocoa.framework/Cocoa", EntryPoint = "NSApplicationLoad")]
private static extern bool NSApplicationLoad();
static void Main(string[] args)
{
NSApplicationLoad();
NSApplication.Init();
NSApplication.Main(args);
}
`
Happy Mojave Day!
@lilleydnSub I found some info and posted it in https://github.com/xamarin/xamarin-macios/issues/4509#issuecomment-423727747.
Hi,
I want to try this solution but when I put in my application, it highlights me DllImport, what should I do:
[DllImport ("/ System / Library / Frameworks / Cocoa.framework / Cocoa", EntryPoint = "NSApplicationLoad")]
聽聽聽聽聽聽聽聽 private static extern bool NSApplicationLoad ();
Alain
@Rogister You'll need to import System.Runtime.InteropServices. Add using System.Runtime.InteropServices; to your Program.cs or Main.cs file.
OK, thanks.
I just tried and it solves all the problems I had. (AlertView, Modal dialog and tableview)
Is there an explanation ?
Alain
@Rogister Well, from the info I was able to find I assume that macOS Mojave thinks that mono apps are not properly configured Cocoa apps and NSApplicationLoad fixes that. I don't know exactly what triggers this but as mentioned in the other thread, just calling mono_jit_init introduces the problem so the source of the issue must be somewhere in that method.
Chris would have to look at the problem because it's not very normal that we have to specify that.
Are you going to tell me, as long as it works ?
198/5000
I notice a last problem on Mojave with the toolbar.
I have buttons (image) that is no longer displayed correctly and I have the impression that the function SetTouchBar (null) no longer works.
The SetTouchBar (null) works fine!
But there is a problem. I display several buttons and now there is only
the first 5 that appears by putting me a big space between some buttons
The cousin bug to this (#4509) appears fixed _for me_ on stable 10.14, please update, retest, and report back.
I try today without putting the lines of code that solves the problem and I still have the problem with MacOS Mojave Final
The problem is not solved without putting
聽 [DllImport ("/ System / Library / Frameworks / Cocoa.framework / Cocoa", EntryPoint = "NSApplicationLoad")]
聽聽聽聽聽聽聽聽 private static extern bool NSApplicationLoad ();
聽聽聽聽聽聽聽聽 static void Main (string [] args)
{
聽聽聽聽聽聽聽聽聽聽聽聽 NSApplicationLoad ();
聽 NSApplication.Init ();
NSApplication.Main (args);
聽聽聽聽聽聽聽聽 }
I'm having this problem too. Tried the proposed workaround (calling NSApplicationLoad) but it didn't work either. Using Xamarin.Mac on https://github.com/DanWBR/dwsim5 through https://github.com/picoe/Eto
I believe this has the same root cause as:
radar://44763485 & mono/mono#10802
The mono team is investigating it now. The following things make the issue go away for _me_ at least:
And as a side note, NSApplicationLoad was a work around suggested by another user, not a solution at all.
I'm having a new issue too, sometimes the controls inside a view vanish all of a sudden. I didn't have this issue before upgrading to Mojave (specifically, it was bug-free with High Sierra + XCode 10). Maybe it is related to the bug being discussed.
There are a number of drawing corruptions various people are seeing after the mprotect call in mono startup, from the title bar disappearing, to strange resize behavior, to modal dialogs and controls not drawing.
I believe they all have the same root cause, and you can try the temporary work arounds I suggested to see if they hide it for now (reverting to xcode94 is likely the easiest) A fix is in research.
@chamons sure, I understand. I'm just trying to help by adding as much as info as possible.
@chamons Just wanted to note that in my testing just using a storyboard for the main menu and app delegate isn't enough to work around the issue. You'll also need to have your main window in the storyboard as well as the entry point of the app set to that window.
Ok, the gears may feel like they are slowly turning on getting this fix out on an official channel, but considering the fact that the fix only landed _4 days ago_ things are moving along faster than it appears.
~This is a "from the developer's machine" build for people to try:~
~https://xamarin.azureedge.net/uploads/y50ozav12uz/xamarin.mac-5.2.0.2-10.14.fix.pkg~
~If you aren't comfortable with that, and can wait half a day - I'll post an official build machine package later, but I wanted to get something out as soon as I could.~
Here is an official build: https://bosstoragemirror.blob.core.windows.net/wrench/jenkins/d15-9/2d1d118302f3c131a6fc91eca113877a6ae1111c/38/package/xamarin.mac-5.2.1.4.pkg
Please test it (or the later package) and report back
@chamons tested it here and all issues seem to be gone. Thank you all very much!
This fixes the issue for me too. I work on two Xamarin.Mac applications, one of which was fixed by NSApplicationLoad and one wasn't. Messing around with WantsLayer didn't help that one either. But with this new build of Xamarin.Mac all appears well. Thanks @chamons
@chamons
I installed the fix and everything seems to work properly. Thank you very much
I note that sometimes I still have empty boxes. It's almost impossible to reproduce. Sometimes (extremely rarely, the box is empty and if I do it again soon after, no problem).
I'm happy to say that the build I posted a week ago appears to work for everyone so far, so I'm going to close this issue as fixed (in the next major version). It will come out in a future d15-9 release, but until then you can use the posted build from that branch.
If you run into additional issues _not_ fixed by this, please open a new issue.
@chamons - When is the release likely to be?
Unfortunately, I don't have any official dates I can point to.
This document describes the Visual Studio release cycle - https://docs.microsoft.com/en-us/visualstudio/productinfo/vs2017-release-rhythm
We also have older d15-9 builds in the Alpha and Beta channel currently.
Ok, thanks.
Just wanted to check as, when the patch is applied, I'm no longer able to build my app from the command line. Discovered this when I tried to build a beta of our app.
Incase it helps I'm running from within a build script:
/Library/Frameworks/Mono.framework/Versions/Current/Commands/msbuild <ProjectName>.sln /target:Build /p:SolutionDir=. /p:Configuration=AppStore "/p:Platform=Any CPU" /p:ArchiveOnBuild=true
And fails with the following error:
"/Users/ewan/Documents/<ProjectName>/<ProjectName>.sln" (Build target) (1) ->
"/Users/ewan/Documents/<ProjectName>/<ProjectName>/<ProjectName>.csproj" (default target) (2) ->
(_CopyContentToBundle target) ->
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Mac/Xamarin.Mac.Common.targets(265,3): error : System.IO.FileNotFoundException: /Users/ewan/Documents/<ProjectName>/<ProjectName>/obj/AppStore/actool/bundle/AppIcons.icns does not exist [/Users/ewan/Documents/<ProjectName>/<ProjectName>/<ProjectName>.csproj]
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Mac/Xamarin.Mac.Common.targets(265,3): error : File name: '/Users/ewan/Documents/<ProjectName>/<ProjectName>/obj/AppStore/actool/bundle/AppIcons.icns' [/Users/ewan/Documents/<ProjectName>/<ProjectName>/<ProjectName>.csproj]
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Mac/Xamarin.Mac.Common.targets(265,3): error : at System.IO.File.Copy (System.String sourceFileName, System.String destFileName, System.Boolean overwrite) [0x000b6] in <71f4e3d7d65e42b0a699d02e59766d3c>:0 [/Users/ewan/Documents/<ProjectName>/<ProjectName>/<ProjectName>.csproj]
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Mac/Xamarin.Mac.Common.targets(265,3): error : at Xamarin.MacDev.Tasks.SmartCopyTaskBase.CopyFile (System.String source, System.String target, System.String targetItemSpec) [0x00030] in <b8439c57492548a58e72cdd146a1847a>:0 [/Users/ewan/Documents/<ProjectName>/<ProjectName>/<ProjectName>.csproj]
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Mac/Xamarin.Mac.Common.targets(265,3): error : at Xamarin.MacDev.Tasks.SmartCopyTaskBase.Execute () [0x000e7] in <b8439c57492548a58e72cdd146a1847a>:0 [/Users/ewan/Documents/<ProjectName>/<ProjectName>/<ProjectName>.csproj]
The build works fine from Visual Studio Mac in the same configuration. It also worked in previous versions of Xamarin.Mac.
Should I raise a new issue with this?
Please file that as a new issue, with a way for us to reproduce it.
Am I correct in believing that it still not fixed in Alpha and Beta channels ?
Any closer to being released ?
That is correct 馃槮 It is queued up for release.
The latest d15-9 builds, which are publicly available, have the fix.
I can not comment on when it will go out currently, but yes closer...
@chamons:
The latest d15-9 builds, which are publicly available, have the fix.
Does this mean the 15-9 builds now available via ALPHA/BETA channels or are these found elsewhere?
No, there is a separation. Let me explain:
The fix is in d15-9, and the bits are available (The package I linked earlier was from here). Assuming no additional changes are needed, we'll be pushing those bits out at some point in the future when QA and release processing is complete. Until then, you can obtain them "early" as I noted.
See: https://github.com/xamarin/xamarin-macios/issues/4848#issuecomment-427405971
These builds are now in Beta channel (not Alpha, looking into that now).
Most helpful comment
Ok, the gears may feel like they are slowly turning on getting this fix out on an official channel, but considering the fact that the fix only landed _4 days ago_ things are moving along faster than it appears.
~This is a "from the developer's machine" build for people to try:~
~https://xamarin.azureedge.net/uploads/y50ozav12uz/xamarin.mac-5.2.0.2-10.14.fix.pkg~
~If you aren't comfortable with that, and can wait half a day - I'll post an official build machine package later, but I wanted to get something out as soon as I could.~
Here is an official build: https://bosstoragemirror.blob.core.windows.net/wrench/jenkins/d15-9/2d1d118302f3c131a6fc91eca113877a6ae1111c/38/package/xamarin.mac-5.2.1.4.pkg
Please test it (or the later package) and report back