Saturday, February 23, 2008

Type Spoofing and CLR

 

Type spoofing is the cause of many security breaches and
compromises an application's stability and robustness. Type safety is therefore an extremely
important part of the CLR.

 

CLR checks the type security at runtime

Casting Object to a specific type will compile all fine, but at run time an exception 'InvalidCastException' is thrown if the type boxed in Object cannot be converted to the specific type ( i.e is not of the specific type or its base type )

Use As Over Is : using Is and then casting results in type checking twice. Once for Is and then while casting the CLR does the default type check. To avoid this use the As operator.

No comments: