Skip to content

Why are generics not supported with PInvoke #46204

Discussion options

You must be logged in to vote

@Dewera Great question. There are a few ways to answer this, let me offer you some.

  1. A P/Invoke is designed to represent a C export and exposing them as a Generic function would be kind of confusing given C has no concept of Generics.
  2. The P/Invoke system was written at a time, .NET 1.0, when Generics didn't exist. When Generics were added in .NET 2.0, it just wasn't done.
  3. The P/Invoke system as it currently exists only supports a single associated IL Stub.

Is there a technical limitation to supporting this? I can't honestly think of one in the current dynamic IL Stub system - (3) is the biggest and then of course efficiently determining which IL Stub to use. It would require a non-trivia…

Replies: 4 comments 4 replies

Comment options

You must be logged in to vote
3 replies
@acaly
Comment options

@Dewera
Comment options

@acaly
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@am11
Comment options

Answer selected by danmoseley
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
5 participants