System.Math.Abs() calls into native method System.AppDomain.GetId()?

喜夏-厌秋 提交于 2019-12-01 16:56:47

First, you need to know that the debugger evaluate can't call native method. (well its depend if it real func eval or not, but even when its not real func eval we will see that its not completely true but wait...)

How does it only work some of the time? Is there runtime trickery happening where the conditional breakpoint code isn't the same each time I run it?

Yes it's strange but it could be. The debugger evaluator actually able to get the app domain id, but sometimes some error occurred and then you will get that exception.

If there was, why on earth would any version of the code for Abs() call AppDomain.GetId() - it's purely arithmetic surely?

I pretty sure that this call not relating just to Math.Abs.

The .NET reference source shows a method extern public static double Abs(double). Doesn't that mean it's always native anyway? How could it ever work?

Because for some of the native methods, the debugger evaluator has hooks that handle it in a special way. Math.Abs is one of them.


I tried to reproduce it in my Visual Studio but without success. (VS 2017)

Try to evaluate the same expression in Watch Window (with suffix of ,nse) and tell me if you still get the exception.

Just to show you an example of trying evaluate a method that call to native code: (read the error message)

One more thing, try to evaluate it in other version of Visual Studio.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!