Diagnosing MEF Failure
Upcoming SlideShare
Loading in...5

Diagnosing MEF Failure






Total Views
Views on SlideShare
Embed Views



0 Embeds 0

No embeds



Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
Post Comment
Edit your comment
  • Step0: Run default – no exception. Run MEFx from the command line.
  • Step2
  • Show step0, show step1, show approval test

Diagnosing MEF Failure Diagnosing MEF Failure Presentation Transcript

  • Diagnosing MEF FailuresJim Counts | jcounts18@gmail.com | @jamesrcountsIhadthisideaonce.wordpress.com
  • Why care? Diagnosing composition failure can be tricky at first. Root cause often misidentified by exceptions and tracing. Better tools are available now. Better exception and tracing are coming in MEF 2.
  • What do we already know aboutMEF? Hopefully most of you have seen Karl’s introduction to MEF. Key points:  MEF is used to compose parts.  A motor is part of a car.  MEF will reject a part if any required nested part is missing.  To MEF, no such thing as a “car without a motor”.  Or, if its not usable, it doesn’t exist.  Not all parts are required, you can have options  Sun roof is optional, car works without it, but you can only have one.  Cup holders are optional, but you can have many.
  • What does MEF failure look like? Composition exception – your module explodes and is unusable.  You see this when you ask MEF for a part it can’t provide.  The fact that there are no wheels available for the car is fine… until someone orders a car. Wrong behavior – Composition succeeds, but desired plugins/services are not loaded.  You see this when asking for a part that has optional parts which MEF can’t provide.  Car still works without cup holders… but customer wont accept the car without them.
  • DiagnosticsDude, where’s my part?
  • Pizza Factory [Export(typeof(IPizzaFactory))] public class PizzaFactory : IPizzaFactory Pizza Kitchen would have { been a better name [ImportMany] Wants to import Pizza public IEnumerable<IPizzaMaker> PizzaMakers Makers (recipes) { It wont ever be rejected get; set; But it might not know } how to make the pizza the customer orders. public IPizza MakePizza(string pizzaType) { Lets look at some // ... diagnostics } }
  • Debugger Inspection Pros Cons Easy way to diagnose  Requires debugger, simple scenarios. source code, symbols You can see what made  Hard to read. it into the catalog.  Large catalogs harder to If the catalog is small, navigate. you can probably figure  Limited use when dealing out what’s missing. with a “collection of Comes in the box. unknowns”.  No analysis.
  • Trace Messages Pros Cons Logs rejected parts.  Logs the last cause of failure, not the root Does not require a cause. debugger.  Tells lies. Comes in the box.  TMI  No analysis.
  • MEF Explorer (MEFx) Pros Cons Cool name  Trouble with type load exceptions. Separate EXE provides static analysis for  Command line (almost) any MEF parameters don’t respect application. the working directory. Open Source (MS-PL)  Output can be hard to read in command window.
  • Visual MEFx Pros Cons Cooler name, has  Beware of type load “Visual” in it. exceptions GUI  GUI Easier to read. Easier to play with “what-if” scenarios. Open Source (mefcontrib-tools, MS- PL)
  • Composition Diagnostics API Pros Cons Same library used by  Integration tests less MEFx and VMEFx useful in “true” plug-in Easy to integrate with scenario. tests  Test/Production catalogs ApprovalTests can “read” must be kept in sync. the output for you. Works with CI when you know what the composition should look like. Open Source (MS-PL)
  • MEF 2The part “FunnySubtitle” was rejected because the part “FunnySpeaker” could not be satisfied.
  • Diagnostics in MEF 2 Better exceptions  Improved formatting  Root cause is shown (for real this time) Unstable composition  Container option.  Causes exception to be thrown for any part that would have been rejected.  Great for applications that just use MEF for composition, and not for extensibility.
  • Getting SatisfactionMick Jagger just didn’t know enough about MEF
  • Satisfaction Checklist Do your parts have the [Export] attribute? Are your matching parts missing from the catalog? Are there too many matching parts in the catalog? Did you forget to export using the part’s interface name? Do your contract names match? Does each import meta data key exist on the export? Does the type of the meta data on the import match the type of the meta data on the export (1 != “1”) Are your parts using the right creation policy?
  • Satisfaction Checklist Can your container satisfy all nested imports? Did the container reject your change during recomposition? Do your parts reference unavailable assemblies? Are there conflicts between different versions of the same assembly? Do your assemblies target the expected CPU? Are your assemblies available in your current load context? Do you have any other type load issues?
  • ReferencesHow to Debug and Diagnose MEFFailures, Daniel Plaisteds Bloghttp://blogs.msdn.com/b/dsplaisted/archive/2010/07/13/how-to-debug-and-diagnose-mef-failures.aspxDiagnosing Composition Problems,mef.codeplex.comhttp://mef.codeplex.com/wikipage?title=Debugging%20and%20Diagnostics&referringTitle=Guide
  • Outline Why should you care about MEF diagnostics? What do we already know about MEF? How might MEF fail? How might we diagnose MEF failures?