Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 单声道加载外部DLL及其依赖项_C#_.net_Mono - Fatal编程技术网

C# 单声道加载外部DLL及其依赖项

C# 单声道加载外部DLL及其依赖项,c#,.net,mono,C#,.net,Mono,我的行为有严重问题。我的应用程序使用System.Component.Composition加载插件。这些插件放在我的程序的子文件夹中。让我告诉你: +ProgramFolder --Program.exe --ProgramCore.dll -+PluginsFolder --+Plugin1Folder ----Plugin1.dll ----SomeLibrary.dll (it's dependence which is used by Plugin1.dll) ---Plugin2

我的行为有严重问题。我的应用程序使用System.Component.Composition加载插件。这些插件放在我的程序的子文件夹中。让我告诉你:

+ProgramFolder
--Program.exe
--ProgramCore.dll
-+PluginsFolder
--+Plugin1Folder
----Plugin1.dll
----SomeLibrary.dll (it's dependence which is used by Plugin1.dll)
---Plugin2
在本机windows环境中运行时,它运行得非常好。但只要我想在MONO环境中运行它,它就会出错

Could not load file or assembly 'Plugin1' or one of its dependencies. The system cannot find the file specified.
在我的app.config中,我在程序集绑定部分放置了这样的探测

<probing privatePath="PluginsFolder/Plugin1Folder"/>

允许我的程序在这里搜索dll,但MONO似乎忽略了这一部分。如何在MONO中工作?

我找到了解决方案。这是我第二次看到MONO的工作方式完全不同于本机Windows环境。我不得不重写这个方法,现在,它在两种环境下都能正常工作

这是一个使用appropiate方法的类:

class ModulesLoader
{
    [ImportMany(typeof(ISchedulable))]
    public IEnumerable<ISchedulable> Modules { get; set; }
    private string dir;
    private string name;

    public ModulesLoader(string directory, string name)
    {
        Assert.ThrowIfEmptyString(directory);
        Assert.ThrowIfNull (name);
        this.dir = directory;
        this.name = name;
    }

    public void Load()
    {
        var catalog = new AggregateCatalog();
        var assembly = GetType ().Assembly; //Assembly of our executable program
        var dllCatalog = new AssemblyCatalog (assembly);
        catalog.Catalogs.Add(dllCatalog);
        var pluginAssembly = Assembly.LoadFrom (Path.Combine (dir, name)); //We have to explicit point which assembly will be loaded
        var pluginCatalog = new AssemblyCatalog (pluginAssembly); //pass it to catalog to let framework know each vital information about this .dll
        catalog.Catalogs.Add (pluginCatalog);
        CompositionContainer container = new CompositionContainer(catalog);
        container.ComposeParts(this); //and it works!
    }
}
还有第二个问题。System.Configuration dll未标记为“Copy local”,MONO抛出InvalidProgrammeException,通知方法体为空。最后,我设法使它工作xD

编写平台无关软件有时真的很奇怪