HostSecurityManager.ProvideAssemblyEvidence(Assembly, Evidence) Method

Definition

Provides the assembly evidence for an assembly being loaded.

C#
public virtual System.Security.Policy.Evidence ProvideAssemblyEvidence(System.Reflection.Assembly loadedAssembly, System.Security.Policy.Evidence inputEvidence);

Parameters

loadedAssembly
Assembly

The loaded assembly.

inputEvidence
Evidence

Additional evidence to add to the assembly evidence.

Returns

The evidence to be used for the assembly.

Examples

The following example shows how to override the ProvideAssemblyEvidence method for a custom host security manager. This example is part of a larger example provided for the HostSecurityManager class.

C#
public override Evidence ProvideAssemblyEvidence(Assembly loadedAssembly, Evidence evidence)
{
    Console.WriteLine("Provide assembly evidence for: " + (loadedAssembly == null ? "Unknown" : loadedAssembly.ToString()) + ".");
    if (evidence == null)
        return null;

    evidence.AddAssemblyEvidence(new CustomEvidenceType());
    return evidence;
}

Remarks

This method can be overridden in a derived class.

This method is called whenever an assembly is loaded, either implicitly or explicitly. The passed in parameters are the assembly being loaded, and the computed evidence from the common language runtime. The host implementation can choose to extend or reduce the evidence. The return value is the evidence to be used for the assembly. The base implementation always returns the evidence object passed in as the inputEvidence parameter.

Important

See the Notes to Inheritors for the HostSecurityManager class for critical implementation information.

Applies to

Product Versions
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10