Friday, December 5, 2008

Error CS0117: '<MyClass>' does not contain a definition for 'Profile'

I discovered another bad idea: creating a member variable named 'Context' in a web page class (or any class that inherits System.Web.UI.Control). I happened to make this mistake in a MasterPage class.

If you do, you should receive a love letter or two from the compiler much like mine:
'MyNamespace.MyClass' does not contain a definition for 'Profile'
...and/or:
'MyNamespace.MyClass' does not contain a definition for 'ApplicationInstance'.

You'll also find this warning:
'MyPageClass.Context' hides inherited member 'System.Web.UI.Control.Context'. To make the current member override that implementation, add the override keyword. Otherwise add the new keyword.

Here's the list of other member names you may only envy when building classes that inherit the Control class:
http://msdn.microsoft.com/en-us/library/system.web.ui.control_members.aspx

1 comment:

Unknown said...

Gaaaaaaarrrrr!
Been wresting this for a couple hours, thought I was loosing my mind. In my case I had a base class for some common pages that exposed a property named 'Context'. The project built fine so something smelled fishy when this error came up. I renamed this property to DataContext and all is well. Thank You Thank You you saved me so much headache. Who woulda thunk Context was a bad word. And by the way, how rude of someone to go around calling Context no anything it can find!