The following methods are excluded because they can't be virtual:
- static methods
- private methods
- methods in sealed classes
Maybe you're using one of the following tools:
All these tools make use of DynamicProxy. DynamicProxy allows for runtime interception of members. The one caveat is that all intercepted members must be virtual. This means that that all the above tools, to some extent, require members to be virtual:
- EF: Lazy Loading "When using POCO entity types, lazy loading is achieved by creating instances of derived proxy types and then overriding virtual properties to add the loading hook"
- Must Everything Be Virtual With NHibernate?
- RhinoMocks: Why methods need to be declared virtual
- Moq: My method needs to be virtual?
- "NMock supports mocking of classes with virtual methods"
- Ninject Important Note:Your methods/properties to be intercepted must be virtual!
- NSubstitute:Some operations on non virtual members should throw an exception
When a member is not virtual these tools will not work and fail in sometimes very unhelpful ways. So rather than having to remember to use the virtual keyword, Virtuosity means members will be virtual by default.
You may also just prefer to work with all methods virtual by default, as in Java.