How does MethodImplAttribute work in .NET?

I studied some framework code (the System.AppDomain.GetDynamicDir method), and this was shown by the whole assembler:

[MethodImpl(MethodImplOptions.InternalCall)] private extern string GetDynamicDir(); 

What happens when this method is called? I do not mean this particular method, but methods with this attribute as a whole.

+7
attributes disassembly
source share
2 answers

From MSDN :

MethodImplOptions.InternalCall : indicates an internal call. An internal call is a call to a method that is implemented as part of the execution language itself.

Basically, the CLR provides its own implementation of this method (which is probably in its own code), so you cannot see it in the disassembler.

+10
source share

The answer is here :

(...) MethodImplOptions.InternalCall used in combination with external text runtime, which is implemented within the system itself. This is done for many basic .NET. Framework methods that are better executed in unmanaged code. For example, many of the methods on String , GC and Math classes are marked as InternalCall . As you noticed, Guid.CompleteGuid also an InternalCall .

+6
source share

All Articles