ノー権限でのAppDomainで作成するが、SecurityPermissionFlag.Executeインスタンスそのうち私は、このクラスを持っている:AppDomain.DoCallBackにはReflectionPermissionが必要ですか?
class IsolationEntryPoint : MarshalByRefObject
{
// main is the original AppDomain with all the permissions
public void Enter(AppDomain main)
{
// these work correctly
Console.WriteLine("Currently in: " + AppDomain.CurrentDomain.FriendlyName);
Console.WriteLine("Host: " + main.FriendlyName);
// the exception is thrown here
main.DoCallBack(this.MyCallBack);
}
public void MyCallBack()
{
Console.WriteLine("Currently in: " + AppDomain.CurrentDomain.FriendlyName);
}
}
奇妙なことは、私は言ってDoCallbackラインにSecurityExceptionを得ることです:用
リクエストを 'System.Security.Permissions.ReflectionPermission、mscorlib、 バージョン= 4.0.0.0、Culture =ニュートラル、PublicKeyToken = b77a5c561934e089' のアクセス許可が失敗しました。 AppDomain.DoCallBackの許可要件に関する
MSDNsays this:
ReflectionPermission などType.InvokeMemberなどの機構を通じて遅延バインディング呼び出されたとき。
コールにはType.InvokeMemberのようなものは使用されていません。なぜ例外が表示されますか?
EDIT:
明確にするために、ここで私は分離オブジェクトとのAppDomainを作成するために使用するコードは次のとおりです。
[STAThread]
static void Main(string[] args)
{
var setup = new AppDomainSetup();
setup.ApplicationBase = Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase);
var evidence = new Evidence();
var permissions = new PermissionSet(PermissionState.None);
permissions.AddPermission(new SecurityPermission(SecurityPermissionFlag.Execution));
var domain = AppDomain.CreateDomain(
"isolationDomain",
evidence,
setup,
permissions);
var handle = Activator.CreateInstanceFrom(
domain, typeof(IsolationEntryPoint).Assembly.ManifestModule.FullyQualifiedName,
typeof(IsolationEntryPoint).FullName);
var instance = (IsolationEntryPoint)handle.Unwrap();
instance.Enter(AppDomain.CurrentDomain);
}
これら2つのコードは私の完全なアプリケーションです、何もありませんelse(例外が再現しやすいように)。あなたの助け
ああコース。 ReShaperはクラスにアクセス修飾子を与えることを私に叫んでいます。助けてくれてありがとう、あなたのために+100をつけてください:)(0125)。 –
あなたは時にはツール_トランプを使います.-祈りのソースを使ってください。) - 寛大な賞金をいただきありがとうございます。 –