.NET Framework Bookmark and Share   
 index > Managed Extensibility Framework > Weird crash when Candidate provider does not export the imported type
 

Weird crash when Candidate provider does not export the imported type

e.g. I can get something to compile, but during App Startup, In Vista you get error like "...Has stopped working..."

public class DateStringProvider{

[Export(typeof(int))]
public String providedCaption{
get { return DateTime.Today.ToString(); }
}
}

For a console App, the error is found easily as

Unhandled Exception: System.ComponentModel.Composition.CompositionException: The
re was at least one composition issue of severity level `error'. Review the Issues collection for detailed information.
at System.ComponentModel.Composition.CompositionContainer.Bind()
at ConsoleApplication1.Program.test() in C:\Users\v-rdas\Desktop\MEF_CTP_June
_4_2008\examples\HelloWorld\ConsoleApplication1\Program.cs:line 43
at ConsoleApplication1.Program.Main(String[] args) in C:\Users\v-rdas\Desktop
\MEF_CTP_June_4_2008\examples\HelloWorld\ConsoleApplication1\Program.cs:line 23
Press any key to continue . . .

Viewing the issues collection reveals no meaningful diagnostic.


::Rajiv
thothful
Thanks Rajiv. If you look at the CompositionException, what does the Description say for each of the Issues in the Issues collection? I'm hoping it should be verbose enough to understand where there's export not found or another issue with composition.
BTW - I think your choice of contract type is a bit unusal, however something like this should work:

public class Foo
{
[Export(typeof(int))]
public String providedCaption
{
get { return DateTime.Today.ToString(); }
}

}

public class Bar
{
[Import(typeof(int))]
public String providedCaption { get; set; }

}


class Program
{
static void Main(string[] args)
{
var container = new CompositionContainer();
var bar = new Bar();
container.AddComponents(new Foo(), bar);
container.Bind();
Console.WriteLine(bar.providedCaption);
Console.ReadLine();
}

}


Alex Bulankou, Microsoft Corporation. This posting is provided "AS IS".
Alex Bulankou
Thanks Rajiv. If you look at the CompositionException, what does the Description say for each of the Issues in the Issues collection? I'm hoping it should be verbose enough to understand where there's export not found or another issue with composition.
BTW - I think your choice of contract type is a bit unusal, however something like this should work:

public class Foo
{
[Export(typeof(int))]
public String providedCaption
{
get { return DateTime.Today.ToString(); }
}

}

public class Bar
{
[Import(typeof(int))]
public String providedCaption { get; set; }

}


class Program
{
static void Main(string[] args)
{
var container = new CompositionContainer();
var bar = new Bar();
container.AddComponents(new Foo(), bar);
container.Bind();
Console.WriteLine(bar.providedCaption);
Console.ReadLine();
}

}


Alex Bulankou, Microsoft Corporation. This posting is provided "AS IS".
Alex Bulankou

You can use google to search for other answers

Custom Search

More Threads

• Firing Tab Changed Events for a TabbedWorkspace
• Task List Extensibility
• POCO and XML Mapping support
• "LoadLibrary" for "Com object" inside a dll
• not able to call vs 2005 c++ "clr" jni dll in other machines without vs 2005???????
• CompositionContainer & AOP
• Comparison of CompositionContainer with traditional IoC Containers
• Derived Classes & ExportProperty
• One framework to rule them all?
• Composite CompositionContainer or ValueResolvers?