473,763 Members | 4,808 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Mismatched behaviour between regular compiler and refactoringcomp iler

The included program compiles without errors, but produces an error
when you attempt to use a refactoring tool:

J:\TypeofTest\T ypeofTest1\Prog ram.cs(3,27): error CS0246: The type or
namespace name 'Bar' could not be found (are you missing a using
directive or an assembly reference?)

In addition, the syntax highlighter doesn't highlight the "Bar" in
"typeof(Bar )" as a class. If I replace that with "typeof(Foo.Bar )",
everything works as expected. What I don't understand is why there is
a difference. Should it be possible to implicitly reference an inner
class in an attribute like this (in which case it seems the
refactoring compiler is incorrect) or is it in fact not allowed (in
which case surely the regular compiler should say something)? I'm
using Visual Studio 2005.

using System.Diagnost ics;

[DebuggerTypePro xy(typeof(Bar))]
public class Foo
{
public class Bar
{
private Foo m_foo;
public Bar(Foo foo) { m_foo = foo; }
}
}

class Program
{
static void Main() { }
}
Jun 27 '08 #1
10 1282
I've found a further problem. In the code that this example is derived
from, the equivalent to Bar is a private class. In that case, when I
change "typeof(Bar )" to "typeof(Foo.Bar )", I get a new error (again,
only from the refactoring compiler, not the regular one):

J:\TypeofTest\T ypeofTest1\Prog ram.cs(3,31): error CS0122: 'Foo.Bar' is
inaccessible due to its protection level

It seems it comes down to a question of whether or not the expression
for attribute constructors are evaluated inside or outside the scope
of the class. I should note that I'm using a private inner class in
large part because of this example here:

http://msdn2.microsoft.com/en-us/library/x810d419.aspx

Even so, I think it's cleaner to use a private inner class rather than
an internal top-level class, because there's really no need to make
the debug stuff visible to any other code.

On Apr 29, 11:44 am, Weeble <clockworksa... @gmail.comwrote :
The included program compiles without errors, but produces an error
when you attempt to use a refactoring tool:

J:\TypeofTest\T ypeofTest1\Prog ram.cs(3,27): error CS0246: The type or
namespace name 'Bar' could not be found (are you missing a using
directive or an assembly reference?)

In addition, the syntax highlighter doesn't highlight the "Bar" in
"typeof(Bar )" as a class. If I replace that with "typeof(Foo.Bar )",
everything works as expected. What I don't understand is why there is
a difference. Should it be possible to implicitly reference an inner
class in an attribute like this (in which case it seems the
refactoring compiler is incorrect) or is it in fact not allowed (in
which case surely the regular compiler should say something)? I'm
using Visual Studio 2005.

using System.Diagnost ics;

[DebuggerTypePro xy(typeof(Bar))]
public class Foo
{
public class Bar
{
private Foo m_foo;
public Bar(Foo foo) { m_foo = foo; }
}

}

class Program
{
static void Main() { }

}
Jun 27 '08 #2
but produces an error
when you attempt to use a refactoring tool:
Which refactoring tool? The code is fine "as is" for regular C#...

Marc
Jun 27 '08 #3
On Apr 29, 12:45 pm, Marc Gravell <marc.grav...@g mail.comwrote:
but produces an error
when you attempt to use a refactoring tool:

Which refactoring tool? The code is fine "as is" for regular C#...

Marc
Any of the built-in refactoring tools in Visual Studio 2005 seem to do
it for me. For example, right-click on "Program" (or any other
identifier) and choose "Refactor->Rename..." The output window will
switch to "Show output from: Refactor" and the error I described will
appear in it. The other symptom is the syntax highlighting, as I said.
If I have "typeof(Bar )" then "Bar" will appear black, whereas if I
have "typeof(Foo.Bar )", the "Foo.Bar" will appear teal, the colour
that indicates the name of a class.

I do have Visual Assist X installed, but I disabled it for these tests.
Jun 27 '08 #4
Verified (in VS2008) - interesting! But (in VS2008, at least) it is
purely cosmetic - the refactor still completes successfully (you just
get a yellow-triangle warning that it isn't happy, but once complete
it compiles fine; and so I couldn't say it is super-critical, unless
it actually stops VS2005 from completing the refactor [does it?]) .

