Bug 23868 - Incorrect values in UIScreen.MainScreen.Bounds
Summary: Incorrect values in UIScreen.MainScreen.Bounds
Status: VERIFIED FIXED
Alias: None
Product: Visual Studio Extensions
Classification: Xamarin
Component: iOS ()
Version: 3.6
Hardware: PC Windows
: High major
Target Milestone: 3.8
Assignee: Adrian Alonso
URL:
: 23499 24151 ()
Depends on:
Blocks:
 
Reported: 2014-10-16 01:55 UTC by shtyle@rambler.ru
Modified: 2015-05-22 05:58 UTC (History)
21 users (show)

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


Attachments
Blank App project (4.43 KB, application/x-zip-compressed)
2014-10-16 01:56 UTC, shtyle@rambler.ru
Details
Patched targets file for workaround (35.62 KB, application/octet-stream)
2014-11-01 00:58 UTC, Brendan Zagaeski (Xamarin Team, assistant)
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 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 shtyle@rambler.ru 2014-10-16 01:55:43 UTC
Issue:
  UIScreen.MainScreen.Bounds contains strange values when blank application debugged using Visual Studio iOS Add-in:

in AppDelegate.cs:
...
        public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            Console.WriteLine(UIScreen.MainScreen.Bounds);
            //iPhone 5 (and simulator) - {X=0,Y=5,60546739703229E-315,Width=0,Height=0}
            //iPhone 6 simulator - {X=0,Y=0,Width=320,Height=568}
            Console.WriteLine((RectangleF)UIScreen.MainScreen.Bounds);
            //iPhone 5 (and simulator) - {X=0,Y=640,Width=0,Height=0}
            //iPhone 6 simulator - {X=0,Y=0,Width=320,Height=568}
            Console.WriteLine(UIScreen.MainScreen.NativeBounds); 
            //iPhone 5 (and simulator) - {X=0,Y=5,64691262732458E-315,Width=0,Height=0}
            //iPhone 6 simulator - {X=0,Y=0,Width=640,Height=1136}
            Console.WriteLine((RectangleF)UIScreen.MainScreen.NativeBounds); 
            //iPhone 5 (and simulator) - {X=0,Y=640,Width=0,Height=0}
            //iPhone 6 simulator - {X=0,Y=0,Width=640,Height=1136}
            return true;
        }
...

Also iPhone 6 has 1334×750 native resolution.

