Bug 25758 - [XVS.iOS 3.9] MtouchExtraArgs variables no longer expand, causing "Input string was not in a correct format" error
Summary: [XVS.iOS 3.9] MtouchExtraArgs variables no longer expand, causing "Input stri...
Status: VERIFIED FIXED
Alias: None
Product: Visual Studio Extensions
Classification: Xamarin
Component: iOS ()
Version: 3.9
Hardware: PC Windows
: High major
Target Milestone: 3.9.1
Assignee: Jose Gallardo
URL:
: 25753 ()
Depends on:
Blocks:
 
Reported: 2015-01-06 17:21 UTC by Brendan Zagaeski (Xamarin Team, assistant)
Modified: 2015-05-08 09:38 UTC (History)
14 users (show)

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


Attachments
Test case (9.28 KB, application/zip)
2015-01-06 17:21 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 Brendan Zagaeski (Xamarin Team, assistant) 2015-01-06 17:21:27 UTC
Created attachment 9259 [details]
Test case

Using MSBuild properties in subarguments of the "--gcc_flags" MtouchExtraArgs argument cause "Input string was not in a correct format" error. This bug is similar to bug 22614, but this new bug only happens starting in XVS 3.9.

Regression status: regression between XVS 3.8.150 + XI 8.4.0.43 and XVS 3.9.221 + XI 8.6.0.41


## Steps to reproduce

Attempt to build and debug the attached test case on device or simulator from Visual Studio.

The test case is just an iPhone Classic API template project with a few lines added to call and display the results of the `test()` native method. The `test()` native method is defined in `libfoo.a`.


## Partial workaround

One way to work around the problem is to replace the `${ProjectDir}` entries in the MtouchExtraArgs with absolute paths.


For example for the attached test case, I changed:

> --gcc_flags "-L${ProjectDir}/lib -lfoo 
> -force_load ${ProjectDir}/lib/libfoo.a"

... to:
> --gcc_flags
> "-L/Users/macuser/Library/Caches/Xamarin/mtbs/builds/iPhoneApp1/e5058807dab2fcc4f62e474dcf461f29/lib
> -lfoo
> -force_load /Users/macuser/Library/Caches/Xamarin/mtbs/builds/iPhoneApp1/e5058807dab2fcc4f62e474dcf461f29/lib/libfoo.a"


Maybe the MTouch Task isn't expanding the `${ProjectDir}` variables correctly?


## Result

### Error from the Output -> Build window in Visual Studio

> Server returned an error. The remote server returned an error: (500) Internal Server Error.
>   Server error code: 500
>   Internal Server Error
>   
>    (TaskId:58)
>   Remote task execution failed. (TaskId:58)
>   MTouchTask: 2015-01-06T16:35:29.4685344-05:00 - Finished (TaskId:58)
> Done executing task "MTouchTask" -- FAILED. (TaskId:58)
> Done building target "_CompileToNative" in project "iPhoneApp1.csproj" -- FAILED.: (TargetId:93)

### Corresponding error from ~/Library/Logs/Xamarin/MonoTouchVS/mtbserver.log

