2011-03-18 106 views
2

我正在創建一個將在沙盒環境中運行代碼的應用程序。這個環境應該只允許不受信任的代碼處理明確給定的資源並返回一個定義的數據類型。我使用這個文章中找到設置沙箱校長:錯誤:沙盒時出現「繼承安全規則違反」

How to: Run Partially Trusted Code in a Sandbox

我也有一些代碼,需要將沙盒環境中運行。不幸的是,當我嘗試安裝類型,我發現了以下錯誤沙盒中運行:

Inheritance security rules violated by type: 'MyTypeRunningInSandbox'. Derived types must either match the security accessibility of the base type or be less accessible.

我不知道我爲什麼會得到這個錯誤的基本類型和派生類型兩者都是由我創造,並且兩者都不應該比另一個更安全。

我的應用程序Strucure(以幫助您瞭解):

TypeLoader class 
    \ 
    Trusted Sandbox Manager (i.e. sets up a the new sandbox) 
    \    (the error is happening in this class while creating the 
     |    new app domain) 
     | 
     |Untrusted Sandbox Manager (i.e. runs the untrusted code) 

如果你比較我的解決方案對於Microsoft文章上面,我的代碼失敗在相當於以下行:

ObjectHandle handle = Activator.CreateInstanceFrom(
newDomain, typeof(Sandboxer).Assembly.ManifestModule.FullyQualifiedName, 
     typeof(Sandboxer).FullName); 

有關如何解決此問題的任何想法?

回答

5

我終於明白了這一點。我需要更好地理解可信程序集和強名稱的工作原理。問題在於我的不可信類型的基類型位於一個程序集中,該程序集使用與之前設置爲可信的相同的強名稱密鑰進行了簽名。當我將基礎類型移動到具有不同強名稱鍵的新程序集時,它開始工作良好。現在看來如此明顯,無法想象爲什麼我以前沒有看到它。

感謝任何給予此考慮的人!

相關問題