How to prebuild C# generics before runtime

vb 286 Reputation points
2021-01-14T14:45:11.157+00:00

Hi,

Currently, C# generics are built at runtime. First time, generics execution is very slow because runtime compilation.

How to avoid runtime compilation...how to get target x64 or x86 binaries where generics are already compiled to native binary.

Is there LINK option for that I am missing?

Thanks in advance!
Vladimir

Developer technologies .NET .NET Runtime
Developer technologies Visual Studio Other
Community Center Not monitored
Developer technologies .NET .NET CLI
Developer technologies C#
0 comments No comments
{count} votes

Accepted answer
  1. Alberto Poblacion 1,571 Reputation points
    2021-01-14T14:50:48.283+00:00

    If I understand correctly, you want to bypass the JIT-compiler (Just In Time). For classical .Net Framework, you have a tool called NGEN.EXE (Native Image GENerator), which can take your IL files and turn them into executable binaries. Note that this is unrelated to whether you use Generics or not; the JIT and NGEN apply to any code with or without Generics.

    Link to documentation.

    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. vb 286 Reputation points
    2021-01-14T15:33:41.067+00:00

    So, you want to say there is no LINK/BUILD option in Visual Studio that can build native image?

    Only NGEN.exe that you must call from script or manually from cmd?


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.