當您通過COM實例化.NET類時,創建的AppDomain is null的evidence。如何使用空證據創建AppDomain?
我想分析一個只發生在AppDomain證據爲空時的問題,我想純粹在.NET中創建一個mcve,也就是說,不必在COM中註冊該類,並從那裏調用它。爲此,我需要一個帶有空白證據的AppDomain。
我該怎麼做?當通過null
到AppDomain.CreateDomain時,當前AppDomain的證據被重用。
當您通過COM實例化.NET類時,創建的AppDomain is null的evidence。如何使用空證據創建AppDomain?
我想分析一個只發生在AppDomain證據爲空時的問題,我想純粹在.NET中創建一個mcve,也就是說,不必在COM中註冊該類,並從那裏調用它。爲此,我需要一個帶有空白證據的AppDomain。
我該怎麼做?當通過null
到AppDomain.CreateDomain時,當前AppDomain的證據被重用。
確實,沒有辦法在.Net 4.0 +中創建帶有空證據的AppDomain。您的代碼是否在早期版本上運行?
的AppDomain.Evidence
屬性返回內部AppDomain.EvidenceNoDemand
屬性和反編譯源代碼都干將都低於,
它從沒有應用程序域永遠不會有一個空的證據的源代碼看來,不管它是創造通過COM或通過託管程序集。
public Evidence Evidence
{
[SecuritySafeCritical, TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries"), SecurityPermission(SecurityAction.Demand, ControlEvidence=true)]
get
{
return this.EvidenceNoDemand;
}
}
internal Evidence EvidenceNoDemand
{
[SecurityCritical]
get
{
if (this._SecurityIdentity != null)
{
return this._SecurityIdentity.Clone();
}
if (!this.IsDefaultAppDomain() && this.nIsDefaultAppDomainForEvidence())
{
return GetDefaultDomain().Evidence;
}
return new Evidence(new AppDomainEvidenceFactory(this));
}
}
你完全正確,我錯誤地認爲證據是無效的。事實上,證據是空的(Count = 0),這當然是不同的。謝謝你的幫助! – Heinzi
不客氣。 –
檢查AppDomain類的證據屬性的源代碼,似乎沒有任何AppDomain的證據爲空。你確定通過COM實例化一個.net類創建的AppDomain的證據是否爲空?你可以請檢查我的答案(只是爲了證明屬性源代碼,而不是一個真正的答案) –
它是什麼版本的.net框架? –