> [06-Jan-2015 16:35:29] Error: Command [ExecuteTask: CommmandUrl=ExecuteTask] failed.
> [06-Jan-2015 16:35:29] Exception: Exception type: System.FormatException
> Input string was not in a correct format.
>   at System.String.ParseFormatSpecifier (System.String str, System.Int32& ptr, System.Int32& n, System.Int32& width, System.Boolean& left_align, System.String& format) [0x00000] in <filename unknown>:0 
>   at System.String.FormatHelper (System.Text.StringBuilder result, IFormatProvider provider, System.String format, System.Object[] args) [0x00000] in <filename unknown>:0 
>   at System.String.Format (IFormatProvider provider, System.String format, System.Object[] args) [0x00000] in <filename unknown>:0 
>   at System.String.Format (System.String format, System.Object[] args) [0x00000] in <filename unknown>:0 
>   at Mtb.Server.LoggingHelperRecorder.LogMessage (System.String message, System.Object[] messageArgs) [0x00000] in <filename unknown>:0 
>   at Mtb.Server.BuildEngine.LogMessageEvent (Microsoft.Build.Framework.BuildMessageEventArgs e) [0x00000] in <filename unknown>:0 
>   at Microsoft.Build.Utilities.TaskLoggingHelper.LogMessageFromText (System.String lineOfText, MessageImportance messageImportance) [0x00000] in <filename unknown>:0 
>   at Microsoft.Build.Utilities.TaskLoggingHelper.LogMessage (MessageImportance importance, System.String message, System.Object[] messageArgs) [0x00000] in <filename unknown>:0 
>   at (wrapper remoting-invoke-with-check) Microsoft.Build.Utilities.TaskLoggingHelper:LogMessage (Microsoft.Build.Framework.MessageImportance,string,object[])
>   at Xamarin.MacDev.Tasks.LoggingExtensions.LogTaskProperty (Microsoft.Build.Utilities.TaskLoggingHelper log, System.String propertyName, System.String value) [0x00000] in <filename unknown>:0 
>   at Xamarin.iOS.Tasks.MTouchTaskBase.Execute () [0x00000] in <filename unknown>:0 
>   at Mtb.Server.InProcTaskRunner.Execute (ILoggingHelper logger, System.String taskName, System.String inputs) [0x00000] in <filename unknown>:0 
>   at Mtb.Server.Commands.ExecuteTask.HandleRequest (ILoggingHelper logger, System.Object commandRequestState) [0x00000] in <filename unknown>:0 
>   at Mtb.Server.BaseCommand.OnRequest (System.Net.HttpListenerContext context, System.Object commandRequestState) [0x00000] in <filename unknown>:0 
>   at Mtb.Server.Listener.OnRequest (System.Object state) [0x00000] in <filename unknown>:0 

### Corresponding command information from ~/Library/Logs/Xamarin/MonoTouchVS/iPhoneApp1_e5058807dab2fcc4f62e474dcf461f29.log
> [06-Jan-2015 16:35:29] MTouch Task
> [06-Jan-2015 16:35:29]   AppBundleDir: bin/iPhoneSimulator/Debug/iPhoneApp1.app
> [06-Jan-2015 16:35:29]   AppManifest: bin/iPhoneSimulator/Debug/iPhoneApp1.app/Info.plist
> [06-Jan-2015 16:35:29]   Architecture: i386
> [06-Jan-2015 16:35:29]   CompiledEntitlements: obj/iPhoneSimulator/Debug/Entitlements.xcent
> [06-Jan-2015 16:35:29]   Debug: True
> [06-Jan-2015 16:35:29]   EnableGenericValueTypeSharing: True
> [06-Jan-2015 16:35:29]   Entitlements: <null>
> [06-Jan-2015 16:35:29]   ExtraArgs: --gcc_flags "-L${ProjectDir}/lib -lfoo -force_load ${ProjectDir}/lib/libfoo.a"


## Expected result

The app builds and runs successfully on XamarinVS 3.8.150 + Xamarin.iOS 8.4.0.14. It also builds and runs successfully in Xamarin Studio on Mac.

When the app runs correctly, it displays the text: "Result from native method: 13".



## Version information BAD
Xamarin   3.9.221.0 (a6d269d)
Xamarin.iOS   8.6.0.0 (43e3b715220b50914b45bec675e19008ff50682a)

### Build host
Xamarin.iOS 8.6.0.41 (Business Edition)
Hash: 2c57f4e
Build date: 2014-12-18 16:42:49-0500


## Version information BAD
Xamarin   3.9.235.0 (23e2325)
Xamarin.Android   4.20.0.34 (49a04b966feb40dfdba49d57ba16249b66d606a6)
Xamarin.iOS   8.6.0.0 (cb9aa8428c4d41de5ee53797a6f05cacb43bc32c)

