Export Interface¶
What does this mean ?¶
In classic MEF (System.ComponentModel.Composition), an export advertises a contract to the composition container. A class exported as an interface must be assignable to that interface; matching method names alone is insufficient in C#. Microsoft's ExportAttribute documentation describes the contract type and name.
What can happen ?¶
An incompatible export can cause composition or value retrieval to fail at runtime even when attribute declarations compile. This is a dependency configuration defect, not automatically an authorization bypass. Severity depends on whether the unavailable component is required for a critical operation.
Recommendation¶
Implement the intended contract, or change the declared contract to the type actually supplied. Check the importing member's contract name and type as well. Do not add an unrelated interface solely to silence a diagnostic. An exported object still needs ordinary access controls when it exposes sensitive operations.
Sample Code¶
Both alternatives use using System.ComponentModel.Composition; and this contract:
public interface IReport { string Render(); }
Incorrect contract:
[Export(typeof(IReport))]
public class Report
{
public string Render() => "Report";
}
Matching contract:
[Export(typeof(IReport))]
public class Report : IReport
{
public string Render() => "Report";
}
Regression test: compose a catalog containing Report, retrieve IReport, and assert that Render() returns the expected result. Also test the application's actual importing part; inspecting attributes alone does not prove successful composition.