SlideShare a Scribd company logo
1 of 18
Diagnosing MEF Failures
Jim Counts | jcounts18@gmail.com | @jamesrcounts
Ihadthisideaonce.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 about
MEF?
 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.
Diagnostics
Dude, 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 2
The 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 Satisfaction
Mick 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?
References
How to Debug and Diagnose MEF
Failures, Daniel Plaisted's Blog
http://blogs.msdn.com/b/dsplaisted/archi
ve/2010/07/13/how-to-debug-and-
diagnose-mef-failures.aspx
Diagnosing Composition Problems,
mef.codeplex.com
http://mef.codeplex.com/wikipage?title=D
ebugging%20and%20Diagnostics&referrin
gTitle=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?

More Related Content

What's hot (6)

ITFT- Applet in java
ITFT- Applet in javaITFT- Applet in java
ITFT- Applet in java
 
Start using PHP 7
Start using PHP 7Start using PHP 7
Start using PHP 7
 
Java applets
Java appletsJava applets
Java applets
 
Appletjava
AppletjavaAppletjava
Appletjava
 
Applets
AppletsApplets
Applets
 
Java applets
Java appletsJava applets
Java applets
 

Similar to Diagnosing MEF Failure

Treat Your Unit Tests As Production Code - DARGO - Amadeus - Soirée du Test L...
Treat Your Unit Tests As Production Code - DARGO - Amadeus - Soirée du Test L...Treat Your Unit Tests As Production Code - DARGO - Amadeus - Soirée du Test L...
Treat Your Unit Tests As Production Code - DARGO - Amadeus - Soirée du Test L...TelecomValley
 
Error Correction Techniques
Error Correction TechniquesError Correction Techniques
Error Correction TechniquesKelly Bauer
 
Plug yourself in and your app will never be the same (2 hr editon)
Plug yourself in and your app will never be the same (2 hr editon)Plug yourself in and your app will never be the same (2 hr editon)
Plug yourself in and your app will never be the same (2 hr editon)Mikkel Flindt Heisterberg
 
Plug yourself in and your app will never be the same (2 hour edition)
Plug yourself in and your app will never be the same (2 hour edition)Plug yourself in and your app will never be the same (2 hour edition)
Plug yourself in and your app will never be the same (2 hour edition)Mikkel Flindt Heisterberg
 
Managed Extensibility Framework or Effective Development of Scalable Applicat...
Managed Extensibility Framework or Effective Development of Scalable Applicat...Managed Extensibility Framework or Effective Development of Scalable Applicat...
Managed Extensibility Framework or Effective Development of Scalable Applicat...SoftServe
 
UNIT 3.1 INTRODUCTON TO IDA.ppt
UNIT 3.1 INTRODUCTON TO IDA.pptUNIT 3.1 INTRODUCTON TO IDA.ppt
UNIT 3.1 INTRODUCTON TO IDA.pptManjuAppukuttan2
 
debugging (1).ppt
debugging (1).pptdebugging (1).ppt
debugging (1).pptjerlinS1
 
An important characteristic of a test suite that is computed by a dynamic ana...
An important characteristic of a test suite that is computed by a dynamic ana...An important characteristic of a test suite that is computed by a dynamic ana...
An important characteristic of a test suite that is computed by a dynamic ana...jeyasrig
 
Production Debugging at Code Camp Philly
Production Debugging at Code Camp PhillyProduction Debugging at Code Camp Philly
Production Debugging at Code Camp PhillyBrian Lyttle
 
10 Ways To Improve Your Code( Neal Ford)
10  Ways To  Improve  Your  Code( Neal  Ford)10  Ways To  Improve  Your  Code( Neal  Ford)
10 Ways To Improve Your Code( Neal Ford)guestebde
 
Duplicate Bug Reports Considered Harmful ... Really?
Duplicate Bug Reports Considered Harmful ... Really?Duplicate Bug Reports Considered Harmful ... Really?
Duplicate Bug Reports Considered Harmful ... Really?Nicolas Bettenburg
 
The D language comes to help
The D language comes to helpThe D language comes to help
The D language comes to helpPVS-Studio
 
Plug-in Architectures
Plug-in ArchitecturesPlug-in Architectures
Plug-in Architectureselliando dias
 
Testing Options in Java
Testing Options in JavaTesting Options in Java
Testing Options in JavaMichael Fons
 
