Click here to Skip to main content
15,885,365 members
Home / Discussions / C#
   

C#

 
AnswerRe: How to enable disable Hibernation option by using C# code. Pin
Shameel28-Mar-11 5:34
professionalShameel28-Mar-11 5:34 
QuestionExposing the running assembly to run-time compiled code Pin
Quiltfish27-Mar-11 9:56
Quiltfish27-Mar-11 9:56 
AnswerRe: Exposing the running assembly to run-time compiled code Pin
Bernhard Hiller27-Mar-11 21:14
Bernhard Hiller27-Mar-11 21:14 
AnswerRe: Exposing the running assembly to run-time compiled code Pin
Wayne Gaylard27-Mar-11 21:16
professionalWayne Gaylard27-Mar-11 21:16 
GeneralRe: Exposing the running assembly to run-time compiled code Pin
Quiltfish27-Mar-11 23:36
Quiltfish27-Mar-11 23:36 
GeneralRe: Exposing the running assembly to run-time compiled code Pin
Wayne Gaylard27-Mar-11 23:55
professionalWayne Gaylard27-Mar-11 23:55 
AnswerRe: Exposing the running assembly to run-time compiled code Pin
_Erik_28-Mar-11 4:17
_Erik_28-Mar-11 4:17 
GeneralRe: Exposing the running assembly to run-time compiled code [modified] Pin
Quiltfish28-Mar-11 22:28
Quiltfish28-Mar-11 22:28 
Whoop! Got to work, at least on a medium scale! I think part of what I was doing wrong in my last post was I accidentally set up TWO levels of restrictive appdomains, i.e. the main app set up a restrictive appdomain, then run the sandboxing code in that appdomain, which IN TURN created a restrictive appdomain and tried to load my intended sandboxed assembly into it (but failed because of the first level appdomain being restrictive)

So, to summarize:
A)Create a secondary Class Library project in the solution, let's call it "Exposed", which contains everything that the cs files will have access to.
B)Gather all the cs files I want to compile. The cs files reference "Exposed" in their code.
C)Use a CSharpCodeProvider to CompileAssemblyFromFile() those files into a class library dll-file saved in the appdir.Provide "Exposed.dll" as a reference. Provide compiler options "/target:library /out:*dll-name*.dll".
---The below steps are performed by a slightly customized Sandboxer object detailed here MSDN article[^]---
D)Create the appdomain, taking care to supply a proper PermissionSet (Containing only Execution permission in this case) as well as the StrongName of the current assembly to add it as a FullTrustAssembly. Also set the ApplicationBase (in the AppDomainSetup object) to something other than your main app base directory, for security reasons.
E)Use System.Activator to load a new instance of the Sandboxer class into the restrictive appdomain.
F)The new instance in the restrictive appdomain now invokes the wanted method in the compiled library, taking care to catch SecurityExceptions.

Of course, this can be improved. Currently, the restrictive appdomain is created EVERY TIME the compiled code is called, for instance.
modified on Tuesday, March 29, 2011 7:15 AM

GeneralRe: Exposing the running assembly to run-time compiled code Pin
BobJanova30-Mar-11 23:53
BobJanova30-Mar-11 23:53 
Questionproblem with sending message to serial port with timer [modified] Pin
Honeyboy_2027-Mar-11 8:36
Honeyboy_2027-Mar-11 8:36 
AnswerRe: problem with sending message to serial port with timer Pin
Luc Pattyn27-Mar-11 9:11
sitebuilderLuc Pattyn27-Mar-11 9:11 
GeneralRe: problem with sending message to serial port with timer Pin
Honeyboy_2027-Mar-11 12:39
Honeyboy_2027-Mar-11 12:39 
AnswerRe: problem with sending message to serial port with timer [modified] Pin
Luc Pattyn27-Mar-11 12:54
sitebuilderLuc Pattyn27-Mar-11 12:54 
Questionrun project in network Pin
jojoba201127-Mar-11 6:34
jojoba201127-Mar-11 6:34 
AnswerRe: run project in network Pin
Dalek Dave27-Mar-11 6:47
professionalDalek Dave27-Mar-11 6:47 
GeneralRe: run project in network Pin
jojoba201127-Mar-11 6:53
jojoba201127-Mar-11 6:53 
GeneralRe: run project in network Pin
Dalek Dave27-Mar-11 7:06
professionalDalek Dave27-Mar-11 7:06 
GeneralRe: run project in network Pin
Dave Kreskowiak27-Mar-11 7:50
mveDave Kreskowiak27-Mar-11 7:50 
GeneralRe: run project in network Pin
Ganesh Kumar Kaki13-Apr-11 2:42
Ganesh Kumar Kaki13-Apr-11 2:42 
GeneralRe: run project in network Pin
Dave Kreskowiak13-Apr-11 6:28
mveDave Kreskowiak13-Apr-11 6:28 
GeneralRe: run project in network Pin
Luc Pattyn27-Mar-11 9:16
sitebuilderLuc Pattyn27-Mar-11 9:16 
AnswerRe: run project in network Pin
Richard MacCutchan27-Mar-11 7:04
mveRichard MacCutchan27-Mar-11 7:04 
GeneralRe: run project in network Pin
Dalek Dave27-Mar-11 7:06
professionalDalek Dave27-Mar-11 7:06 
AnswerRe: run project in network Pin
dan!sh 27-Mar-11 8:13
professional dan!sh 27-Mar-11 8:13 
AnswerRe: run project in network Pin
Luc Pattyn27-Mar-11 9:15
sitebuilderLuc Pattyn27-Mar-11 9:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.