### Build host
Xamarin.iOS 8.6.0.49 (Business Edition)
Hash: eb24bdc
Build date: 2015-01-06 14:27:58-0500


## Version information GOOD
Xamarin   3.8.150.0 (10cfd178d55287f09c85f5a1e604dfe20889a40f)
Xamarin.iOS   8.4.0.0 (840a925103a0bf4a856507f13d5eaee3c1579c2f)

### Build host
Xamarin.iOS 8.4.0.43 (Business Edition)
Hash: 840a925
Build date: 2014-11-16 21:03:22-0500


## Additional version information

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

Xcode 6.1 (6604), Build 6A1052d

Mac OS X 10.9.5
Comment 2 Brendan Zagaeski (Xamarin Team, assistant) 2015-01-07 13:57:52 UTC
I'm adjusting the summary slightly for accuracy. The `${ProjectDir}` element is not actually an MSBuild property. It is a special variable defined specifically for the MtouchExtraArgs field.

I've also now confirmed that this problem is not exclusive to `gcc_flags`. *Any* use of these special variables in the MtouchExtraArgs field will hit the problem.


The project options dialog for iOS projects in Xamarin Studio on Mac includes a drop-down menu that offers the the following list of variables for that field:

${TargetPath}
${TargetDir}
${AppBundleDir}
${ProjectDir}
${SolutionDir}


In my quick tests, all of these expanded on XamarinVS 3.8.150 except for `${SolutionDir}`. I believe the `${SolutionDir}` problem is the issue described by bug 22614.

Perhaps also of interest, `${TargetPath}`, `${TargetDir}`, and `${AppBundleDir}` expand differently in Xamarin Studio on Mac compared to XVS 3.8.150. I'll post another update shortly to show the differences.
Comment 3 Brendan Zagaeski (Xamarin Team, assistant) 2015-01-07 18:51:32 UTC
For thoroughness, here are the more detailed differences as mentioned in comment 2.

## Results on Xamarin Studio, XI 8.4.0.43, using mdtool build engine
> ${SolutionDir}   = /Users/macuser/Projects/GccFlagsTest
> ${AppBundleDir}  = /Users/macuser/Projects/GccFlagsTest/iPhoneApp1/bin/iPhoneSimulator/Debug/iPhoneApp1.app
> ${TargetPath}    = /Users/macuser/Projects/GccFlagsTest/iPhoneApp1/bin/iPhoneSimulator/Debug/iPhoneApp1.exe
> ${TargetDir}     = /Users/macuser/Projects/GccFlagsTest/iPhoneApp1/bin/iPhoneSimulator/Debug
> ${TargetExt}     = .exe 
> ${ProjectDir}    = /Users/macuser/Projects/GccFlagsTest/iPhoneApp1

## Results on XVS 3.8.150 + XI 8.4.0.43
The potentially interesting difference here is the appearance of _relative paths_ for the App Bundle and Target* variables.

> ${SolutionDir}   = ${SolutionDir}
> ${AppBundleDir}  = bin/iPhoneSimulator/Debug/iPhoneApp1.app
> ${TargetPath}    = bin/iPhoneSimulator/Debug/iPhoneApp1.exe
> ${TargetDir}     = bin/iPhoneSimulator/Debug
> ${TargetExt}     = .exe
> ${ProjectDir}    = /Users/macuser/Library/Caches/Xamarin/mtbs/builds/iPhoneApp1/e5058807dab2fcc4f62e474dcf461f29

## Results on XVS 3.9.235 + XI 8.6.0.49
The "Input string was not in a correct format" error appears.

As far as I could tell, this error happens in the MTouch Task and causes the task to abort before the `mtouch` executable is run.



The results in Xamarin Studio on Mac using the MSBuild build engine are similar to XVS 3.8.150 + XI 8.4.0.43 except that _only_ `${AppBundleDir}` is a relative path.

