ITagger 및 IWpfTextViewMargin이 있는데 둘 다 MEF 구성 요소로 내보내집니다. 내 여백 코드에 ITagger를 가져온 다음 해당 Tagger에서 일부 멤버를 사용하고 싶습니다.ComposeParts 메서드가 작동하지 않습니다.
이제 Margin 클래스에서 ComponentContainer를 사용한 다음 IViewTaggerProvider를 가져 왔습니다. 다음 코드를 사용하여 많은 MEF 자습서에서 찾을 수 있습니다.
[Import(typeof(IViewTaggerProvider))]
public IViewTaggerProvider vt_provider { get; set; }
var catalog = new AggregateCatalog();
catalog.Catalogs.Add(new AssemblyCatalog(typeof(TestMargin).Assembly));
_container = new CompositionContainer(catalog);
//Fill the imports of this object
try
{
this._container.ComposeParts(this);
}
catch (CompositionException compositionException)
{
System.Diagnostics.Trace.WriteLine(compositionException.Message);
}
및 내보내기 코드.
[Export(typeof(IViewTaggerProvider))]
[ContentType...
내 보낸 클래스는 다른 네임 스페이스이지만 동일한 어셈블리에 정의되어 있습니다.
여기 ComposeParts (this)가 ImportCardinalityMismatchException을 발생시키는 문제가 발생했습니다. 매개 변수가 인 이유를 모르겠습니다.이입니다. 카탈로그을 전달하려고했지만 예외는 없지만 가져 오기도 null입니다. 또한 debug mef failures을 언급했으며 내 보낸 클래스에 올바른 계약 이름과 수출 유형 ID가 있다고 생각합니다.
비주얼 MEFx 및 디버깅 어셈블리를 확인한 후, I는 IViewTaggerProvider도 IViewTaggerProvider의 거부의 MEF 부분 결과 인 비주얼 스튜디오 IClassificationTypeRegistryService를 가져 때문에 아마 있다는 발견.
[Primary Rejection]
[Exception] System.ComponentModel.Composition.ImportCardinalityMismatchException: No valid exports were found that match the constraint '((exportDefinition.ContractName == "Microsoft.VisualStudio.Text.Classification.IClassificationTypeRegistryService") AndAlso (exportDefinition.Metadata.ContainsKey("ExportTypeIdentity") AndAlso "Microsoft.VisualStudio.Text.Classification.IClassificationTypeRegistryService".Equals(exportDefinition.Metadata.get_Item("ExportTypeIdentity"))))', invalid exports may have been rejected.
그래서 한 가지 해결책은 IClassificationTypeRegistryService를 내보내는 어셈블리를 추가하는 것입니다. Visual Studio 핵심 편집기 서비스이지만 어셈블리를 내보내는 항목을 찾을 수 없습니다. 누구든지 이걸 알고 있니?
또는 더 좋은 해결책이 있습니까?
수입품 목록과 수출액 목록을 작성하면 쉽게 도움이 될 것입니다. "소비"는 기본적으로'[가져 오기]'를 의미합니다. –
@ jberger : 아마도 당신이 말한 것을 시도해 보았을 것입니다. 내 질문을 업데이트 한 새로운 것 같다 – Neo
당신의'Margin' 클래스의 서명은 무엇입니까? –