0
votes

I have a factory class which imports a list of IOperation types. I get the following error when I try and resolve the factory class:

Resulting in:

Cannot activate part 'Message36Operation'. Element: Message36Operation --> Message36Operation --> DirectoryCatalog (Path=".\")

Resulting in:

Cannot get export 'Message36Operation (ContractName="IOperation")' from part 'Message36Operation'. Element: Message36Operation (ContractName="IOperation") --> Message36Operation --> DirectoryCatalog (Path=".\")

Resulting in:

Cannot set import 'OperationsFactory.Operations (ContractName="IOperation")' on part 'OperationsFactory'. Element: OperationsFactory.Operations (ContractName="IOperation") --> OperationsFactory --> AssemblyCatalog (Assembly="RmiToODKMessanger, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null")

Here's what I have:

[Export(typeof(OperationsFactory))]
public class OperationsFactory
{
    [ImportMany(typeof(IOperation))]
    private IEnumerable<IOperation> Operations { get; set; }
 }

public interface IOperation
{

}

public abstract class BaseRmiOperation : IOperation
{

}

[Export(typeof(IOperation))]
public class Message36Operation : BaseRmiOperation, IOperation
{

}

The exception is thrown will I try and resolve an instance of the factory.

I can get this to work if I remove the abstract class.

Any ideas,

Thanks,

Ken

** Update:

Below is the BaseRmiOperation class. I'm instantiating a few classes in the cstor and that's it.

I forgot to mention the structure of the app previously.

  • CG.App: contains OperationsFactory and bootstrapper class for MEF.
  • CG.Plugins : Contains various IOperation implementations such as Message36Operation and the BaseRmiOperation abstract class
  • CG.Common : Contains IOperation interface. This assembly is referenced by both CG.App and CG.Plugins

The CG.App.Bootstrapper class loads the plugins from bin/plugins.

public abstract class BaseRmiOperation : IOperation
{

    protected SettingsManager _settingsManager;
    protected RmiMessenger _messenager;
    protected ILogger _logger;
    protected TagManager _tagManager;

    protected Environments _rmiEnvironment;
    protected string _msgSource;
    protected string _emp_id;

    public BaseRmiOperation()
    {

        this._settingsManager = new SettingsManager();
        this._messenager = new RmiMessenger(null, null);
        this._tagManager = new TagManager(); // pass ILogger 
        //this._logger = logger;

        // pulls the rmi_env and a few other settings from
        // winCC.
        PopulateRmiSettings();

    }


    public abstract ExitCodes Execute(object[] data);

    public abstract string Description { get;  }

    public abstract string Alias { get;  }
1
I've not managed to replicate your issue, when I rebuild this, it works fine pastebin.com/Z7Nq51b2. Can you put the full code for your abstract class. I would imagine you might be trying to perform imports on it, using [Import] instances?Matthew Abbott
Thanks for the help Matthew. I've posted the code for the abstract class. I have no imports. Perhaps the assembly structure is the problem?Lance
Sorted the problem. Silly mistake. The TagManager assembly was not present in the /bin folder and was causing the BaseRmiOperation cstor to crash. A breakpoint at the start of the cstor was never being called, it always crashed on the line to resolve the OperationFactory. Figured it out by going back to basics and adding functionality one line at a time. Thanks.Lance

1 Answers

1
votes

Sorted the problem. Silly mistake. The TagManager assembly was not present in the /bin folder and was causing the BaseRmiOperation cstor to crash. A breakpoint at the start of the cstor was never being called, it always crashed on the line to resolve the OperationFactory. Figured it out by going back to basics and adding functionality one line at a time. Thanks.