Continuous Integration
Continuous  IntegrationContinuous  Integration
Continuous IntegrationLiyao Chen
 
The compiler is to blame for everything
The compiler is to blame for everythingThe compiler is to blame for everything
The compiler is to blame for everythingPVS-Studio
 

Similar to Diagnosing MEF Failure (20)

Custom JSF components
Custom JSF componentsCustom JSF components
Custom JSF components
 
Treat Your Unit Tests As Production Code - DARGO - Amadeus - Soirée du Test L...
Treat Your Unit Tests As Production Code - DARGO - Amadeus - Soirée du Test L...Treat Your Unit Tests As Production Code - DARGO - Amadeus - Soirée du Test L...
Treat Your Unit Tests As Production Code - DARGO - Amadeus - Soirée du Test L...
 
Debugging in .Net
Debugging in .NetDebugging in .Net
Debugging in .Net
 
Error Correction Techniques
Error Correction TechniquesError Correction Techniques
Error Correction Techniques
 
Plug yourself in and your app will never be the same (2 hr editon)
Plug yourself in and your app will never be the same (2 hr editon)Plug yourself in and your app will never be the same (2 hr editon)
Plug yourself in and your app will never be the same (2 hr editon)
 
Plug yourself in and your app will never be the same (2 hour edition)
Plug yourself in and your app will never be the same (2 hour edition)Plug yourself in and your app will never be the same (2 hour edition)
Plug yourself in and your app will never be the same (2 hour edition)
 
Managed Extensibility Framework
Managed Extensibility FrameworkManaged Extensibility Framework
Managed Extensibility Framework
 
Managed Extensibility Framework or Effective Development of Scalable Applicat...
Managed Extensibility Framework or Effective Development of Scalable Applicat...Managed Extensibility Framework or Effective Development of Scalable Applicat...
Managed Extensibility Framework or Effective Development of Scalable Applicat...
 
UNIT 3.1 INTRODUCTON TO IDA.ppt
UNIT 3.1 INTRODUCTON TO IDA.pptUNIT 3.1 INTRODUCTON TO IDA.ppt
UNIT 3.1 INTRODUCTON TO IDA.ppt
 
debugging (1).ppt
debugging (1).pptdebugging (1).ppt
debugging (1).ppt
 
An important characteristic of a test suite that is computed by a dynamic ana...
An important characteristic of a test suite that is computed by a dynamic ana...An important characteristic of a test suite that is computed by a dynamic ana...
An important characteristic of a test suite that is computed by a dynamic ana...
 
Production Debugging at Code Camp Philly
Production Debugging at Code Camp PhillyProduction Debugging at Code Camp Philly
Production Debugging at Code Camp Philly
 
10 Ways To Improve Your Code( Neal Ford)
10  Ways To  Improve  Your  Code( Neal  Ford)10  Ways To  Improve  Your  Code( Neal  Ford)
10 Ways To Improve Your Code( Neal Ford)
 
Duplicate Bug Reports Considered Harmful ... Really?
Duplicate Bug Reports Considered Harmful ... Really?Duplicate Bug Reports Considered Harmful ... Really?
Duplicate Bug Reports Considered Harmful ... Really?
 
The D language comes to help
The D language comes to helpThe D language comes to help
The D language comes to help
 
Plug-in Architectures
Plug-in ArchitecturesPlug-in Architectures
Plug-in Architectures
 
Testing Options in Java
Testing Options in JavaTesting Options in Java
Testing Options in Java
 
Continuous Integration
Continuous  IntegrationContinuous  Integration
Continuous Integration
 
The compiler is to blame for everything
The compiler is to blame for everythingThe compiler is to blame for everything
The compiler is to blame for everything
 
Intro To AOP
Intro To AOPIntro To AOP
Intro To AOP
 

Recently uploaded

Muzaffarpur Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Muzaffarpur Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMuzaffarpur Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Muzaffarpur Call Girls 🥰 8617370543 Service Offer VIP Hot ModelDeepika Singh
 
European Football Icons that Missed Opportunities at UEFA Euro 2024.docx
European Football Icons that Missed Opportunities at UEFA Euro 2024.docxEuropean Football Icons that Missed Opportunities at UEFA Euro 2024.docx
European Football Icons that Missed Opportunities at UEFA Euro 2024.docxEuro Cup 2024 Tickets
 
