GenericsDemo with MefBootstrapper

Dec 14, 2010 at 11:38 PM
Edited Dec 14, 2010 at 11:46 PM

I broke the MefContrib.Samples.Interception GenericDemo up into separate projects.

Domain.Core
IRepository.cs

Domain.MainModule.Entities
Customer.cs

Infrastructure.Data.Core
Repository.cs

Infrastructure.Data.MainModule
MyGenericContractRegistry.cs
Trampoline.cs

WpfApplication1
MyBootstrapper.cs

More or less all I did was take the AggregateCatalog code in CreateContainer2 and add it to the ConfigureAggregateCatalog override.

 The original code was doing a GetExportedValue to Trampoline while I did mine to the MyShell.

The error originates with return this.Container.GetExportedValue<MyShell>();

It’s probably something simple but I have not been able to figure it out.

I traced the error back to MefContrib.CompositionServices.

private static Type GetMethodType(ImportDefinition definition, Type importDefinitionType)
{
    var memberInfos = ReflectionModelServices.GetImportingMember(definition).GetAccessors();
    var memberInfo = memberInfos[0];

    if (memberInfo.MemberType == MemberTypes.Method) // <-Object reference not set to an instance of an object.

memberInfos has two objects in it
1. null
2. {Void set_ViewModel(WpfApplication1.MyShellViewModel)}

public partial class MyBootstrapper
    : MefBootstrapper
{
    protected override void ConfigureAggregateCatalog()
    {
        this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(MyBootstrapper).Assembly));

        // Add any modules that are referenced in the project and directly in code.
        this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(AutoPopulateExportedViewsBehavior).Assembly));

        this.AggregateCatalog.Catalogs.Add(new TypeCatalog(typeof(Trampoline)));
        this.AggregateCatalog.Catalogs.Add(new GenericCatalog(new MyGenericContractRegistry()));
    }

    protected override void ConfigureContainer()
    {
        base.ConfigureContainer();
    }

    protected override void InitializeShell()
    {
        base.InitializeShell();

        Application.Current.MainWindow = (MyShell)this.Shell;
        Application.Current.MainWindow.Show();
    }

    protected override IRegionBehaviorFactory ConfigureDefaultRegionBehaviors()
    {
        // Adds a Region Behaviors for All Regions.
        var factory = base.ConfigureDefaultRegionBehaviors();

        if (factory != null)
        {
            factory.AddIfMissing("AutoPopulateExportedViewsBehavior", typeof(AutoPopulateExportedViewsBehavior));
        }

        return factory;
    }

    protected override DependencyObject CreateShell()
    {
        return this.Container.GetExportedValue<MyShell>();
    }


    protected override CompositionContainer CreateContainer()
    {
        var container = base.CreateContainer();

        // This allows CompositionInitializer to use the same MEF composition container that Prism is using.
        CompositionHost.Initialize(container);

        return container;
    }
}
*Edit* added stacktrace
   at MefContrib.CompositionServices.GetMethodType(ImportDefinition definition, Type importDefinitionType) in C:\Projects\3rdParty\CodePlex\MefContrib\Source\src\MefContrib\CompositionServices.cs:line 34
   at MefContrib.CompositionServices.GetImportDefinitionType(ImportDefinition definition) in C:\Projects\3rdParty\CodePlex\MefContrib\Source\src\MefContrib\CompositionServices.cs:line 22
   at MefContrib.Hosting.Generics.GenericExportHandler.GetExports(ImportDefinition definition, IEnumerable`1 exports) in C:\Projects\3rdParty\CodePlex\MefContrib\Source\src\MefContrib\Hosting\Generics\GenericExportHandler.cs:line 99
   at MefContrib.Hosting.Interception.InterceptingCatalog.GetExports(ImportDefinition definition) in C:\Projects\3rdParty\CodePlex\MefContrib\Source\src\MefContrib\Hosting\Interception\InterceptingCatalog.cs:line 70
   at MefContrib.Hosting.Generics.GenericCatalog.GetExports(ImportDefinition definition) in C:\Projects\3rdParty\CodePlex\MefContrib\Source\src\MefContrib\Hosting\Generics\GenericCatalog.cs:line 58
   at System.ComponentModel.Composition.Hosting.AggregateCatalog.GetExports(ImportDefinition definition)
   at System.ComponentModel.Composition.Hosting.CatalogExportProvider.GetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition)
   at System.ComponentModel.Composition.Hosting.ExportProvider.TryGetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition, IEnumerable`1& exports)
   at System.ComponentModel.Composition.Hosting.AggregateExportProvider.GetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition)
   at System.ComponentModel.Composition.Hosting.ExportProvider.TryGetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition, IEnumerable`1& exports)
   at System.ComponentModel.Composition.Hosting.ExportProvider.TryGetExports(ImportDefinition definition, AtomicComposition atomicComposition, IEnumerable`1& exports)
   at System.ComponentModel.Composition.Hosting.CompositionContainer.GetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition)
   at System.ComponentModel.Composition.Hosting.ExportProvider.TryGetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition, IEnumerable`1& exports)
   at System.ComponentModel.Composition.Hosting.ExportProvider.GetExports(ImportDefinition definition, AtomicComposition atomicComposition)
   at System.ComponentModel.Composition.Hosting.ImportEngine.TryGetExports(ExportProvider provider, ComposablePart part, ImportDefinition definition, AtomicComposition atomicComposition)
   at System.ComponentModel.Composition.Hosting.ImportEngine.TrySatisfyImportSubset(PartManager partManager, IEnumerable`1 imports, AtomicComposition atomicComposition)
   at System.ComponentModel.Composition.Hosting.ImportEngine.TryPreviewImportsStateMachine(PartManager partManager, ComposablePart part, AtomicComposition atomicComposition)
   at System.ComponentModel.Composition.Hosting.ImportEngine.PreviewImports(ComposablePart part, AtomicComposition atomicComposition)
   at System.ComponentModel.Composition.Hosting.CatalogExportProvider.DetermineRejection(ComposablePartDefinition definition, AtomicComposition parentAtomicComposition)
   at System.ComponentModel.Composition.Hosting.CatalogExportProvider.IsRejected(ComposablePartDefinition definition, AtomicComposition atomicComposition)
   at System.ComponentModel.Composition.Hosting.CatalogExportProvider.GetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition)
   at System.ComponentModel.Composition.Hosting.ExportProvider.TryGetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition, IEnumerable`1& exports)
   at System.ComponentModel.Composition.Hosting.AggregateExportProvider.GetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition)
   at System.ComponentModel.Composition.Hosting.ExportProvider.TryGetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition, IEnumerable`1& exports)
   at System.ComponentModel.Composition.Hosting.ExportProvider.TryGetExports(ImportDefinition definition, AtomicComposition atomicComposition, IEnumerable`1& exports)
   at System.ComponentModel.Composition.Hosting.CompositionContainer.GetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition)
   at System.ComponentModel.Composition.Hosting.ExportProvider.TryGetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition, IEnumerable`1& exports)
   at System.ComponentModel.Composition.Hosting.ExportProvider.GetExports(ImportDefinition definition, AtomicComposition atomicComposition)
   at System.ComponentModel.Composition.Hosting.ExportProvider.GetExportsCore(Type type, Type metadataViewType, String contractName, ImportCardinality cardinality)
   at System.ComponentModel.Composition.Hosting.ExportProvider.GetExportedValueCore[T](String contractName, ImportCardinality cardinality)
   at System.ComponentModel.Composition.Hosting.ExportProvider.GetExportedValue[T](String contractName)
   at System.ComponentModel.Composition.Hosting.ExportProvider.GetExportedValue[T]()
   at BackOffice.MyBootstrapper.CreateShell() in C:\Projects\Test\WpfApplication1\WpfApplication1\MyBootstrapper.cs:line 101
   at Microsoft.Practices.Prism.MefExtensions.MefBootstrapper.Run(Boolean runWithDefaultConfiguration)
   at Microsoft.Practices.Prism.Bootstrapper.Run()
   at WpfApplication1.App.RunInDebugMode() in C:\Projects\Test\WpfApplication1\WpfApplication1\App.xaml.cs:line 44
   at WpfApplication1.App.OnStartup(StartupEventArgs e) in C:\Projects\Test\WpfApplication1\WpfApplication1\App.xaml.cs:line 35
   at System.Windows.Application.<.ctor>b__1(Object unused)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
   at System.Windows.Threading.DispatcherOperation.InvokeImpl()
   at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)
   at System.Threading.ExecutionContext.runTryCode(Object userData)
   at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Windows.Threading.DispatcherOperation.Invoke()
   at System.Windows.Threading.Dispatcher.ProcessQueue()
   at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
   at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
   at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
   at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
   at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
   at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
   at System.Windows.Threading.Dispatcher.Run()
   at System.Windows.Application.RunDispatcher(Object ignore)
   at System.Windows.Application.RunInternal(Window window)
   at System.Windows.Application.Run(Window window)
   at System.Windows.Application.Run()
   at WpfApplication1.App.Main() in C:\Projects\Test\WpfApplication1\WpfApplication1\App.xaml.cs:line 29
   at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
   at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
   at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()
Coordinator
Dec 15, 2010 at 8:00 AM

Thank you for reporting this! Can you please share the full solution code ? It would be much easier for me to further investigate =) Please reach me directly at piotr DOT wlodek AT gmail DOT com.

Thanks!

 

Piotr

Dec 15, 2010 at 3:34 PM

Piotr,

I have sent you an email with the full solution.

Coordinator
Dec 16, 2010 at 10:05 AM

Kevin,

You have found a pretty nasty bug! InterceptingCatalog didn't inject setter-only properties. Bug has been fixed, grab the latest code from github.

 

Piotr

Coordinator
Dec 16, 2010 at 10:40 AM
thank you for reporting this xiquon and great work on fixing it piotr!

On Thu, Dec 16, 2010 at 12:05 PM, pwlodek <notifications@codeplex.com> wrote:

From: pwlodek

Kevin,

You have found a pretty nasty bug! InterceptingCatalog didn't inject setter-only properties. Bug has been fixed, grab the latest code from github.

Piotr

Read the full discussion online.

To add a post to this discussion, reply to this email (MEFContrib@discussions.codeplex.com)

To start a new discussion for this project, email MEFContrib@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com