Bug 52849 - Failure to deploy application to device with resource content using Visual Studio
Summary: Failure to deploy application to device with resource content using Visual St...
Status: RESOLVED NORESPONSE
Alias: None
Product: Visual Studio Extensions
Classification: Xamarin
Component: iOS ()
Version: 4.3.0 (C9)
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2017-02-27 16:38 UTC by jnoyes
Modified: 2017-04-20 00:07 UTC (History)
4 users (show)

Tags:
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 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:
RESOLVED NORESPONSE

Description jnoyes 2017-02-27 16:38:25 UTC
When trying to build to an iOS device using Visual Studio, the build will launch but crash on trying to read a resource file located in the Project.iOS folder.  This appears to be a Visual Studio only bug since this is not an issue when building to a device using Xamarin Studio on a Mac.
Comment 1 Brendan Zagaeski (Xamarin Team, assistant) 2017-02-27 23:00:22 UTC
## Bookkeeping note

I will assign this bug to myself for a moment for a preliminary non-engineering team review.
Comment 2 Brendan Zagaeski (Xamarin Team, assistant) 2017-02-27 23:57:50 UTC
Non-engineering team preliminary quick review




## Steps attempted to replicate


1. Create a new "Visual C# > iPhone > Single View App (iPhone)" project.  I named the project "SingleView1.iOS" for my test.


2. Add a .png file to the project as a BundleResource.  I named the .png file "Test.png" for my test.


3. Add lines similar to the following the the `ViewDidLoad()` override:

```
var imageView = new UIImageView(UIImage.FromBundle("Test.png"));
imageView.Frame = new CoreGraphics.CGRect(10, 10, 200, 200);
View.AddSubview(imageView);
```

4. Deploy and run the app a physical iOS device.



### Results with my current local Xamarin Cycle 9 environment

The .png is displayed successfully on the device screen after the app launches.




## Suggested next steps for the reporter

