Whole Tomato Software Forums
Whole Tomato Software Forums
Main Site | Profile | Register | Active Topics | Members | Search | FAQ
User name:
Password:
Save Password
Forgot your password?

 All Forums
 Visual Assist
 Technical Support
 Rename fails in C#
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

gbozoki
Ketchup Master

USA
70 Posts

Posted - Jan 11 2012 :  1:45:38 PM  Show Profile  Reply with Quote
The following piece of code fails when Refactor->Rename is used to rename the static class (all this code is in a single file):

using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

[assembly: AssemblyProduct ( MyInfo.Name )]
[assembly: AssemblyDescription ( MyInfo.Name )]

...

internal static class MyInfo
{
    public const string Name = "My name";
}


When the caret is placed in the MyInfo symbol and Refactor->Rename is clicked, the Rename dialog only finds the MyInfo symbol in a single place (the class definition) - other instances are ignored.

I'm using VS 2008 and C#. Here's my system info:

VA_X.dll file version 10.6.1862.0 built 2011.12.13
Licensed to:
VA X: gbozoki<removed> (1-user license) Support ends 2012.02.12
DevEnv.exe version 9.0.30729.1 Enterprise
msenv.dll version 9.0.30729.4462
Font: Courier New 13(Pixels)
Comctl32.dll version 6.0.2900.6028
Windows XP 5.1 Build 2600 Service Pack 3
2 processors (x86)
Language info: 1252, 0x409

Platform: Win32
Stable Includes:
C:\\Program Files\\Microsoft Visual Studio 9.0\\VC\\include;
C:\\Program Files\\Microsoft Visual Studio 9.0\\VC\\atlmfc\\include;
C:\\Program Files\\Microsoft SDKs\\Windows\\v6.0A\\include;
C:\\Program Files\\Microsoft SDKs\\Windows\\v6.0A\\include;

Other Includes:

Stable Source Directories:
C:\\Program Files\\Microsoft Visual Studio 9.0\\VC\\atlmfc\\src\\mfc;
C:\\Program Files\\Microsoft Visual Studio 9.0\\VC\\atlmfc\\src\\mfcm;
C:\\Program Files\\Microsoft Visual Studio 9.0\\VC\\atlmfc\\src\\atl;
C:\\Program Files\\Microsoft Visual Studio 9.0\\VC\\crt\\src;

Edit: updated the Name symbol to be a const string. The code originally posted didn't compile.

Edited by - gbozoki on Jan 11 2012 4:10:57 PM

gbozoki
Ketchup Master

USA
70 Posts

Posted - Jan 11 2012 :  1:51:03 PM  Show Profile  Reply with Quote
As a related, but secondary (and much more serious) issue: when I put the caret on the "Name" symbol inside "MyInfo" and run Rename, it picks up Name as a global symbol and suggests to replace things in completely unrelated places.

This caused me a massive loss of code yesterday when a common name that I wanted to replace got replaced in a bunch of other C++ projects in the same solution (these places had the same symbol name but were not related semantically). I had to discard a lot of code to revert all the changes from source control because I hit save all without realizing what happened.
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
18727 Posts

Posted - Jan 11 2012 :  3:48:16 PM  Show Profile  Reply with Quote
First please let me apologise for the bad Rename, this is a serious problem, and should not happen. Hopefully you did not loose to much code in the process.

So far I cannot reproduce your first problem report. I have added this code to a .cs file in VS2008, and when I use both Find References and Rename on the symbol "MyInfo" VA is finding 3 references.

If you try Find References here, how many references is VA finding? Rename uses Find References, so this is a good test, and it is not going to trigger any unwanted code changes. I am wondering if I have somehow done something wrong, or missed a step here.

I am wondering if your second problem is related, and if there is something else in your code file that is confusing our parser, thus causing this nasty problems.

zen is the art of being at one with the two'ness
Go to Top of Page

gbozoki
Ketchup Master

USA
70 Posts

Posted - Jan 11 2012 :  4:09:58 PM  Show Profile  Reply with Quote
feline,

Thanks for the reply - here's my full file (with some symbol names changed, but otherwise complete):

using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

/// <summary>
/// !!! WARNING !!!
/// 
/// This file is shared across multiple projects. Any
/// changes in this file will affect those connected
/// projects as well.
/// 
/// !!! WARNING !!!
/// </summary>

/// <summary>
/// General information about an assembly is controlled
/// through the following set of attributes. Change these
/// attribute values to modify the information associated
/// with an assembly.
/// </summary>
[assembly: AssemblyCompany ( "Company" )]
[assembly: AssemblyCopyright ( "Copyright (c)." )]

#if !SYMBOL
    [assembly: AssemblyProduct ( MyInfo.Name )]
    [assembly: AssemblyDescription ( MyInfo.Name + " descr" )]
#else
    [assembly: AssemblyProduct ( MyInfo.Name + " other" )]
    [assembly: AssemblyDescription ( MyInfo.Name + " other" )]
#endif

[assembly: AssemblyTrademark ( MyInfo.Name + " trademark" )]
[assembly: AssemblyCulture ( "" )]
[assembly: AssemblyConfiguration ( "" )]

/// <summary>
/// Version information
/// </summary>

// File version

/// <summary>
/// The following version definition section enclosed
/// by the BEGIN VERSION DEFINITION and END VERSION DEFINITION
/// markers is used by the build process to automatically
/// increment the version number of the built components.
/// Do not manually modify this section unless you know what
/// you're doing.
/// </summary>

/// [BEGIN VERSION DEFINITION]
[assembly: AssemblyFileVersion ( "1.0.0.0" )]
/// [END VERSION DEFINITION]

// Product version
[assembly: AssemblyInformationalVersion ( "1.0.0.0" )]

internal static class MyInfo
{
    public const string Name = "My name";
}


This file is linked in to many projects (the file is in a central location and .csproj files link to it). The solution has 13 projects, 7 C# and 6 C++. The total number of source files (C# & C++) is about 1500.

I can consistently reproduce both of these problems on multiple computers with the same results: the class name (MyInfo) is recognized only once and trying to replace the Name symbol brings up Name symbols all over my solution for rename. Let me know if you need my VAX settings to duplicate this problem.

PS: there was a syntax error in my first post: the Name symbol doesn't compile as a static string, it must be a const string. The Rename behavior is the same regardless.

Edited by - gbozoki on Jan 11 2012 9:36:33 PM
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
18727 Posts

Posted - Jan 12 2012 :  10:02:31 PM  Show Profile  Reply with Quote
Thank you for the extra sample code, I have now figured out the difference, and why I was not able to reproduce this problem at first. I had placed the class into a namespace. This problem only happens when the class is not inside a namespace:

case=63952

Is there a reason the class is not inside a namespace? I was under the impression that C# classes are normally, if not always placed inside a namespace.

zen is the art of being at one with the two'ness
Go to Top of Page

gbozoki
Ketchup Master

USA
70 Posts

Posted - Jan 13 2012 :  5:10:36 PM  Show Profile  Reply with Quote
Hmm, I don't know - I didn't even notice it's not inside an explicit namespace until I read your reply. I only added this class quickly to help with setting up version information over multiple projects and since it compiled, I didn't think about it much.

I'm glad you were able to reproduce it.
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
18727 Posts

Posted - Jan 13 2012 :  7:27:48 PM  Show Profile  Reply with Quote
If wrapping the class in a namespace does not cause any problems I would recommend this, as a temporary work around to reduce the risk of another bad rename breaking something.

zen is the art of being at one with the two'ness
Go to Top of Page

gbozoki
Ketchup Master

USA
70 Posts

Posted - Jan 14 2012 :  2:52:59 PM  Show Profile  Reply with Quote
Yes, I'll do that - thanks for looking into it. Fortunately, it only happened once. :)
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
© 2023 Whole Tomato Software, LLC Go To Top Of Page
Snitz Forums 2000