Search code examples
c#dynamic-compilation

C# code at runtime?


How can I compile raw C# code at runtime? So if I want to add security by removing important pieces of code and downloading it via a server, and then execute it from within my application?


Solution

  • Do you want to download the source code, or a compiled version?

    You can download the MSIL and use Assembly.Load(byte[]) to load it for execution.

    But none of these methods add security. If you send the code to the user's computer in ANY format, they can capture a copy. Never saving it to disk just adds a small speedbump.

    See: The #1 law of software licensing.