(See https://developer.xamarin.com/guides/cross-platform/troubleshooting/questions/howto-file-bug/ for general reference.)



1. Please provide any relevant stack traces, error message text, or crash logs.  The bug does not yet mention the text of any errors you might be seeing for example from the iOS device crash reports, the iOS device console logs, or the "Output > Debug" window.



2. Please provide additional details about the scenario you are following to see a problem.  For a starting place, can you reproduce the problem in a template iOS project to which you have added a single image file?  If not, please suggest additional conditions required to replicate the problem.  For example:

(a) Simplify your original project to a small sample that still demonstrates the issue, and then attach it back.

or

(b) As another smaller alternative, maybe attach back just the .csproj file from the project that demonstrates the issue.



3. Please describe the environment where the bug was encountered, including the operating system and versions of Xamarin and any dependencies.  As a start, you can collect and attach back the Visual Studio version information from "Help > About Microsoft Visual Studio > Copy Info".



4. Especially if it is not possible to provide a test case, please collect and attach back the diagnostic build output for the "bad" build:

a. Set "Tools > Options > Projects and Solutions > Build and Run > MSBuild project build output verbosity" to Diagnostic.

b. The next time you build the project the diagnostic MSBuild output will now be visible in the Output window.

c. You can then save the output to a file via "File > Save Output As...", and then zip up and attach back that file.

(https://msdn.microsoft.com/en-us/library/jj651643.aspx)




* * *

Preliminary review bookkeeping




## Common indications of incorrect behaviors



### Suspected to be a regression or a problem with a new feature?

Uncertain.  For example, the reporter did not mention whether the problem was present in earlier versions with the same project.



### Specific to one particular project, development computer, or target mobile device?

Uncertain.  Additional information from the reporter would be excellent.  See the "Suggested next steps."




## Ease of reproducing and studying the issue locally



### Includes clear steps to reproduce the problem?

Not yet.  See the "Steps attempted" and the "Suggested next steps."



### Makes an effort to narrow down the particular part of the process where something goes wrong (IDE editing, MSBuild building, deploying, launching, attaching the debugger, an in-app error, or something else)?

Yes.  The reporter describes that the issue is likely an MSBuild building issue that causes an in-app exception and crash when the app launches on device.



### Considers the relevant log files for that part of the process and has them attached?

Not yet.  See the "Suggested next step" 3.




## Area of impact

Not applicable for now until we know a bit more about the failure scenario.
Comment 3 jnoyes 2017-02-28 18:27:50 UTC
Unfortunately I am not allowed to share much of the code/output for this current project.

The Visual Studio I am using is Community 2015 with the latest update from Xamarin.  I'm trying to read in a XML file that is built as Content and set to copy always.  Within the code, I have a function that tries to open and read the XML file, this works on the simulator, however with the device I get an object is null error.  Copying over the same code to the MacBook and building with Xamarin Studio to the device works with no issue.
Comment 4 Brendan Zagaeski (Xamarin Team, assistant) 2017-03-02 03:36:13 UTC
I can potentially try another local experiment to see if switching to using an XML resource in some way is sufficient to replicate the problem.


In order for me to try that, I'd like to request as prerequisites 3 additional pieces of information:


- A snippet of the code that tries to use the XML resource, at the level of the Xamarin.iOS API calls.  This might be as short as one line.  You may randomize the letters of the filename and path in the string that gets passed to the function, but please keep any path markers intact.


- The specific iOS test device being used, including the model and the iOS version.


- For thorough bookkeeping, paste the precise "Xamarin" version including the 4-digit version number and the 7-character hash from the Visual Studio information dialog into your next reply.




Once those 3 pieces of information are present, I will proceed with an additional experiment.  Thanks!
Comment 5 Brendan Zagaeski (Xamarin Team, assistant) 2017-04-20 00:04:21 UTC
## Additional steps attempted to replicate: not yet able to replicate


1. Create a new "Visual C# > iPhone > Single View App (iPhone)" project.  I named the project "SingleView1.iOS" for my test.


2. Add a .xml file to the project as a BundleResource.  I named the .xml file "Test.xml".


3. Add lines similar to the following in the `ViewController.ViewDidLoad()` override:

```
var xmlContents = 
var imageView = new UIImageView(UIImage.FromBundle("Test.png"));
imageView.Frame = new CoreGraphics.CGRect(10, 10, 200, 200);
View.AddSubview(imageView);
```

4. Deploy and run the app on a physical iOS device in the "Debug | iPhone" configuration.




## Results in my test environment with XamarinVS 4.3.0.784 "Cycle 9" as published on 2017-02-22

The contents of the .xml file are displayed successfully on the device screen after the app launches.




## Additional testing environment info



### Windows

Visual Studio 2015 Update 3
Windows 10 (64-bit) Version 1607 (OS Build 14393.1066)



### Mac

Xamarin.iOS 10.4.0.123 (cycle9: 35d1ccd)
Mono 4.8.0 (mono-4.8.0-branch/e4a3cf3)

Xcode 8.2.1, Build version 8C1002
Mac OS 10.12.4



### iOS device

iPad Mini 2, iOS 8.0
Comment 6 Brendan Zagaeski (Xamarin Team, assistant) 2017-04-20 00:05:06 UTC
## Status update

I will mark this bug as resolved for now for bookkeeping, with a suspicion that the reporter of the bug might have already resolved the issue by examining the diagnostic build output or by updating to newer versions of Xamarin.  If the reporter would like to pick back up on the investigation at some future date, please follow-up with the additional information from Comment 4 (*), and then change the "Status" of this bug to "REOPENED".  Thanks!

(*) The diagnostic build output ("Suggested next step" 4 from Comment 2) would also be excellent.  In case it might be helpful, I could mark this bug as non-public so that the build output shared back would only be visible to the Xamarin team.
Comment 7 Brendan Zagaeski (Xamarin Team, assistant) 2017-04-20 00:07:34 UTC
Correction for step 3 in Comment 5

3. Add lines similar to the following in the `ViewController.ViewDidLoad()` override:

```
string xmlResourcePath = NSBundle.MainBundle.PathForResource("Test", "xml");
string xmlResourceContent = System.IO.File.ReadAllText(xmlResourcePath);
UITextView textView = new UITextView(new CoreGraphics.CGRect(10, 10, 200, 200));
textView.Text = xmlResourceContent;
View.AddSubview(textView);
```