Configuration:
 PC:
  Microsoft Visual Studio Professional 2012   Version 11.0.61030.00 Update 4
  Microsoft .NET Framework   Version 4.5.50938
  Windows 8(x64) ver. 6.2 (build 9200)
  Xamarin   3.7.203.0 (ff146f5240189a2ec6d3c6f75cf3967f79c79a18)
  Xamarin.Android   4.18.0.34 (3b7ef0a796e8744972c48034403a6e7cb7ec189e)
  Xamarin.iOS   8.2.0.0 (65b2f3a0f52f365b90ac952f0ec2e40fa0b510d4)
 Mac:
  MacBookPro (2011 year)
  XCode 6.0.1
  Xamarin Studio Version 5.6 (build 273)
   Installation UUID: 3c4fd657-1e45-4839-a35d-d64b6f832da1
   Runtime:
      Mono 3.10.0 ((detached/633e444)
      GTK+ 2.24.23 (Raleigh theme)
 Device:
  iPhone 5 (iOS 8.0.2)
Comment 1 shtyle@rambler.ru 2014-10-16 01:56:16 UTC
Created attachment 8428 [details]
Blank App project
Comment 2 shtyle@rambler.ru 2014-10-16 05:33:56 UTC
Also simple code string:
..
nfloat a = 32;
Console.WriteLine(a);
..
print result 
  {5.47077039858234E-315}
Comment 3 Udham Singh 2014-10-16 06:40:15 UTC
I have checked this issue by doing the steps below:

1. Create a simple iOS app ('Blank App(iPhone)').
2. Add below code in method 'FinishedLaunching' in class 'AppDelegate.cs'.

Console.WriteLine(UIScreen.MainScreen.Bounds);           
Console.WriteLine((RectangleF)UIScreen.MainScreen.Bounds);           
Console.WriteLine(UIScreen.MainScreen.NativeBounds);           
Console.WriteLine((RectangleF)UIScreen.MainScreen.NativeBounds);           
return true;

3. Run the app on iPhone 5 and iPhone 6 simulators, And got the below results in output window

 *Result For iPhone 5 Simulator

   {X=0,Y=5.60546739703229E-315,Width=0,Height=0}
   {X=0,Y=320,Width=0,Height=0}
   {X=0,Y=5.64691262732458E-315,Width=0,Height=0}
   {X=0,Y=640,Width=0,Height=0}

 *Result For iPhone 6 Simulator

   {X=0,Y=0,Width=320,Height=568}
   {X=0,Y=0,Width=320,Height=568}
   {X=0,Y=0,Width=640,Height=1136}
   {X=0,Y=0,Width=640,Height=1136}

Could you please have a look on this and let me know if these outputs are similar to yours.

Screencast : http://www.screencast.com/t/tLEhcMPRum6

Environment Info : 

Windows 8.1

Microsoft Visual Studio Professional 2013
Version 12.0.30723.00 Update 3
Microsoft .NET Framework
Version 4.5.51641
Installed Version: Professional

Xamarin : 3.7.203.0
Xamarin.iOS Build Host : 8.2.0.193
Comment 4 shtyle@rambler.ru 2014-10-16 06:57:24 UTC
Yes, it's looks like my bugs. I found that problem occures when system struct 'nfloat' writes his included double value on device/simulator from any .NET runtime variable. So, there is no fast solution...
 Thanks for your comment.
Comment 5 Rolf Bjarne Kvinge [MSFT] 2014-10-17 04:00:20 UTC
@Udham, did you try in Xamarin Studio or Visual Studio? Can you try from Visual Studio if you didn't already?
Comment 6 Udham Singh 2014-10-17 05:04:39 UTC
Hi Rolf,

I have checked this in Visual Studio as shown in screencast provided in comment 3.
Screencast : http://www.screencast.com/t/tLEhcMPRum6

Thanks
Comment 7 Rolf Bjarne Kvinge [MSFT] 2014-10-17 05:47:18 UTC
@Udham, can you zip up and attach the .app directory from the Mac? The path is shown in the Output pad (you can see it in the screencast, at the top of the Output pad "Loaded assembly: /Users/360_macmini/Library/Developer/.../")
Comment 8 Udham Singh 2014-10-17 07:19:44 UTC
@Rolf, I have uploaded  the .app directory in Dropbox. Please download these directories from the link below:

For iPhone 5 iOS 8.0 (Simulator) : https://www.dropbox.com/s/ye2c38ibx5quqs8/app%20-%20iPhone%205%20iOS%208.0.zip?dl=0

For iPhone 6 iOS 8.0 (Simulator) : https://www.dropbox.com/s/f19pqf8kqzx0564/app%20-%20iPhone%206%20iOS%208.0.zip?dl=0
Comment 9 Rolf Bjarne Kvinge [MSFT] 2014-10-17 13:33:12 UTC
@Udham, can you add "-v -v -v -v" to the additional mtouch arguments in VS and attach the full build output?
Comment 10 Udham Singh 2014-10-17 14:15:22 UTC
Hi Rolf,

Below are the application output log.

For iPhone 5 : https://gist.github.com/Parmendrak/f8b1047b4fd15c6c4e9b
For iPhone 6 : https://gist.github.com/Parmendrak/d5f6e54e215e36a4c063

I have checked this with Xamarin 3.7.226 and and Build Host 8.2.0.207, and attached logs are obtained with these builds.

Thanks
Comment 11 Udham Singh 2014-10-17 14:29:25 UTC
An update to the comment 10.

For iPhone 5:

Diagnostic Output Log : https://gist.github.com/Parmendrak/fbb440db673ef56ec188
Build Order Log : https://gist.github.com/Parmendrak/b92e297f5b9f37b2db5a
Mtvs Server Log : https://gist.github.com/Parmendrak/78ee5c9571dc74d90c4a
Output Log : https://gist.github.com/Parmendrak/85a5b59477694ca24af8

For iPhone 6:

Diagnostic Output Log : https://gist.github.com/Parmendrak/7ecae029b71ee0959006
Build Order Log : https://gist.github.com/Parmendrak/a031fe60aeab38a8aa5b
Mtvs Server Log : https://gist.github.com/Parmendrak/aad9f8dc47b76165e298
Output Log : https://gist.github.com/Parmendrak/8ec34d615e15b2361a51


I have checked this with Xamarin 3.7.226 and and Build Host 8.2.0.207, and
attached logs are obtained with these builds.

Thanks
Comment 12 Rolf Bjarne Kvinge [MSFT] 2014-10-20 04:52:01 UTC
@kzu: it looks like MTVS is copying Xamarin.iOS.dll from Windows (see the Build Order Logs from previous comment):

1>  Copying bin/iPhoneSimulator/Debug/Xamarin.iOS.dll... (TaskId:54)

Is this on purpose?
Comment 13 Cody Beyer (MSFT) 2014-10-23 16:25:04 UTC
Still happening in

=== Xamarin Studio ===

Version 5.6.2 (build 5)
Installation UUID: 3e4348fa-e0b3-46a4-8426-58f27e19159e
Runtime:
	Mono 3.10.0 ((detached/633e444)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 310000020

=== Apple Developer Tools ===

Xcode 6.1 (6604)
Build 6A1052d

=== Xamarin.Mac ===

Version: 1.10.0.18 (Business Edition)

=== Xamarin.Android ===

Version: 4.18.0 (Business Edition)
Android SDK: /Users/codybeyer/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		2.1   (API level 7)
		2.2   (API level 8)
		2.3   (API level 10)
		3.1   (API level 12)
		4.0.3 (API level 15)
		4.2   (API level 17)
		4.4   (API level 19)
Java SDK: /usr
java version "1.8.0_25"
Java(TM) SE Runtime Environment (build 1.8.0_25-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode)

=== Xamarin.iOS ===

Version: 8.4.0.15 (Business Edition)
Hash: 08968c4
Branch: 
Build date: 2014-10-20 21:48:06-0400

=== Build Information ===

Release ID: 506020005
Git revision: 19bc3b64b70332bfab18faf9cf1ce7d3aa191b36
Build date: 2014-10-17 14:49:01-04

=== Operating System ===

Mac OS X 10.10.0
Darwin Codys-MacBook-Pro.local 14.0.0 Darwin Kernel Version 14.0.0
    Fri Sep 19 00:26:44 PDT 2014
    root:xnu-2782.1.97~2/RELEASE_X86_64 x86_64
Comment 14 Rolf Bjarne Kvinge [MSFT] 2014-10-24 04:10:08 UTC
=> Visual Studio.

The problem is that Xamarin.iOS.dll is copied from the Windows machine and referenced directly, instead of just referencing the reference version on the Mac. mtouch contains logic to select the proper 32bit or 64bit version of Xamarin.iOS.dll if the reference version on the Mac is referenced, but that won't work if VS copies over whatever's referenced on the Windows machine.
Comment 15 Kerry 2014-10-24 05:06:50 UTC
I'm seeing this same problem with an actual device, in this case an iPhone 6 Plus.
Comment 17 Brendan Zagaeski (Xamarin Team, assistant) 2014-10-30 00:40:11 UTC
Here are two more bugs that are likely duplicates of this bug:
https://bugzilla.xamarin.com/show_bug.cgi?id=23312
https://bugzilla.xamarin.com/show_bug.cgi?id=24151
Comment 18 Brendan Zagaeski (Xamarin Team, assistant) 2014-10-30 12:24:11 UTC
*** Bug 23499 has been marked as a duplicate of this bug. ***
Comment 19 Brendan Zagaeski (Xamarin Team, assistant) 2014-11-01 00:58:51 UTC
Created attachment 8588 [details]
Patched targets file for workaround

## Workarounds

These workarounds are based on comment 14. They are not final fixes (I'm not a developer on the VS team), but at least with Xamarin 3.7.248 they do produce the desired behavior for this bug as well as bug 24151. I quickly tested this result on both simulators and devices.


### Option 1

Force `mtouch` to use the correct assembly on the Mac build host by adding the following line under "Project properties -> iOS Build -> Additional mtouch arguments":

(Remove the > greater-than character from the beginning of the line)

> -r /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/Xamarin.iOS/Xamarin.iOS.dll


After this change, you'll need to fix up the `<MtouchArch>` element in the `.csproj` file by hand due to bug 24150.

For hardware device configurations:
> <MtouchArch>ARMv7, ARM64</MtouchArch>

For simulators configurations:
> <MtouchArch>i386, x86_64</MtouchArch>


### Option 2

Replace `C:\Program Files (x86)\MSBuild\Xamarin\iOS\Xamarin.iOS.Common.targets` with the attached patched version (based on Xamarin 3.7.248). This essentially does the same thing as "Option 1," but it does it automatically, and it also prevents VS from copying the redundant Windows version of `Xamarin.iOS.dll` to the build host.

#### Diff vs. the original `.targets` file

(Remove the > greater-than character from the beginning of each line)

> --- Xamarin.iOS.Common.targets
> +++ Xamarin.iOS.Common.targets
> @@ -383,0 +384,2 @@
> +			<XamarinIosReferencePath Include="@(ReferencePath)" Condition="'%(Filename)' == 'Xamarin.iOS'" />
> +			<ReferencePathWithoutXamarinIos Include="@(ReferencePath)" Condition="'%(Filename)' != 'Xamarin.iOS'" />
> @@ -384,0 +387,3 @@
> +		<PropertyGroup>
> +			<MtouchExtraArgs Condition="'@(XamarinIosReferencePath->Count())' > '0'">$(MtouchExtraArgs) -r /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/Xamarin.iOS/Xamarin.iOS.dll</MtouchExtraArgs>
> +		</PropertyGroup>
> @@ -408 +413 @@
> -			References="@(ReferencePath);@(MTouchReferencePath)"
> +			References="@(ReferencePathWithoutXamarinIos);@(MTouchReferencePath)"
Comment 20 Olaf Bartelt 2014-11-04 09:01:52 UTC
Had a similar bug with a project converted to Unified API, where, when accessing UITableView.ContentOffset, the app crashed (in the simulator) with a "method cache corrupted" error.

Option 2 from comment 19 fixed it for me, so please include that in the next update after checking.
Comment 25 Udham Singh 2014-11-06 11:00:45 UTC
I have checked this issue with the code provided in bug description and getting the below output for both simulators iPhone 5 and iPhone 6.

{X=0,Y=0,Width=320,Height=568}
{X=0,Y=0,Width=320,Height=568}
{X=0,Y=0,Width=640,Height=1136}
{X=0,Y=0,Width=640,Height=1136}


I have also checked with code provided in comment 2 and getting the expected output in application output window.

Screencast : http://www.screencast.com/t/4RfMl5wc

As of now I am closing this issue. Please let me know if I have check anything else to verify this issue.

Environment Info :

Windows 8
VS 2013
Xamarin 3.8.113.0
Xamarin.iOS Build Host 8.4.0.28
Comment 28 Udham Singh 2014-11-13 08:06:32 UTC
Hi Vlad,

This issue is fixed with current xamarin beta (Xamarin 3.8.134). You can find it in beta channel.

Screencast : http://www.screencast.com/t/OgusiniIQFN

Thanks
Comment 29 Brendan Zagaeski (Xamarin Team, assistant) 2015-04-10 20:56:52 UTC
*** Bug 24151 has been marked as a duplicate of this bug. ***
Comment 30 Jori Seidel 2015-05-22 05:33:11 UTC
Sorry to react to a bug that has been closed for several months, but I am currently experiencing this issue after updating to the unified API. After a long period I discovered that the only solution for me is to rename the folder where the csproj file is located. So no changes to code or anything like that helps.

Could it be that Xamarin somehow caches something with regards to this directory or something? I'm almost certain there is a directory somewhere on my PC or Macbook that needs deletion to make it work, but I am unsure which one.
Comment 31 Jori Seidel 2015-05-22 05:58:15 UTC
I've found the solution. After I built the project once more after renaming the folder, I got an error message:

Error	1	System.IO.FileNotFoundException: /Users/joriseidel/Library/Caches/Xamarin/mtbs/builds/ArchieiOS/a9f48fbd727d3d601c1a50eb3e61ff13/obj/iPhone/Debug/html/images/archie_banner.png does not exist

And so I thought it might be the cache directory I mentioned in my previous comment. After I deleted the  directory /Users/joriseidel/Library/Caches/Xamarin/mtbs/builds and now it works (even with the old directory name).

So I guess the problem has something to do with migrating to the unified API.