Bug 31772 - Invalid C# caused no build errors or warnings
Summary: Invalid C# caused no build errors or warnings
Status: RESOLVED FEATURE
Alias: None
Product: Compilers
Classification: Mono
Component: C# ()
Version: unspecified
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: ---
Assignee: Marek Safar
URL:
Depends on:
Blocks:
 
Reported: 2015-07-08 20:29 UTC by Paul Young
Modified: 2015-07-24 09:59 UTC (History)
1 user (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 GitHub or 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 FEATURE

Description Paul Young 2015-07-08 20:29:37 UTC
I was receiving System.MissingMethodException when running unit tests against a C# PCL project which had no issues building in Xamarin Studio 5.9.4 (build 5)

I opened the same solution in Visual Studio to find that it wouldn't build without fixing some issues. Afterwards, the tests ran without issue.

Please find a diff of the changes necessary below:

- IApi Api { get; }
+ IApi Api { get; set; }

- public Token(string Username, string Value)
+ public Token(string Username, string Value) : this()

- public User(string AvatarUrl, string EmailAddress, string Id, string Name)
+ public User(string AvatarUrl, string EmailAddress, string Id, string Name) : this()
Comment 1 Marek Safar 2015-07-09 15:27:04 UTC
This is not very actionable report.

Could you provide steps how to reproduce the issue, including error message(s) you got when compiled using VS?
Comment 2 Paul Young 2015-07-10 08:21:42 UTC
I will try to create a stand-alone test project that reproduces the issues.

Error messages from Visual Studio are below (some information removed).


Regarding the missing setter definition:

- 'ApiClient.Api.get' must declare a body because it is not marked abstract or extern. Automatically implemented properties must define both get and set accessors.

- Property or indexer 'ApiClient.Api' cannot be assigned to -- it is read only


Regarding the missing default constructor calls:

- Backing field for automatically implemented property 'User.Name' must be fully assigned before control is returned to the caller. Consider calling the default constructor from a constructor initializer.

- Backing field for automatically implemented property 'User.Id' must be fully assigned before control is returned to the caller. Consider calling the default constructor from a constructor initializer.

- Backing field for automatically implemented property 'User.EmailAddress' must be fully assigned before control is returned to the caller. Consider calling the default constructor from a constructor initializer.

- Backing field for automatically implemented property 'User.AvatarUrl' must be fully assigned before control is returned to the caller. Consider calling the default constructor from a constructor initializer.

- Backing field for automatically implemented property 'Token.Value' must be fully assigned before control is returned to the caller. Consider calling the default constructor from a constructor initializer.

- Backing field for automatically implemented property 'Token.Username' must be fully assigned before control is returned to the caller. Consider calling the default constructor from a constructor initializer.

- The 'this' object cannot be used before all of its fields are assigned to

- The 'this' object cannot be used before all of its fields are assigned to
Comment 3 Paul Young 2015-07-13 12:33:14 UTC
An example project can be found at https://github.com/paulyoung/Bug31772
Comment 4 Marek Safar 2015-07-24 09:13:37 UTC
Mono C# compiler defaults to C#6 where Visual Studio Community 2013 still uses C#5. Switching to newer version of VS will allow you to use same feature in VS too.
Comment 5 Paul Young 2015-07-24 09:47:33 UTC
I'm not sure I understand.

It seems like the Mono compiler should have reported those same errors, and it was only after I made the changes suggested by the Visual Studio compiler that things worked in Xamarin Studio.

I'll try the example project in Visual Studio Community 2015 and see if I receive any error messages, but not sure how that is relevant to Xamarin Studio so I don't think this issue is resolved.
Comment 6 Marek Safar 2015-07-24 09:59:27 UTC
The syntax is allowed in C#6 but it was error in C#5. Going from C#5 -> C#6 (VS2k8 -> XS) is ok, going the other way will likely cause issue like in your case.