title: ASP.NET MVC 3.0 + Microsoft.Web.Mvc 3.0 + MEF compatibility
body: <p>When i have an reference to Microsoft.Web.Mvc.dll in my ASP.NET MVC 3.0 project i am getting an error when i am building <code>DirecotryCatalog</code> in my <code>CustomDependencyResolver</code>.       </p>
  
  <pre><code>string path = HostingEnvironment.MapPath("~/bin");
   var container = new DirectoryCatalog(path); 
  </code></pre>
  
  <p>Then i looked at <code>container.Parts.Results View.LoadedExeptions</code> and it is saying:</p>
  
  <p><em><strong>+[0]{"Method 'GetControllerSessionBehavior' in type 'Microsoft.Web.Mvc.MvcDynamicSessionControllerFactory' from assembly 'Microsoft.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=null' does not have an implementation.":"Microsoft.Web.Mvc.MvcDynamicSessionControllerFactory"}    System.Exception {System.TypeLoadException}</em></strong></p>
  
  <p><em><strong>+[1]{"Method 'GetControllerSessionBehavior' in type 'Microsoft.Web.Mvc.Resources.ResourceControllerFactory' from assembly 'Microsoft.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=null' does not have an implementation.":"Microsoft.Web.Mvc.Resources.ResourceControllerFactory"}  System.Exception {System.TypeLoadException}</em></strong></p>
  
  <p>Just for test i removed reference to Microsoft.Web.Mvc.dll(physically removing it from bin direcotry) and then everything just fine. Looks like Microsoft.Web.Mvc.dll couldn't be loaded.</p>
  
  <p>Is there any work around? </p>
  
  <p>I found similar issue here <a href="http://forums.asp.net/t/1622399.aspx?MVC+3+RC.+Where+is+the+Futures+Assembly%3F" rel="nofollow">http://forums.asp.net/t/1622399.aspx?MVC+3+RC.+Where+is+the+Futures+Assembly%3F</a> the answer saying that MVC 3 Beta Futures + MVC 3 RC Runtime = are incompatible. But i am using both RTM versions:</p>
  
  <p><strong>Microsoft.Web.Mvc</strong> Runtime version v4.0.30319, Version 3.0.0.0 (downloaded from here <a href="http://mvccontrib.codeplex.com/releases/view/59313" rel="nofollow">http://mvccontrib.codeplex.com/releases/view/59313</a>)</p>
  
  <p><strong>System.Web.Mvc</strong> Runtime version v4.0.30319, Version 3.0.0.0</p>
  
  <p><strong>UPDATED:</strong></p>
  
  <p>As Darin Dimitrov menthioned in his answer i need to exclude System.Web.Mvc from scanning process.
  Here is the way how to do that:</p>
  
  <pre><code>public class SafeDirectoryCatalog : ComposablePartCatalog
  {
      private readonly AggregateCatalog _catalog;
  
      public SafeDirectoryCatalog(string directory)
      {
          var files = Directory.EnumerateFiles(directory, "*.dll", SearchOption.AllDirectories);
  
          _catalog = new AggregateCatalog();
  
          foreach (var file in files)
          {
              try
              {
                  var asmCat = new AssemblyCatalog(file);
  
                  //Force MEF to load the plugin and figure out if there are any exports
                  // good assemblies will not throw the RTLE exception and can be added to the catalog
                  if (asmCat.Parts.ToList().Count &gt; 0)
                      _catalog.Catalogs.Add(asmCat);
              }
              catch (ReflectionTypeLoadException)
              {
              }
          }
      }
      public override IQueryable&lt;ComposablePartDefinition&gt; Parts
      {
          get { return _catalog.Parts; }
      }
  }
  </code></pre>