Closed wliao008 closed 11 years ago
I think the problem is with boxing and unboxing of the returned type. If I changed the aspect to return -1.0 everything works fine.
It seems this is the expected behavior, we can only unbox a value type to its original type (and the nullable version of that type)
int i = 1;
object o = i;
double d = (double)o; // <--- this will cause InvalidCastException
Console.WriteLine("d: " + d);
Console.WriteLine("Done");
Console.Read();
check stackoverflow post at http://stackoverflow.com/q/1085097/150607
Example program:
The Around aspect:
Generated MSIL:
The program compiles fine and MSIL displays ok, but when execute the modified program, the following error occurred:
Unhandled Exception: System.InvalidCastException: Specified cast is not valid. at client.TraceAspectTester.divide634878808119716310(Int32 a, Int32 b) at client.Program.Main(String[] args)