BUG: Microsoft IntelliSense cannot list properties that only have one accessor in an interface (814742)
The information in this article applies to:
- Microsoft Visual C# .NET (2003)
SYMPTOMSIn Microsoft Visual C# .NET 2003, when you type a period (".") after
the name of a variable, Microsoft IntelliSense may not list properties of the corresponding class. Instead,
IntelliSense may list the get_PropertyName and the set_PropertyName methods, where PropertyName is a
property of your class. Additionally, if your class
is a control, and if you add this control to a form or to a user control, you may
notice one or more design-time errors in the Task List window that are similar to the following: Operation is not
valid due to the current state of the object.
At least one element in
the source array could not be cast down to the destination array
type.
Type 'MyClass' does not have a constructor with parameters of
types String.
Object type cannot be converted to target
type. Note This bug does not appear in Microsoft Visual Studio .NET
2002. CAUSEIf a property in an interface has only one accessor
that is declared, and if your class implements the interface, you may implement the get accessor and the set accessor. Then you build your class, you add a project reference
from another project to the built assembly, and then you declare a variable that has your class as the data type. When you type the name of the declared variable
and then type a period, IntelliSense incorrectly imports your property. Therefore,
IntelliSense does not list your property and only lists methods that correspond to the get_PropertyName method and the set_PropertyName method that is mentioned in the "Symptoms" section of this article. Additionally, you may
notice errors similar to the errors in the "Symptoms" section of this article because of a
special case where objects are replaced by their names. Note- This bug and the related errors are noticed only at design time. Even though this bug exists, you may build and may run your projects as expected.
- You notice this bug only if you add a project reference to
your class from another project. If you use your class in the same project as
the class file, you do not notice the behavior that is mentioned in the "Symptoms"
section of this article.
WORKAROUNDTo work around this bug, you may modify your class, you may
modify your interface, or you may ignore the bug. Microsoft recommends that you
modify your class so that your class implements only the accessor that is
declared in your interface. Modify Your ClassModify your class so that your class implements only
the accessor that is declared in your interface. To do this, follow these steps for the sample that is created in the "Steps to Reproduce This Behavior" section of this article: - Press ESC to ignore the IntelliSense
list that is displayed when you type
MyReference..
- Press BACKSPACE to delete the period (".")
that you typed in step 13 of the "Steps to Reproduce This Behavior" section of this article.
- Switch to ClassLibrary1, and then open Class1.cs.
- Locate and then delete the following code:
set
{
MyInt = value;
} - On the Build menu, click Build
ClassLibrary1.
- Switch to ConsoleApplication1.
- In Solution Explorer, expand
References.
- Right-click ClassLibrary1, and then click
Remove.
- On the Project menu, click Add
Reference.
- In the Add Reference dialog box, click
Browse.
- Locate and select the ClassLibrary1.dll file that
you built in step 5, and then click Open.
- In the Add Reference dialog box, click OK. This adds a project reference to ClassLibrary1.dll to ConsoleApplication1.
- In Class1.cs, type . where you
pressed BACKSPACE in step 2. The IntelliSense
list is displayed together with MyProperty.
Note These steps are based on the sample from the "Steps to Reproduce the Behavior" section of this article. Therefore, the code and the file names in these steps
may differ from your code and your file names. Modify Your InterfaceModify your interface so that your interface declares
both accessors for your property. To do this, follow these steps for
the sample that is in the "Steps to Reproduce This Behavior" section of this article:
- Press ESC to ignore the IntelliSense
list that is displayed when you type
MyReference.
- Press BACKSPACE to delete the period (".")
that you typed in step 13 of the "Steps the Reproduce This Behavior" section of this article.
- Switch to ClassLibrary1, and then open Class1.cs.
- Locate the following code:
get; - Add the following code to Class1.cs, after the code that
you located in step 4:
set; - On the Build menu, click Build
ClassLibrary1.
- Switch to ConsoleApplication1.
- In Solution Explorer, expand
References.
- Right-click ClassLibrary1, and then click
Remove.
- On the Project menu, click Add
Reference.
- In the Add Reference dialog box, click
Browse.
- Locate and select the ClassLibrary1.dll file that
you built in step 6, and then click Open.
- In the Add Reference dialog box, click OK. This adds a project reference to ClassLibrary1.dll to ConsoleApplication1.
- In Class1.cs, type . where you
pressed BACKSPACE in step 2. The IntelliSense
list is displayed together with MyProperty.
Note These steps are based on the sample from the "Steps to Reproduce This Behavior" section of this article. Therefore, the code and the file names in these steps
may differ from your code and your file names. Ignore the BugYou notice this bug only at design time. Therefore, you
may ignore the bug and then build and run your application as
expected. To do this, follow these steps for the sample in the "Steps to Reproduce This Behavior" section of this article:
- Press ESC to ignore the IntelliSense
list that is displayed when you type
MyReference..
- Type MyProperty.
You may
then use MyReference.MyProperty in your project. Note These steps are based on the sample from the "Steps to Reproduce This Behavior"
section of this article. Therefore, the code and the file names in these steps
may differ from your code and your file names. STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are
listed at the beginning of this article.
REFERENCESFor more information, visit the following Microsoft
Developer Network (MSDN) Web sites:
Modification Type: | Minor | Last Reviewed: | 1/13/2006 |
---|
Keywords: | kbpending kbConsole kbIDEProject kbDevStudio kbProperties kbide kbProgramming kbbug KB814742 kbAudDeveloper |
---|
|