Sports Writing (Rules,Tips, Examples, etc)
Sports Writing (Rules,Tips, Examples, etc)Sports Writing (Rules,Tips, Examples, etc)
Sports Writing (Rules,Tips, Examples, etc)CMBustamante
 
Who Is Emmanuel Katto Uganda? His Career, personal life etc.
Who Is Emmanuel Katto Uganda? His Career, personal life etc.Who Is Emmanuel Katto Uganda? His Career, personal life etc.
Who Is Emmanuel Katto Uganda? His Career, personal life etc.Marina Costa
 
JORNADA 6 LIGA MURO 2024TUXTEPECOAXACA.pdf
JORNADA 6 LIGA MURO 2024TUXTEPECOAXACA.pdfJORNADA 6 LIGA MURO 2024TUXTEPECOAXACA.pdf
JORNADA 6 LIGA MURO 2024TUXTEPECOAXACA.pdfArturo Pacheco Alvarez
 
Unveiling the Mystery of Main Bazar Chart
Unveiling the Mystery of Main Bazar ChartUnveiling the Mystery of Main Bazar Chart
Unveiling the Mystery of Main Bazar ChartChart Kalyan
 
UEFA Euro 2024 Squad Check-in Which team is Top favorite.docx
UEFA Euro 2024 Squad Check-in Which team is Top favorite.docxUEFA Euro 2024 Squad Check-in Which team is Top favorite.docx
UEFA Euro 2024 Squad Check-in Which team is Top favorite.docxEuro Cup 2024 Tickets
 
Technical Data | Sig Sauer Easy6 BDX 1-6x24 | Optics Trade
Technical Data | Sig Sauer Easy6 BDX 1-6x24 | Optics TradeTechnical Data | Sig Sauer Easy6 BDX 1-6x24 | Optics Trade
Technical Data | Sig Sauer Easy6 BDX 1-6x24 | Optics TradeOptics-Trade
 
JORNADA 5 LIGA MURO 2024INSUGURACION.pdf
JORNADA 5 LIGA MURO 2024INSUGURACION.pdfJORNADA 5 LIGA MURO 2024INSUGURACION.pdf
JORNADA 5 LIGA MURO 2024INSUGURACION.pdfArturo Pacheco Alvarez
 
Asli Kala jadu, Black magic specialist in Pakistan Or Kala jadu expert in Egy...
Asli Kala jadu, Black magic specialist in Pakistan Or Kala jadu expert in Egy...Asli Kala jadu, Black magic specialist in Pakistan Or Kala jadu expert in Egy...
Asli Kala jadu, Black magic specialist in Pakistan Or Kala jadu expert in Egy...baharayali
 
2k Shots ≽ 9205541914 ≼ Call Girls In Sheikh Sarai (Delhi)
2k Shots ≽ 9205541914 ≼ Call Girls In Sheikh Sarai (Delhi)2k Shots ≽ 9205541914 ≼ Call Girls In Sheikh Sarai (Delhi)
2k Shots ≽ 9205541914 ≼ Call Girls In Sheikh Sarai (Delhi)Delhi Call girls
 
Sector 62, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 62, Noida Call girls :8448380779 Model Escorts | 100% verifiedSector 62, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 62, Noida Call girls :8448380779 Model Escorts | 100% verifiedDelhi Call girls
 
Netherlands Players expected to miss UEFA Euro 2024 due to injury.docx
Netherlands Players expected to miss UEFA Euro 2024 due to injury.docxNetherlands Players expected to miss UEFA Euro 2024 due to injury.docx
Netherlands Players expected to miss UEFA Euro 2024 due to injury.docxEuro Cup 2024 Tickets
 
WhatsApp Chat: 📞 8617697112 Birbhum Call Girl available for hotel room package
WhatsApp Chat: 📞 8617697112 Birbhum  Call Girl available for hotel room packageWhatsApp Chat: 📞 8617697112 Birbhum  Call Girl available for hotel room package
WhatsApp Chat: 📞 8617697112 Birbhum Call Girl available for hotel room packageNitya salvi
 
