Bug 4527 - Cannot watch instance field inside iterator
Summary: Cannot watch instance field inside iterator
Status: RESOLVED FIXED
Alias: None
Product: Xamarin Studio
Classification: Desktop
Component: Debugger ()
Version: unspecified
Hardware: PC Linux
: --- normal
Target Milestone: ---
Assignee: Jeffrey Stedfast
URL:
Depends on:
Blocks:
 
Reported: 2012-04-19 13:39 UTC by Marek Safar
Modified: 2012-05-01 18:07 UTC (History)
3 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 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 Marek Safar 2012-04-19 13:39:52 UTC
using System;
using System.Collections.Generic;

class C
{
	string ss = "aa";
	
	public IEnumerable<int> GetIter ()
	{
		yield return 1;
		yield return 2; // Set a breakpoint here
		yield return 3;
	}

    public static void Main()
    {
		foreach (var item in new C ().GetIter ()) {
			
		}
    }
}

Then go to watch window and add `ss'. Error Unknown identifier: ss
Comment 1 Jeffrey Stedfast 2012-04-20 17:15:15 UTC
if you add Console.WriteLine (ss); to the top of GetIter(), it works.

This suggests to me that it's a runtime or compiler issue.
Comment 2 Mikayla Hutchinson [MSFT] 2012-04-23 08:15:04 UTC
I would guess that mcs isn't emitting a "this" reference on the closure class. It should always do that for debug code, even if it isn't used.
Comment 3 Marek Safar 2012-04-23 10:40:07 UTC
Good point Michael. Although I don't think it's worth always adding `this' reference, because it can significantly alter generated code and you will still have to handle cases which don't follow this assumption.

VS prints "An object reference is required for the non-static field, method, or property 'C.ss'" when the `this' proxy is not available. We could probably show better error message but I'd go with an error message instead of adding `this' everywhere (it's quite tricky for anonymous methods).
Comment 4 Jeffrey Stedfast 2012-04-23 14:25:17 UTC
the error message is fixed in git master
Comment 5 Mikayla Hutchinson [MSFT] 2012-04-23 18:58:41 UTC
IIRC csc always generates the "this" reference for debug code, but I could be wrong.
Comment 6 Marek Safar 2012-04-24 03:16:50 UTC
Yes but only for iterators not for other kinds of lifted blocks like anonymous methods or async blocks
Comment 7 Marek Safar 2012-04-24 05:53:02 UTC
MD now prints the message even if the name does not exist at all
Comment 8 Jeffrey Stedfast 2012-05-01 18:07:53 UTC
fixed