TypeMismatchBetweenImportAndExport : Error : Type mismatch on contract

Oct 9, 2009 at 6:00 AM

 

3)Hi, this is a stupid error that i can not get hold of. If anyone has any idea, please help :(

Here is the setup:

 

1) In project 1 , I describe the interface as the following: 

 

 

namespace Switchboard.ServiceInterfaces.LogService

{

    public interface ILogService

    {

        void InitializeLogger(String configFileLocation);

        void WriteLog(ELogLevel logLevel, String log);



    }

}

2) in project 2 , i implement that interface and export it:

 

 

namespace LoggingService

{



    [Export(typeof(ILogService))]

    public class LogWriter :  ILogService

    {


	public void InitializeLogger(string configFileLocation)
        {
           // throw new System.NotImplementedException();
        }

        public void WriteLog(ELogLevel logLevel, string log)
        {
           // throw new System.NotImplementedException();
        }
    }
}

3) finally , in project1 again , i try to import that class like this:

 

 

 

public class Common

    {



         [Import(typeof(ILogService))]

         public ILogService LogServ { get; set; }

	 public Common()
        {
            CompleteImports();
          //  LogServ.InitializeLogger(GetLogConfigLocation());
        }

        private void CompleteImports()
        {
            var catalog = new AggregatingComposablePartCatalog();
            catalog.Catalogs.Add(new DirectoryPartCatalog(@"D:\Work\Switchboard\Sourcode\Current Version\Switchboard\bin\Debug\Plugins\"));
            var container = new CompositionContainer(catalog.CreateResolver());
            container.AddPart(this);
            try
            {
                container.Compose();
            }
            catch (CompositionException compositionException)
            {
                Console.WriteLine(compositionException.Message);
            }
        }

    }
}

Which composes with an error:

The composition produced 1 composition issues. The first few issues of severity level 'error' are provided below. Review the Issues collection for more detailed information.
CM:TypeMismatchBetweenImportAndExport : Error : Type mismatch on contract 'Switchboard.ServiceInterfaces.LogService.ILogService' between an export of type 'LoggingService.LogWriter' and import of type 'ILogService'.


But In step two , you can see I am exporting of type ILogService through these two lines: 

 
 [Export(typeof(ILogService))]

 public class LogWriter :  ILogService


Does anyone know why is this happening?

   

Regards,
Shrouk Khan

 

 

 

Oct 9, 2009 at 6:48 AM

hi ,

ok i found the part that was causing the issue:

 

  void WriteLog(ELogLevel logLevel, String log);

Where ELogLevel is an enum declared in the same namespace as the interface ILogService. 
So if I remove reference to that enum , then it works!

But why does this happen?
Developer
Oct 9, 2009 at 11:36 PM

That seems strange I wouldn't have expected the Enum to cause this sort of problem.

I did notice that you are using a pretty old version of MEF have you considered moving up the the latest preview 7.