This project has moved. For the latest updates, please go here.

Error in MetadataView

Jul 17, 2009 at 4:11 PM

I'm having a problem with MEF composition in VS 2010 Beta 1 which I have just converted from Preview 4. After exploring it awhile, it's either a lack of understanding on my part, or a bug, so I've explained it in rather excruciating detail. It appears that I have a part that appears to meet the requested interface, But I get an error saying it can't be created. I could really use some help on this as it is currently blocking.

The error message is (Full message below):

  Message=Cannot create a MetadataView of metadataViewType 'AppVenture.Common.IWrapperCompositionRules'.

The code being called when the error occurs is when the IEnumerable is evaluated on the last line of this snippet:

var exports = (from e in _processExports
   where e.MetadataView.TemplateStyle == TemplateStyle.Process &&
   e.MetadataView.Group == _group.Name
   select e);
foreach (var export in exports)

where _processExports is created by

this._processExports = this._container.GetExports<IProcessWrapper, IWrapperCompositionRules>();

I have one satisfying Imports whose signatures is:

   [TemplateWrapperCompositionData(Extensions = "t4", TemplateStyle = TemplateStyle.File, Priority = Utilities.DefaultPriority)]
   public class TemplateWrapperT4 : TemplateWrapper

where TemplateWrapper implements IProcessWrapper. TemplateCompositionDataAttribute has the signature

   [TemplateWrapperCompositionData(Extensions = "t4", TemplateStyle = TemplateStyle.File, Priority = Utilities.DefaultPriority)]
   public class TemplateWrapperT4 : TemplateWrapper

where TemplateWrapperCompositionRulesAttribute has the signature:

[MetadataAttribute, AttributeUsage(AttributeTargets.Class)]
public class TemplateWrapperCompositionDataAttribute : ProcessWrapperCompositionAttribute, IWrapperCompositionRules

I'm using a custom catalog but I don't think it is relevant. I can, or course, provide it.

I grabbed all the matching exports using

         var test = this._container.GetExports<IProcessWrapper>();
         foreach (var pair in test.First().Metadata)
            Console.Write(pair.Key.GetType().Name + " : " + pair.Key.ToString() + " - ");
            if (pair.Value == null)
            { Console.WriteLine("Null"); }
            { Console.WriteLine(pair.Value.GetType().Name + " : " + pair.Value.ToString()); }

and the resulting metadata is (to compare with the interface):

String : Extensions - String : t4
String : Group - Null
String : Name - Null
String : TemplateStyle - TemplateStyle : File
String : Id - Null
String : Priority - Int32 : -1
String : ExportTypeIdentity - String : AppVenture.Common.IProcessWrapper
String : System.ComponentModel.Composition.CreationPolicy - CreationPolicy : NonShared

IwrapperCompositionRules is:

  public interface IWrapperCompositionRules : IProcessWrapperComposition
      // Properties
      string Extensions { get; set; }
      string Group { get; set; }
      string Name { get; set; }
      TemplateStyle TemplateStyle { get; set; }

Here's the full message:

System.InvalidOperationException was unhandled
  Message=Cannot create a MetadataView of metadataViewType 'AppVenture.Common.IWrapperCompositionRules'.
       at System.ComponentModel.Composition.MetadataViewProvider.GetMetadataView[TMetadataView](IDictionary`2 metadata)
       at System.ComponentModel.Composition.Export`2.get_MetadataView()
       at AppVenture.TemplateHarness.TemplateHarness.<>c__DisplayClassc.<GatherProcesses>b__b(Export`2 e) in D:\Users\Kathleen\Current Projects\CodeGen\AppVentureCommunityGenerator - 2010\T4Host\Source\CSharp\TemplateHarness\TemplateHarness.cs:line 155
       at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
       at AppVenture.TemplateHarness.TemplateHarness.GatherProcesses(IGenerationGroup _group, IList`1 items) in D:\Users\Kathleen\Current Projects\CodeGen\AppVentureCommunityGenerator - 2010\T4Host\Source\CSharp\TemplateHarness\TemplateHarness.cs:line 158
       at AppVenture.TemplateHarness.TemplateHarness.RunGroups(IEnumerable`1 groups, String outerNamespace, String outerTemplatePath, String outerOutputPath) in D:\Users\Kathleen\Current Projects\CodeGen\AppVentureCommunityGenerator - 2010\T4Host\Source\CSharp\TemplateHarness\TemplateHarness.cs:line 245
       at AppVenture.TemplateHarness.TemplateHarness.Run(IGenerationDefinition generationDefinition) in D:\Users\Kathleen\Current Projects\CodeGen\AppVentureCommunityGenerator - 2010\T4Host\Source\CSharp\TemplateHarness\TemplateHarness.cs:line 226
       at AppVenture.TemplateHarness.TemplateHarnessHelpers.ExecuteGeneration() in D:\Users\Kathleen\Current Projects\CodeGen\AppVentureCommunityGenerator - 2010\T4Host\Source\CSharp\TemplateHarness\TemplateHarnessHelpers.cs:line 102
       at AppVenture.CmdGeneration.GenerationRun.Run() in D:\Users\Kathleen\Current Projects\CodeGen\AppVentureCommunityGenerator - 2010\T4Host\Source\UserInterfaces\CmdGeneration\Program.cs:line 185
       at AppVenture.CmdGeneration.Program.Main(String[] args) in D:\Users\Kathleen\Current Projects\CodeGen\AppVentureCommunityGenerator - 2010\T4Host\Source\UserInterfaces\CmdGeneration\Program.cs:line 46
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: System.InvalidOperationException
       Message=Method 'set_Id' does not have a method body.
            at System.Reflection.Emit.TypeBuilder.CreateTypeNoLock()
            at System.Reflection.Emit.TypeBuilder.CreateType()
            at System.ComponentModel.Composition.MetadataViewGenerator.GenerateInterfaceViewProxyType(Type viewType)
            at System.ComponentModel.Composition.MetadataViewGenerator.GenerateView(Type viewType)
            at System.ComponentModel.Composition.MetadataViewProvider.GetMetadataView[TMetadataView](IDictionary`2 metadata)

Jul 17, 2009 at 5:47 PM

Kathleen, does your metadata view have setters, or only gettes?


Jul 17, 2009 at 5:48 PM

Forget it, I see it, it does have getters and setters. Metadata views only work if the interface has getters only, thus IWrapperCompositionRules need to pure getters.


Jul 17, 2009 at 7:03 PM

Just to let anyone reading know... This fixed the problem. Removing the setters from the interface did the trick.

Thank you again for your help!