Personal Brand Exploration - By Bradley Dennis
Personal Brand Exploration - By Bradley DennisPersonal Brand Exploration - By Bradley Dennis
Personal Brand Exploration - By Bradley Dennisjocksofalltradespodc
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
UEFA Euro 2024 Squad Check-in Who is Most Favorite.docx
UEFA Euro 2024 Squad Check-in Who is Most Favorite.docxUEFA Euro 2024 Squad Check-in Who is Most Favorite.docx
UEFA Euro 2024 Squad Check-in Who is Most Favorite.docxEuro Cup 2024 Tickets
 
Hire 💕 8617697112 Kasauli Call Girls Service Call Girls Agency
Hire 💕 8617697112 Kasauli Call Girls Service Call Girls AgencyHire 💕 8617697112 Kasauli Call Girls Service Call Girls Agency
Hire 💕 8617697112 Kasauli Call Girls Service Call Girls AgencyNitya salvi
 
Croatia vs Italy Euro Cup 2024 Three pitfalls for Spalletti’s Italy in Group ...
Croatia vs Italy Euro Cup 2024 Three pitfalls for Spalletti’s Italy in Group ...Croatia vs Italy Euro Cup 2024 Three pitfalls for Spalletti’s Italy in Group ...
Croatia vs Italy Euro Cup 2024 Three pitfalls for Spalletti’s Italy in Group ...Eticketing.co
 
Slovenia Vs Serbia UEFA Euro 2024 Fixture Guide Every Fixture Detailed.docx
Slovenia Vs Serbia UEFA Euro 2024 Fixture Guide Every Fixture Detailed.docxSlovenia Vs Serbia UEFA Euro 2024 Fixture Guide Every Fixture Detailed.docx
Slovenia Vs Serbia UEFA Euro 2024 Fixture Guide Every Fixture Detailed.docxWorld Wide Tickets And Hospitality
 

Recently uploaded (20)

Muzaffarpur Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Muzaffarpur Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMuzaffarpur Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Muzaffarpur Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
European Football Icons that Missed Opportunities at UEFA Euro 2024.docx
European Football Icons that Missed Opportunities at UEFA Euro 2024.docxEuropean Football Icons that Missed Opportunities at UEFA Euro 2024.docx
European Football Icons that Missed Opportunities at UEFA Euro 2024.docx
 
Sports Writing (Rules,Tips, Examples, etc)
Sports Writing (Rules,Tips, Examples, etc)Sports Writing (Rules,Tips, Examples, etc)
Sports Writing (Rules,Tips, Examples, etc)
 
Who Is Emmanuel Katto Uganda? His Career, personal life etc.
Who Is Emmanuel Katto Uganda? His Career, personal life etc.Who Is Emmanuel Katto Uganda? His Career, personal life etc.
Who Is Emmanuel Katto Uganda? His Career, personal life etc.
 
JORNADA 6 LIGA MURO 2024TUXTEPECOAXACA.pdf
JORNADA 6 LIGA MURO 2024TUXTEPECOAXACA.pdfJORNADA 6 LIGA MURO 2024TUXTEPECOAXACA.pdf
JORNADA 6 LIGA MURO 2024TUXTEPECOAXACA.pdf
 
Unveiling the Mystery of Main Bazar Chart
Unveiling the Mystery of Main Bazar ChartUnveiling the Mystery of Main Bazar Chart
Unveiling the Mystery of Main Bazar Chart
 
UEFA Euro 2024 Squad Check-in Which team is Top favorite.docx
UEFA Euro 2024 Squad Check-in Which team is Top favorite.docxUEFA Euro 2024 Squad Check-in Which team is Top favorite.docx
UEFA Euro 2024 Squad Check-in Which team is Top favorite.docx
 
Technical Data | Sig Sauer Easy6 BDX 1-6x24 | Optics Trade
Technical Data | Sig Sauer Easy6 BDX 1-6x24 | Optics TradeTechnical Data | Sig Sauer Easy6 BDX 1-6x24 | Optics Trade
Technical Data | Sig Sauer Easy6 BDX 1-6x24 | Optics Trade
 
JORNADA 5 LIGA MURO 2024INSUGURACION.pdf
JORNADA 5 LIGA MURO 2024INSUGURACION.pdfJORNADA 5 LIGA MURO 2024INSUGURACION.pdf
JORNADA 5 LIGA MURO 2024INSUGURACION.pdf
 
