photo_tom
photo_tom

Reputation: 7342

Unable to Compile with ImportMany attribute

As to total MEF newbie, I'm having a problem with my first test of MEF. My problem code is below-

using System;
using GlobalInterfaces;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.ComponentModel.Composition;
using System.ComponentModel.Composition.Hosting;

namespace GlobalInterfacesUnitTest
{
    [TestClass]
    public class GlobalInterfacesUnitTest
    {
        [TestMethod]
        public void TestMethod1()
        {
            [ImportMany(AllowRecomposition = true)]
            Lazy<IComponentGui, IImportComponentGuiCapabilites>[] Senders {get;set;}
        }
    }
}

The problem that I cannot get the compiler to find "ImportMany" attribute. I've checked the references against several demos and copied their references and still have the same problem. I cannot see what I'm overlooking. I am using VS2010 / Net4.0.

Upvotes: 0

Views: 244

Answers (1)

Andrey
Andrey

Reputation: 60065

You can't define properties inside method. Move it out to class. Try:

[TestClass]
public class GlobalInterfacesUnitTest
{
    [ImportMany(AllowRecomposition = true)]
    Lazy<IComponentGui, IImportComponentGuiCapabilites>[] Senders {get;set;}

    [TestMethod]
    public void TestMethod1()
    {

    }
}

Upvotes: 4

Related Questions