This project has moved and is read-only. For the latest updates, please go here.

Exported method with a ref formal argument

Oct 13, 2008 at 8:35 PM

MemberInfoComposableItem.GetDelegate throws an exception during the call to container.Compose() when the exported method (and the respective imported delegate) contains a formal argument with the ref type modifier.

Here is a minimalist example. (The "direct call" to ExportedMethod(ref int i) was just added to demonstrate that it is a valid delegate call.)

Can you please let me know if this a known limitation, a misunderstanding on my part, or a bug that I should report.



using System;
using System.ComponentModel.Composition;
using System.Reflection;

class Program

    public delegate void A1ByRef<T1>(ref T1 x);

    public A1ByRef<int> ImportedMethod { get; set; }

    public void Run()
        int i = 123;
        A1ByRef<int> DirectDelegate = ExportedMethod;
        DirectDelegate(ref i); // Valid delegate call
        Compose();  // Exception      
        ImportedMethod(ref i);

    public void ExportedMethod(ref int i)

    private void Compose()
        AttributedAssemblyPartCatalog catalog = new AttributedAssemblyPartCatalog(Assembly.GetExecutingAssembly());
        var container = new CompositionContainer(catalog.CreateResolver());

    static void Main(string[] args)
        var p = new Program();

Oct 14, 2008 at 12:48 AM

Hi Sebastien,

You're right in your assumption, this should be a valid scenario. Please log an issue through the Issue Tracker and we'll make sure to track internally.