डीबगिंग करते समय वर्तमान में, मैं एमईएफ का उपयोग कर विजुअल स्टूडियो 2010 में एक विस्तार विकसित कर रहा हूं और मुझे अपनी वैश्विक स्थिति शुरू करने की आवश्यकता है। मैंविजुअल स्टूडियो पैकेज प्रारंभिक विधि कॉल नहीं करता है जब
[PackageRegistration(UseManagedResourcesOnly = true)]
[InstalledProductRegistration("#110", "#112", "1.0.0.0", IconResourceID = 400)]
[Guid("1AF4B41B-F2DF-4F49-965A-816A103ADFEF")]
public sealed class MyPackage : Package
{
protected override void Initialize()
{
ContainerConfigurator.Configure();
ContainerConfigurator.IsInitialized = true;
base.Initialize();
}
}
इसके अलावा, मैं एक MEF वर्गीकारक प्रदाता है कि इस राज्य
[Export(typeof(IClassifierProvider))]
[Name("This is my provider")]
[ContentType("DebugOutput")]
[ContentType("Output")]
public class MyClassifierProvider : IClassifierProvider
{
[Import]
private IClassificationTypeRegistryService _classificationRegistry = null; // MEF
public IClassifier GetClassifier(ITextBuffer textBuffer)
{
// This always false
if (!ContainerConfigurator.IsInitialized)
throw new InvalidOperationException();
return textBuffer.Properties.GetOrCreateSingletonProperty(() => new TypedClassifier(ServiceLocator.Current, _classificationRegistry));
}
}
दोनों पैकेज और MEF वर्गीकारक का एक ही विधानसभा में हैं का उपयोग करता है Package.Initialize विधि में यह करने के लिए कोशिश कर रहा हूँ। जब मैं डिबगिंग शुरू करता हूं और ब्रेकपॉइंट डालता हूं तो मुझे लगता है कि यह समझा जाता है। लेकिन MyClassifierProvider को MyPackage से पहले शुरू किया गया है। कॉल प्रारंभ करें। इसलिए एमईएफ घटकों में से कोई भी शुरू होने से पहले मैं अपने वैश्विक राज्य को शुरू नहीं कर सकता। क्या कोई यह समझा सकता है कि मैं उस व्यवहार से क्यों और कैसे बच सकता हूं?
धन्यवाद
पहले लिंक गलत है के लिए आवश्यक है, यह VSConstants से जोड़ता है, ProvideAutoLoad मदद है यहां मिला: http://msdn.microsoft.com/en-us/library/Microsoft.VisualStudio.Shell.ProvideAutoLoadAttribute.aspx –
'ProvideAutoLoad' विशेषता अभी भी वैध (कम से कम वीएस 2015 के लिए) – CrazyIvan1974