I would suggest logging it via connect... http://connect.microsoft.com/VisualStudio
(if you do log it, post the url and I'll mark it as validated; or if
you don't already have a passport, I could log it on your behalf if
you like - but I won't do so without your nod).

Marc
Jun 27 '08 #5
On Apr 29, 1:56 pm, Marc Gravell <marc.grav...@g mail.comwrote:
I would suggest logging it via connect...http://connect.microsoft.com/VisualStudio
(if you do log it, post the url and I'll mark it as validated; or if
you don't already have a passport, I could log it on your behalf if
you like - but I won't do so without your nod).
Yikes, that was an ordeal to get set up. I've submitted the bug here
(I think):
https://connect.microsoft.com/Visual...dbackID=340962
Jun 27 '08 #6
On Apr 29, 3:24 pm, Weeble <clockworksa... @gmail.comwrote :
On Apr 29, 1:56 pm, Marc Gravell <marc.grav...@g mail.comwrote:
I would suggest logging it via connect...http://connect.microsoft.com/VisualStudio
(if you do log it, post the url and I'll mark it as validated; or if
you don't already have a passport, I could log it on your behalf if
you like - but I won't do so without your nod).

Yikes, that was an ordeal to get set up. I've submitted the bug here
(I think):https://connect.microsoft.com/Visual...wFeedback.aspx...
It got resolved "Won't Fix". Does that mean never? Seems a bit
disappointing. I tried to figure out which behaviour is correct, and
the best I could understand from the spec is that the refactoring
engine is correct and the regular compiler is wrong on the basis that
class members are only in scope inside the "class body", which
comprises everything between the curly braces, but not the attribute
specifiers. To be honest, that's not the behaviour I'd want, but I
couldn't see anything in there that would make me believe that either
attribute specifiers count as being in the class body, or that class
members are in scope anywhere except the class body or the class body
of a descendent class.

My workaround is to implement DebuggerTypePro xy classes as inner
classes with internal instead of private access, and to use fully
qualified names when constructing the attributes. That way both the
refactoring engine and the regular compiler seem happy. I wouldn't
like the refactoring engine to be spitting out lots of errors whenever
a colleague attempts to use it, even if I know it shouldn't actually
prevent it from working.
Jun 27 '08 #7
I'd need to look closely at the spec to figure which behavior is
correct; I would presume the regular compiler, but it could go either
way... however, I can see their view that it isn't eactly critical
(purely cosmetic, and purely during refactoring). But yes: sometimes
it can be frustrating when you see "won't fix"; I've had "won't fix"
with critical runtime issues in things like WSE, and even something as
simple (yet commonplace) as the runtime not being able to sort strings
correctly [genuinely!]. But sometimes things do get fixed... oh well.

Marc
Jun 27 '08 #8
On May 2, 10:37 am, Marc Gravell <marc.grav...@g mail.comwrote:
I'd need to look closely at the spec to figure which behavior is
correct; I would presume the regular compiler, but it could go either
way... however, I can see their view that it isn't eactly critical
(purely cosmetic, and purely during refactoring). But yes: sometimes
it can be frustrating when you see "won't fix"; I've had "won't fix"
with critical runtime issues in things like WSE, and even something as
simple (yet commonplace) as the runtime not being able to sort strings
correctly [genuinely!]. But sometimes things do get fixed... oh well.
A few hours later there was a comment explaining the reasoning. I
totally understand that it's not worth going to the bother of changing
the refactoring engine in 2005 or 2008 for something quite minor. I
am, however, worried by the idea that the problem could be in the
regular compiler. To me, that would be quite serious. I'm hoping that
someone who understands the spec better than I do might explain it to
me.

As I understand it, based on the C# Spec V3, the "scope" of a class
member (i.e. the places it can be used without "Class.Memb er"
qualification) is the "class-body" of that class and of any
subclasses. (§3.7) The "accessibil ity domain" of a private class
member (i.e. the places it can be accessed from at all) are the
"program text" of the class, which is itself defined as the "class-
body". (§3.5.2) The "class-body" is defined as being everything
between the { curly braces } of the class, which does not include
attribute specifiers.

I sure do hope my interpretation is wrong!
Jun 27 '08 #9
On May 2, 1:55 pm, Weeble <clockworksa... @gmail.comwrote :

<snip>
As I understand it, based on the C# Spec V3, the "scope" of a class
member (i.e. the places it can be used without "Class.Memb er"
qualification) is the "class-body" of that class and of any
subclasses. (§3.7) The "accessibil ity domain" of a private class
member (i.e. the places it can be accessed from at all) are the
"program text" of the class, which is itself defined as the "class-
body". (§3.5.2) The "class-body" is defined as being everything
between the { curly braces } of the class, which does not include
attribute specifiers.

I sure do hope my interpretation is wrong!
Well, your logic certainly sounds right to me. However, it could just
be another case where the bug is actually in the spec - that the
current behaviour is the designed one, but the design wasn't correctly
described in the spec. I think it's as likely that there'll be a spec
change to fix this as a compiler change (especially as fixing the spec
to mirror reality isn't a breaking change; fixing the compiler to
mirror the spec certainly would be).

Another one to ask the team, I guess...

Jon
Jun 27 '08 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2169
by: Gerhard Esterhuizen | last post by:
Hi, I am observing unexpected behaviour, in the form of a corrupted class member access, from a simple C++ program that accesses an attribute declared in a virtual base class via a chain of virtual method calls. To further complicate (or perhaps simplify) matters, some compilers (GCC and MingW) produce the expected behaviour, while others (MSVS 7.1) do not. I can only offer two explanations for my observations: 1. The Microsoft...
25
3098
by: Nitin Bhardwaj | last post by:
Well, i'm a relatively new into C( strictly speaking : well i'm a student and have been doing & studying C programming for the last 4 years).....and also a regular reader of "comp.lang.c" I don't have a copy of ANSI C89 standard,therefore i had to post this question: What is the difference between "unspecified" behaviour & "undefined" behaviour of some C Code ??
12
1808
by: RoSsIaCrIiLoIA | last post by:
On Mon, 07 Feb 2005 21:28:30 GMT, Keith Thompson <kst-u@mib.org> wrote: >"Romeo Colacitti" <wwromeo@gmail.com> writes: >> Chris Torek wrote: >>> In article <4205BD5C.6DC8@mindspring.com> >>> pete <pfiland@mindspring.com> wrote: > >>> >If you have >>> > int array; >>> >then
31
2631
by: DeltaOne | last post by:
#include<stdio.h> typedef struct test{ int i; int j; }test; main(){ test var; var.i=10; var.j=20;
62
5043
by: Argento | last post by:
I was curious at the start about how ungetc() returns the character to the stream, so i did the following coding. Things work as expected except if I change the scanf("%c",&j) to scanf("%d",&j). I don't understand how could scanf() affect the content of i and i. Can someone tell me why? #include <stdio.h> #include <ctype.h> void main() {
24
1842
by: temper3243 | last post by:
Hi, Many people have used this code in my project. It works because b is using the extra memory for other 4 variables.I access obj max. well here are a few questions 1) Where does it fail. I mean is there any exception where it willnot work assuming malloc works fine. 2) someone told me in C99 we have declar b obj , so that it can be declared at runtime. How do we do that. Do we have to malloc again .
285
8910
by: Sheth Raxit | last post by:
Machine 1 : bash-3.00$ uname -a SunOS <hostname5.10 Generic_118822-30 sun4u sparc SUNW,Sun-Fire-280R bash-3.00$ gcc -v Reading specs from /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/2.95.3/ specs gcc version 2.95.3 20010315 (release)
3
1999
by: Martin Kulov [MVP] | last post by:
Hi, I am wondering if this problem is still valid for ASP.NET 2.0. "To maintain session state across different Web servers in the Web farm, the application path of the Web site (for example, \LM\W3SVC\2) in the Microsoft Internet Information Services (IIS) metabase must be the same for all of the Web servers in the Web farm. The case also needs to be the same because the application path is case-sensitive."
11
1405
by: Pranav | last post by:
The Code is compiling without Error/Bug/Exception.., What are the possibilities for this behaviour? //*************************************************************** #include<stdio.h> typedef struct abc_ *abc; static abc param; abc fun(void)
0
9386
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10144
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9937
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7366
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6642
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5270
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5405
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3917
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2793
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.