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?
            Asked
            
        
        
            Active
            
        
            Viewed 449 times
        
    1
            
            
        - 
                    Yes, that's exactly what I mean. – Nahydrin Jul 05 '11 at 05:10
 
2 Answers
0
            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.
- 
                    The downloaded source code is encrypted. It's an online-only program, so the inconveneice will always be there. – Nahydrin Jul 05 '11 at 05:21
 - 
                    @Dark: Doesn't really matter, since the decryption keys are on the user's computer. Just another speedbump, no real security. – Ben Voigt Jul 05 '11 at 05:29
 - 
                    @Dark: Anyway, why send source code, when you can encrypt and send the MSIL output from the C# compiler? – Ben Voigt Jul 05 '11 at 05:41
 - 
                    
 - 
                    1@Dark: Just build a DLL project. Send that file, when you decrypt it on the receiving side, instead of writing it to disk, call `Assembly.Load(byte[])`. – Ben Voigt Jul 05 '11 at 06:25