0

I've seen some code marked with MethodImplOptions.InternalCall

From the documentation, it is said that such a method is a "method is implemented within the common language runtime itself".

I'd like to know what is the usage of marking a method as an Internal Call ?

Can't such a method be implemented in the .NET library itself? or as a native method that can be invoked using the standard techniques? (e.g: Pinvoke)

Another question question dealt with "why not implement the same as a CIL instruction": What's the point of MethodImplOptions.InternalCall?

which answered only why it's better off to not introduce new CIL instructions, but doesn't fully answer what i'm after.

Also, can internal implementations be created in non-CLR code? (e.g: native app that hosts the CLR?)

Community
  • 1
  • 1
lysergic-acid
  • 19,570
  • 21
  • 109
  • 218

1 Answers1

1

As it is mentioned in the link you shared MethodImplOptions.InternalCall is used along MethodImplAttribute

[MethodImpl(MethodImplOptions.InternalCall)]

MethodImpl is what is known as a pseudo-attribute these type of attributes has an special treatment and are not store as part of the metadata for the type but instead they are use to set values values in the metadata tables. Another attribute with a similar behaviour is the SerializableAttribute. MethodImplAttribute receives MethodImplOptions as parameter to configure the method implementation. MethodImplOptions.InternalCall is normally used with code associated with unmanaged code.

You can find additional information here:

http://msdn.microsoft.com/en-us/magazine/cc163896.aspx

Dalorzo
  • 19,834
  • 7
  • 55
  • 102
  • I have seen 3rd party code that uses InternalCall. How does the runtime locate the implementation? In tgat case the implementation is not in the CLR. – lysergic-acid Dec 27 '13 at 14:57
  • I do not understand. Can you refer in terms if manage and unmanage code ? It is really what we are talking about, isn't it? – Dalorzo Dec 27 '13 at 15:04
  • In Unity3d (a game engine), some managed methods are marked as intetnal calls. How are these implemented? And how is the implementation located? – lysergic-acid Dec 28 '13 at 15:56
  • @lysergic-acid, Unity uses Mono's CLR runtime directly, which is open-source. This means that you have the power to abuse CLR the way you wish, but you nust also know C/C++ extremely well and know CLR times more than an average C# programmer. Check this article, however, you will have to dig a lot more in Mono's sources. About your answer - they are implemented into the game EXE and the Unity EXE / Unty Standalone player. Also, Check this: http://www.mono-project.com/docs/advanced/embedding/ – Петър Петров Jan 27 '17 at 22:59