Bug 15832 - Using variable can be modified on mono, but cannot in .NET
Summary: Using variable can be modified on mono, but cannot in .NET
Status: RESOLVED FIXED
Alias: None
Product: Compilers
Classification: Mono
Component: C# ()
Version: 3.2.x
Hardware: PC All
: --- normal
Target Milestone: ---
Assignee: Marek Safar
URL:
Depends on:
Blocks:
 
Reported: 2013-10-30 16:38 UTC by ssundermann
Modified: 2013-11-14 12:22 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 ssundermann 2013-10-30 16:38:29 UTC
This compiles with mono:

using (GLib.Value v = new GLib.Value((GLib.GType)value.GetType())) {
    v.Val = value;
    SetProperty(property, v);
}

but gives a compile error in .NET saying that v is using variable and thus the associated variables cannot be modified.
Comment 1 Marek Safar 2013-11-14 03:51:04 UTC
I cannot reproduce it with 3.2.3.

My full sample is

using System;

struct D : IDisposable
{
    public int Val;

    public void Dispose ()
    {
        throw new NotImplementedException ();
    }
}

class X
{
    public static void Main ()
    {
        int value = 0;
        using (var v = new D ()) {
            v.Val = value;
        }
    }
}

Can  you provide complete code sample which reproduces the issue?


}
Comment 2 Andres G. Aragoneses 2013-11-14 08:12:52 UTC
I think the key thing here is using a property:

	struct Foo : IDisposable
	{
		public object Property
		{
			set { }
		}
		public void Dispose()
		{
		}
	}

	class Bar
	{
		static void Baz()
		{
			using (var f = new Foo())
			{
				f.Property = null;
			}
		}
	}
Comment 3 Marek Safar 2013-11-14 12:22:02 UTC
Fixed in master