This project has moved and is read-only. For the latest updates, please go here.

Importing Part problem

May 3, 2010 at 6:09 PM

Hi All,

I'm wondering if someone can help me out here. I've got an application that does something like:

public interface IMySharedObject

public class MySharedObject : IMySharedObject

IMySharedObject myObj;

// on import

IMySharedObject myObj2 = container.GetExportedValue<IMySharedObject>();
For Some reason the myObj2 creates a new instance (so not initialized). 
It was my understanding that exported objects defaulted to shared so it should already be initialized.
If I do another [Import] I get the original object, why not with getExportedValue?
please Help...
May 3, 2010 at 6:39 PM
Edited May 3, 2010 at 6:39 PM

Well I figured this out.

In case anyone else is interested, the problem was that I was initializing the CompositionHost with my AggregateCatalog, not my CompositionContainer.

So I was getting a shared object per container, exactly like you are supposed to. :)

May 3, 2010 at 9:43 PM

That'll do it :-)

Glad you figured it out. Might be a good gotcha to blog about....