## Results on Xamarin Studio, XI 8.4.0.43, using MSBuild build engine
> ${SolutionDir}   = ${SolutionDir}
> ${AppBundleDir}  = bin/iPhoneSimulator/Debug/iPhoneApp1.app
> ${TargetPath}    = /Users/macuser/Projects/GccFlagsTest/iPhoneApp1/bin/iPhoneSimulator/Debug/iPhoneApp1.exe
> ${TargetDir}     = /Users/macuser/Projects/GccFlagsTest/iPhoneApp1/bin/iPhoneSimulator/Debug
> ${TargetExt}     = .exe 
> ${ProjectDir}    = /Users/macuser/Projects/GccFlagsTest/iPhoneApp1

## Results on Xamarin Studio, XI 8.6.0.49, using MSBuild build engine
> ${SolutionDir}   = ${SolutionDir}
> ${AppBundleDir}  = bin/iPhoneSimulator/Debug/iPhoneApp1.app
> ${TargetPath}    = /Users/macuser/Projects/GccFlagsTest/iPhoneApp1/bin/iPhoneSimulator/Debug/iPhoneApp1.exe
> ${TargetDir}     = /Users/macuser/Projects/GccFlagsTest/iPhoneApp1/bin/iPhoneSimulator/Debug
> ${TargetExt}     = .exe
> ${ProjectDir}    = /Users/macuser/Projects/GccFlagsTest/iPhoneApp1
Comment 5 Virgile Bello 2015-01-08 01:15:43 UTC
No workaround?
Can't seem to do anything with latest build due to this.
Comment 6 Rajneesh Kumar 2015-01-08 07:38:15 UTC
I have tried to reproduce this issue with attached sample in bug, we are also getting this issue  "Input string was not in a correct format" error. 

Hence marking this as Confirmed.

Supplement info:
mtbserver log:  https://gist.github.com/saurabh360/3f0a548c30d9f816baa3
MonoTouchVS log: https://gist.github.com/saurabh360/06783e5ba879833f2ff6
Build output: https://gist.github.com/saurabh360/5db2ff0c79a4db85a4e2
VS ide logs: https://gist.github.com/saurabh360/5c664cdb6227b6d4f41c
Screencast: http://screencast.com/t/7Waed7WaDR

Environment info:
VS 2013
Windows 7 and 8
Xamarin 3.9.236
X.iOS 8.6.0.50
Xcode 5.1.1 and Xcode 6.2
Comment 7 Jose Gallardo 2015-01-09 12:07:38 UTC
*** Bug 25753 has been marked as a duplicate of this bug. ***
Comment 9 Joaquin Jares 2015-01-14 10:05:21 UTC
This is resolved and will be shipped in 3.9.1.
Comment 10 Sunil Kumar 2015-01-15 05:44:37 UTC
I have checked this issue and still getting the same "Input string was not in a correct format" error. 

Screencast: http://www.screencast.com/t/PfNoLvmIjwTj
mtbserver log: https://gist.github.com/sunil360/fc82c18f9c58800875e9

Hence Reopening this issue.

Environment info:
Microsoft Visual Studio Professional 2013
Version 12.0.31101.00 Update 4
Microsoft .NET Framework
Version 4.5.50938

Xamarin   3.9.257.0 (e36f3f3)
Xamarin.Android   4.20.0.34 (49a04b966feb40dfdba49d57ba16249b66d606a6)
Xamarin.iOS   8.6.0.0 (dfb682fa615491b012ed24198d2bdcd641e1874f)

Build host info:
X.IOS 8.6.0.52
Mono 3.12.0.68
Xcode 5.1.1
Comment 11 Mohit Kheterpal 2015-01-15 06:06:21 UTC
I have checked this issue using XVS 3.9.257 + X.iOS 8.6.0.51 + Xamarin.iOS build host 3.9.0.257
and this issue is working fine now i.e. we are not getting any error like "Input string was not in a
correct format". 

Actually In comment 10, Sunil does not use xamarin.iOS build host so that's why he was getting same issue. However with Xamarin .iOS build host3.9.257 this issue is working fine.

Hence closing this issue.