none
C#.net inject the c# code on run time?

    Question

  • Hello All Guys,

    Can anyone let me know what will be the use of injecting the code at run time.

    how is it possible to do like this?

    if possible then can anyone help me in giving sole sample code.

    • Moved by Naomi N Thursday, March 30, 2017 12:17 PM Better answer can be here
    Thursday, March 30, 2017 9:51 AM

All replies

  • Not clear what you mean here; may be SQL Injection? https://en.wikipedia.org/wiki/SQL_injection

    Olaf Helper

    [ Blog] [ Xing] [ MVP]

    Thursday, March 30, 2017 10:02 AM
  • C# is not interpreted at run time like vbscript, jscript or powershell. It has to be compiled and then executed. It might be possible to write an application in C# that would take C# code and compile it and run it at run time, but one would question why one would want to do this.

    Some compilers will build and compile libraries during the setup. Perhaps this is what you are looking for,

    Thursday, March 30, 2017 11:30 AM
  • Hello,

    Your question is to high level in it's description. Not knowing what you want perhaps the following might be or not be in the right direction.

    CodeInject - Code Inject and Runtime Intelligence

    CInject (or CodeInject) allows code injection into any managed assembly without disassembling and recompiling it. It eases the inevitable task of injecting any code in single or multiple methods in one or many assemblies to intercept code for almost any purpose.

    When using CInject, you do not require any knowledge of the target application. You can create your own injectors very easily and inject them in any target assembly/executable. An example is provided with this application. If you have an existing code which has no logging or no diagnostics, inject it with CInject and execute it as usual to generate log files. Helps you analyze any code and ease your reverse engineering exercise

    https://github.com/punitganshani/codeinject


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Thursday, March 30, 2017 12:37 PM
    Moderator