Asli Kala jadu, Black magic specialist in Pakistan Or Kala jadu expert in Egy...
Asli Kala jadu, Black magic specialist in Pakistan Or Kala jadu expert in Egy...Asli Kala jadu, Black magic specialist in Pakistan Or Kala jadu expert in Egy...
Asli Kala jadu, Black magic specialist in Pakistan Or Kala jadu expert in Egy...
 
2k Shots ≽ 9205541914 ≼ Call Girls In Sheikh Sarai (Delhi)
2k Shots ≽ 9205541914 ≼ Call Girls In Sheikh Sarai (Delhi)2k Shots ≽ 9205541914 ≼ Call Girls In Sheikh Sarai (Delhi)
2k Shots ≽ 9205541914 ≼ Call Girls In Sheikh Sarai (Delhi)
 
Sector 62, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 62, Noida Call girls :8448380779 Model Escorts | 100% verifiedSector 62, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 62, Noida Call girls :8448380779 Model Escorts | 100% verified
 
Netherlands Players expected to miss UEFA Euro 2024 due to injury.docx
Netherlands Players expected to miss UEFA Euro 2024 due to injury.docxNetherlands Players expected to miss UEFA Euro 2024 due to injury.docx
Netherlands Players expected to miss UEFA Euro 2024 due to injury.docx
 
WhatsApp Chat: 📞 8617697112 Birbhum Call Girl available for hotel room package
WhatsApp Chat: 📞 8617697112 Birbhum  Call Girl available for hotel room packageWhatsApp Chat: 📞 8617697112 Birbhum  Call Girl available for hotel room package
WhatsApp Chat: 📞 8617697112 Birbhum Call Girl available for hotel room package
 
Personal Brand Exploration - By Bradley Dennis
Personal Brand Exploration - By Bradley DennisPersonal Brand Exploration - By Bradley Dennis
Personal Brand Exploration - By Bradley Dennis
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
UEFA Euro 2024 Squad Check-in Who is Most Favorite.docx
UEFA Euro 2024 Squad Check-in Who is Most Favorite.docxUEFA Euro 2024 Squad Check-in Who is Most Favorite.docx
UEFA Euro 2024 Squad Check-in Who is Most Favorite.docx
 
Hire 💕 8617697112 Kasauli Call Girls Service Call Girls Agency
Hire 💕 8617697112 Kasauli Call Girls Service Call Girls AgencyHire 💕 8617697112 Kasauli Call Girls Service Call Girls Agency
Hire 💕 8617697112 Kasauli Call Girls Service Call Girls Agency
 
Croatia vs Italy Euro Cup 2024 Three pitfalls for Spalletti’s Italy in Group ...
Croatia vs Italy Euro Cup 2024 Three pitfalls for Spalletti’s Italy in Group ...Croatia vs Italy Euro Cup 2024 Three pitfalls for Spalletti’s Italy in Group ...
Croatia vs Italy Euro Cup 2024 Three pitfalls for Spalletti’s Italy in Group ...
 
Slovenia Vs Serbia UEFA Euro 2024 Fixture Guide Every Fixture Detailed.docx
Slovenia Vs Serbia UEFA Euro 2024 Fixture Guide Every Fixture Detailed.docxSlovenia Vs Serbia UEFA Euro 2024 Fixture Guide Every Fixture Detailed.docx
Slovenia Vs Serbia UEFA Euro 2024 Fixture Guide Every Fixture Detailed.docx
 

Diagnosing MEF Failure

  • 1. Diagnosing MEF Failures Jim Counts | jcounts18@gmail.com | @jamesrcounts Ihadthisideaonce.wordpress.com
  • 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. What do we already know about MEF?  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. 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.
  • 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. 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. 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. 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. 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. 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. MEF 2 The part “FunnySubtitle” was rejected because the part “FunnySpeaker” could not be satisfied.
  • 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. Getting Satisfaction Mick Jagger just didn’t know enough about MEF
  • 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. 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. References How to Debug and Diagnose MEF Failures, Daniel Plaisted's Blog http://blogs.msdn.com/b/dsplaisted/archi ve/2010/07/13/how-to-debug-and- diagnose-mef-failures.aspx Diagnosing Composition Problems, mef.codeplex.com http://mef.codeplex.com/wikipage?title=D ebugging%20and%20Diagnostics&referrin gTitle=Guide
  • 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?

Editor's Notes

  1. Step0: Run default – no exception. Run MEFx from the command line.
  2. Step2
  3. Show step0, show step1, show approval test