How to prebuild C# generics before runtime

vb 276 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

Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
4,627 questions
.NET CLI
.NET CLI
A cross-platform toolchain for developing, building, running, and publishing .NET applications.
323 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,278 questions
.NET Runtime
.NET Runtime
.NET: Microsoft Technologies based on the .NET software framework.Runtime: An environment required to run apps that aren't compiled to machine language.
1,125 questions
Not Monitored
Not Monitored
Tag not monitored by Microsoft.
36,161 questions
0 comments No comments
{count} votes

Accepted answer
  1. Alberto Poblacion 1,556 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 276 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?