Bug 17232 - Invalid class name generated in the Libraries.g.cs file.
Summary: Invalid class name generated in the Libraries.g.cs file.
Status: RESOLVED FIXED
Alias: None
Product: iOS
Classification: Xamarin
Component: Pre-release ()
Version: 7.1.0.x
Hardware: Macintosh Mac OS
: Normal normal
Target Milestone: Untriaged
Assignee: Alex Soto [MSFT]
URL:
Depends on:
Blocks:
 
Reported: 2014-01-14 16:33 UTC by shuklaa
Modified: 2016-05-05 18:33 UTC (History)
4 users (show)

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


Attachments
Test project showing the bug (94.51 KB, application/zip)
2014-06-09 20:12 UTC, Daniel Tavares
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:
RESOLVED FIXED

Description shuklaa 2014-01-14 16:33:08 UTC
Steps to Reproduce:
1. On the Xamarin alpha channel, create a binding project.
2. In my case the name of the project was xf.Beacons.
3. Import the native library and populate the ApiDefinitions.cs file till all APIs are bounded.
4. Build Debug or Build Release. Same error.


Got this error:
namespace MonoTouch {
	[CompilerGenerated]
	static class Libraries {
		static public class xf.Beacons {
			static public readonly IntPtr Handle = Dlfcn.dlopen (Constants.xf.BeaconsLibrary, 0);
		}
	}
}

Debug/ios/ObjCRuntime/Libraries.g.cs(25,25): Error CS1519: Unexpected symbol `.' in class, struct, or interface member declaration (CS1519) (xf.Beacons)

Any ideas?
Comment 1 shuklaa 2014-01-16 16:34:22 UTC
Ok I think this needs to be escalated. May be I'm doing something wrong or the library that was supplied has issue or it is an issue with Xamarnin.
I'm attaching the project.
Comment 3 Daniel Tavares 2014-06-06 13:40:18 UTC
I'm having the exact same problem while binding an Objective-C library. Did you ever figure out a solution?
Comment 4 shuklaa 2014-06-06 22:13:55 UTC
Have not seen this for a long time.
Comment 5 Daniel Tavares 2014-06-09 20:12:45 UTC
Created attachment 7024 [details]
Test project showing the bug

The problem is caused when binding a static library and not using "_Internal" as the "libraryName" when flagging a property with the Field attribute.

In my case I had something like this:

ObjC:

@implementation TestLibrary

NSString * const TheString = @"A String";

@end

C#:
namespace InvalidClassTest.Foo.Bar
{
    [BaseType (typeof(NSObject))]
    public partial interface TestLibrary {
        [Field ("TheString")]
        NSString TherStringTest { get; }
    }
}

Adding "__Internal" to the Field attribute as mentioned on the FieldAttribute section[1] of the bindings reference guide fixed the problem.

...
[Field ("TheString", "__Internal")]
...

Another side effect of not setting libraryName to "__Internal" is mentioned on this SO[2] thread.


Steps to reproduce:

1. Unzip the attachment and go into its directory via terminal
2. make

Result:

Build fails with the following error:

...
lipo -create -output libTestLibrary.a libTestLibrary-i386.a libTestLibrary-armv7.a
/Developer/MonoTouch/usr/bin/btouch ApiDefinition.cs StructsAndEnums.cs libTestLibrary.linkwith.cs --out=TestLibrary.dll --link-with=libTestLibrary.a,libTestLibrary.a
ObjCRuntime/Libraries.g.cs(35,39): error CS1519: Unexpected symbol `.' in class, struct, or interface member declaration
ObjCRuntime/Libraries.g.cs(35,48): error CS1519: Unexpected symbol `{' in class, struct, or interface member declaration
ObjCRuntime/Libraries.g.cs(39,0): error CS1525: Unexpected symbol `}'
Compilation failed: 3 error(s), 0 warnings
btouch: API binding contains errors.
make: *** [TestLibrary.dll] Error 1

Expected Result:

Build should fail with a more descriptive error about the actual problem, instead of complaining about unrelated symbols.


This is what I had installed on my machine at the time I reproduced the bug:

Xamarin Studio 4.2.3
Runtime:
	Mono 3.2.6 ((no/9b58377)
	GTK+ 2.24.23 theme: Raleigh
	GTK# (2.12.0.0)
	Package version: 302060000
Xamarin iOS 7.2.1.42 (Business Edition)
Mac OS X 10.9.3
Xcode 5.1.1 (5085)


[1] http://developer.xamarin.com/guides/ios/advanced_topics/binding_objective-c/binding_types_reference_guide/
[2] http://stackoverflow.com/questions/16952194/monotouch-binding-project-build-errors
Comment 6 Sebastien Pouliot 2016-03-09 14:54:02 UTC
The original description and comment #5 sounds like different issues. @Alex can you check both case and see if the issue still exists in master ? thanks!