Bug 35232 - [XI 9.1] According to Microsoft Csc.exe, the new btouch enum behavior generates invalid C# enums in the ".g.cs" files, causing "error CS1008: Type byte, sbyte, short, ushort, int, uint, long, or ulong expected"
Summary: [XI 9.1] According to Microsoft Csc.exe, the new btouch enum behavior generat...
Status: VERIFIED FIXED
Alias: None
Product: iOS
Classification: Xamarin
Component: Tools ()
Version: XI 9.1 (iOS 9.1)
Hardware: PC All
: --- major
Target Milestone: 9.1 (iOS 9.1)
Assignee: Bugzilla
URL:
: 35220 ()
Depends on:
Blocks: 35231
  Show dependency tree
 
Reported: 2015-10-24 02:03 UTC by Brendan Zagaeski (Xamarin Team, assistant)
Modified: 2015-10-28 10:23 UTC (History)
6 users (show)

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


Attachments
Test case (6.67 KB, application/zip)
2015-10-24 02:03 UTC, Brendan Zagaeski (Xamarin Team, assistant)
Details
Diagnostic build output from XVS 3.11.1585 (100.76 KB, text/plain)
2015-10-24 02:04 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 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 Brendan Zagaeski (Xamarin Team, assistant) 2015-10-24 02:03:37 UTC
Created attachment 13515 [details]
Test case

[XI 9.1] According to Microsoft Csc.exe, the new btouch enum behavior generates invalid C# enums in the ".g.cs" files, causing "error CS1008: Type byte, sbyte, short, ushort, int, uint, long, or ulong expected"


Additional context about the new behavior of btouch in XI 9.1:
http://developer.xamarin.com/releases/ios/xamarin.ios_9/xamarin.ios_9.1/#Binding_generator_support_for_enums




## Regression status: regression in Xamarin.iOS 9.1




### Temporary workaround

Move the `StructsAndEnums.cs` file to a separate small iOS class library project, set the build action of the file to "Compile", and then reference that class library project from the binding project.




## Steps to reproduce

Attempt to build the attached test case on Windows in Visual Studio while paired successfully with the Mac build host.



### This is not a Windows-specific problem

The underlying problem as described in the "Results" _does_ also happen when building entirely on Mac, but Mono `mcs` is just more lenient about how `enum` types may be defined, so the build completes successfully.



### About the test case

The test case is a "new from template", completely empty binding project with only the following lines added to the `ApiDefinition.cs` file [1]:

> public enum Foo : uint
> {
>     Bar,
>     Baz
> }



[1] Note that this is different than the old technique (before XI 9.1) of putting the enum in the `StructsAndEnums.cs` file.




## Results

The build fails:

> c:\Volumes\Cases\macuser\Library\Caches\Xamarin\mtbs\builds\UnifiedIosBindingsLibrary1\f30b2ccf8c3acf00de2af6aa52478cf8\obj\Debug\ios\UnifiedIosBindingsLibrary1\Foo.g.cs(37,20,37,26):
> error CS1008: Type byte, sbyte, short, ushort, int, uint, long, or ulong expected



The problem is that `btouch` has generated a `Foo.g.cs` file with the following contents:

> namespace UnifiedIosBindingsLibrary1 {
> 	public enum Foo : System.UInt32 {
> 		Bar = 0,
> 		Baz = 1,
> 	}
> }



`Csc.exe` on Windows apparently _requires_ that enum definitions use short names for their parent types. That is, rather than:

> System.UInt32

... the type _must_ be written as:

> uint
Comment 1 Brendan Zagaeski (Xamarin Team, assistant) 2015-10-24 02:04:47 UTC
Created attachment 13516 [details]
Diagnostic build output from XVS 3.11.1585
Comment 2 Brendan Zagaeski (Xamarin Team, assistant) 2015-10-24 02:15:03 UTC
*** Bug 35220 has been marked as a duplicate of this bug. ***
Comment 3 Sebastien Pouliot 2015-10-25 21:47:18 UTC
That one is a surprise.

Fixed in maccore/xcode7.1 911b2c5023e251ee65431f22ad0e87f6c7d30247 for QA verification, before backport to maccore/monotouch-9.1.0-branch.
Comment 5 Mohit Kheterpal 2015-10-27 16:05:40 UTC
I have checked this with XVS 99.0.0.421 + XI 9.3.1.59 after building the test case attached in bug, it is getting build successfully and we are getting below code in ApiDefinitions.cs at path Caches\Xamarin\mtbs\builds\UnifiedIosBindingsLibrary1\f30b2ccf8c3acf00de2af6aa52478cf8

using System;
using System.Drawing;

using ObjCRuntime;
using Foundation;
using UIKit;

namespace UnifiedIosBindingsLibrary1
{
    public enum Foo : uint
    {
        Bar,
        Baz
    }
}

There is no Foo.g.cs file generated. I have also noticed that the path Library\Caches\Xamarin\mtbs\builds\UnifiedIosBindingsLibrary1\f30b2ccf8c3acf00de2af6aa52478cf8\obj\Debug\ios\ is getting break, we are not getting UnifiedIosBindingsLibrary1 directory at the path Library\Caches\Xamarin\mtbs\builds\UnifiedIosBindingsLibrary1\f30b2ccf8c3acf00de2af6aa52478cf8\obj\Debug\ios\.

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

