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 tracin...
What do we already know aboutMEF? Hopefully most of you have seen Karl’s introduction to  MEF. Key points:    MEF is us...
What does MEF failure look like? Composition exception – your module explodes and is  unusable.    You see this when you...
DiagnosticsDude, where’s my part?
Pizza Factory                             [Export(typeof(IPizzaFactory))]                             public class PizzaFa...
Debugger Inspection  Pros                         Cons Easy way to diagnose        Requires debugger,  simple scenarios....
Trace Messages  Pros                      Cons Logs rejected parts.    Logs the last cause of                           ...
MEF Explorer (MEFx)  Pros                      Cons Cool name                Trouble with type load                     ...
Visual MEFx  Pros                       Cons Cooler name, has          Beware of type load  “Visual” in it.            e...
Composition Diagnostics API  Pros                         Cons Same library used by        Integration tests less  MEFx ...
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 com...
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...
Satisfaction Checklist Can your container satisfy all nested imports? Did the container reject your change during  recom...
ReferencesHow to Debug and Diagnose MEFFailures, Daniel Plaisteds Bloghttp://blogs.msdn.com/b/dsplaisted/archive/2010/07/1...
Outline Why should you care about MEF  diagnostics? What do we already know about MEF? How might MEF fail? How might w...
Upcoming SlideShare
Loading in …5
×

Diagnosing MEF Failure

1,303 views

Published on

Published in: Sports, Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,303
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
7
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide
  • Step0: Run default – no exception. Run MEFx from the command line.
  • Step2
  • Show step0, show step1, show approval test
  • Diagnosing MEF Failure

    1. 1. Diagnosing MEF FailuresJim Counts | jcounts18@gmail.com | @jamesrcountsIhadthisideaonce.wordpress.com
    2. 2. 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.
    3. 3. 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.
    4. 4. 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.
    5. 5. DiagnosticsDude, where’s my part?
    6. 6. 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 } }
    7. 7. 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.
    8. 8. 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.
    9. 9. 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.
    10. 10. 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)
    11. 11. 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)
    12. 12. MEF 2The part “FunnySubtitle” was rejected because the part “FunnySpeaker” could not be satisfied.
    13. 13. 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.
    14. 14. Getting SatisfactionMick Jagger just didn’t know enough about MEF
    15. 15. 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?
    16. 16. 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?
    17. 17. 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
    18. 18. 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?

    ×