We have our own tool to create documentation of our web api. It reads the ///
comments and creates the documentation from them. But we have one weird issue with it: The expression typeof(HttpResponseMessage)
weirdly evaluates to null
. Why this happens?
Just to clarify: When we read the assemblies at runtime and create documenation, we have HttpResponseMessage
in MethodInfo.ReturnType
of some API methods. This one works without problem. But when we try to check if the type is HttpResponseMessage
, we do if(methodInfo.ReturnType == typeof(HttpResponseMessage)
and here the right side of this if always evaluates to null
. When I run it in Visual Studio debugger and write typeof(HttpResponseMessage)
to Watch window, it evaluates to null
too.
(The type is defined in System.Net.Http
.)
Here is the screenshot from debugger showing that this is real:
The sceenshot clearly shows that typeof returns null both in program and in Watch window, but parameterType variable actually points to the type object of that class. It is a normal Win32 console application.