I have clean and rebuild the test case attached but still getting the same behavior.



I have added the binding project reference in main project but after building the main project, it does not find the reference of binding project and getting build error.

"Error 1 The type or namespace name 'UnifiedIosBindingsLibrary1' could not be found (are you missing a using directive or an assembly reference?) C:\Users\Arpit\Desktop\New folder (3)\InvalidGeneratedEnum (1)\InvalidGeneratedEnum\App21111\ViewController.cs 4 7 App21111"

I have also checked assembly reference (binding project) with main project and still observe the same build error. And also it does not show "using UnifiedIosBindingLibrary1;" in auto completion window if I add assembly reference.
Comment 6 Brendan Zagaeski (Xamarin Team, assistant) 2015-10-27 16:15:50 UTC
Confirming this bug will now be a little tricky because of the fix for Bug 35231. The fix for Bug 35231 means that by default, the `enum` generation behavior is OFF, which means the `btouch` behavior will be back to the old familiar behavior from Xamarin.iOS 9.0 and earlier, where there was no `Foo.g.cs` file.

To enable the new generation behavior for `Foo.g.cs` it is necessary to pass the "-process-enums" command line option to `btouch`. The most direct way to do that might be to copy-and-paste the `btouch` command from the diagnostic build output into Terminal.app on the Mac, and then add the -process-enums option.
Comment 7 Sebastien Pouliot 2015-10-27 16:19:13 UTC
> There is no Foo.g.cs file generated.

Yes, that's the catch-22. The fix for #35231 hides this issue and Brendan beat me to update the bug ;-)

@Brendan did you really mean to close the bug again ?


OTOH I'm not sure about the 2nd part - but it could be related to the other fix which changed the paths to be fully qualified.
Comment 8 Brendan Zagaeski (Xamarin Team, assistant) 2015-10-27 17:35:50 UTC
>  @Brendan did you really mean to close the bug again ?


Yup, that was a small bit of wishful thinking on my part to request one more verification pass. But happily it was correct too :)


For simplicity now, I have gone ahead and verified this individual fix using:

GOOD: XVS 99.0.0.421 (0065674c) + XI 9.3.1.59 (b027a56)
GOOD: XVS 4.0.0.1566 (5abb0de)  + XI 9.3.1.59 (b027a56)



## Steps to verify


1. Move `btouch-native` to a backup location using Terminal.app:

> $ sudo mv -n /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/bin/btouch-native /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/bin/btouch-native-bak


2. Create a `btouch-native` wrapper that adds the `-process-enums` argument:

> $ printf '#!/bin/sh\n/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/bin/btouch-native-bak -process-enums $*\n' | sudo tee /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/bin/btouch-native

> $ sudo chmod +x /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/bin/btouch-native


3. Add a new from template Unified single view iOS application in Visual Studio that references the binding project and sets `var x = UnifiedIosBindingsLibrary1.Foo.Bar;` in the `ViewDidLoad()` override.


4. Ensure both projects are set to build in the current "Build -> Configuration Manager" configuration.


5. Build the application project (I tested using the "Debug|iPhoneSimulator" configuration).




## The second problem from comment 5: not a regression

> we are not getting UnifiedIosBindingsLibrary1 directory at the path

> "The type or namespace name 'UnifiedIosBindingsLibrary1' could not be found"


This is fairly subtle, but this isn't a regression so I'm not too worried about it. I was able to resolve this problem in the expected way: move the definition of `Foo` back into the "StructsAndEnums.cs" file. This is the "expected way" because the StructsAndEnums.cs file is the _correct_ location for enums when *not* using the `-process-enums` argument. (That is, there are 2 different possible correct places for the definition of `Foo` in this bug report, depending on whether or not you use the `-process-enums` argument for `btouch`.)


We could potentially file an enhancement request to warn or throw a better error when a bindings library contains no code and so produces no `.dll`.
Comment 9 Brendan Zagaeski (Xamarin Team, assistant) 2015-10-27 17:37:17 UTC
This is VERIFIED on maccore/xcode7.1 per comment 8. I am setting the status back to RESOLVED to track the backport to maccore/monotouch-9.1.0-branch.

Thanks!
Comment 10 Oleg Demchenko 2015-10-27 18:21:07 UTC
I followed Brendan's advice from comment #6(run btouch with --process-enums options) and  resulting file Foo.g.cs contains expected definition of enum:

public enum Foo : uint {

instead of

public enum Foo : System.UInt32 {
Comment 11 Udham Singh 2015-10-28 10:23:09 UTC
I have checked this issue with latest iOS 9.1 + C5SR5 builds with the help of instructions provided in comment 8 and observed that this issue has been fixed now. Hence I am closing this issue.

Screencast (Windows) : http://www.screencast.com/t/FXE7prEq7jgv
Environment Info (Windows) : https://gist.github.com/Asimk360/3e994621035822237bee

Screencast (Mac) : http://www.screencast.com/t/yIfaE8LvOpX
Environment Info (Mac) : https://gist.github.com/Asimk360/314ce9a61d4509dbdffc

Thanks!