Bug 40088 - Call in lamda of static method with dynamic parameter fails in constructor argument
Summary: Call in lamda of static method with dynamic parameter fails in constructor ar...
Status: RESOLVED FIXED
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: 2016-04-04 21:36 UTC by Søren Bjergmark
Modified: 2016-04-11 18:41 UTC (History)
2 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 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 FIXED

Description Søren Bjergmark 2016-04-04 21:36:31 UTC
When calling a static method with a dynamic parameter in a lamda as a argument for the base class constructor the compiler gives this error on Mac OS X:
Error CS1673: Anonymous methods inside structs cannot access instance members of `this'. Consider copying `this' to a local variable outside the anonymous method and using the local instead (CS1673) (POCBugCompiler)

The following code works in Xamarin Studio and Visual Studio on Windows however not on Mac OS X. I am using version 5.10.3 (build 51 of Xamarin Studio) - no updates on stable channel. Mono is version 4.2.3.

using System;

namespace POCCompilerError
{
	public class MyClass
	{
		public class SomeBaseClass
		{
			public SomeBaseClass(Action action)
			{

			}
		}

		public class SomeInheritedClass : SomeBaseClass
		{
			public SomeInheritedClass() : base(() =>
				{
					StaticMethod(SomeRandomDynamic());
				})
			{

			}

			public static decimal StaticMethod(dynamic someDynamicArgument)
			{
				return 3m;
			}

			public static dynamic SomeRandomDynamic()
			{
				return new object();
			}
		}
	}
}

I discovered the bug in a similar call but the static method was located in the base class. If needed i would help with providing more information.
Comment 1 Marek Safar 2016-04-11 18:41:02 UTC
Fixed in master and mono 4.4