Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement MEF DirectoryCatalog #17212

Closed
marcusien opened this issue May 6, 2016 · 7 comments
Closed

Implement MEF DirectoryCatalog #17212

marcusien opened this issue May 6, 2016 · 7 comments

Comments

@marcusien
Copy link

@marcusien marcusien commented May 6, 2016

Hi,

Really need to got back the feature of MEF to get all dlls from a directory via DirectoryCatalog.
Is there something done in that way ?

Thank you

@AlexGhiondea
Copy link
Member

@AlexGhiondea AlexGhiondea commented Nov 23, 2016

@marcusien is there any workaround you can use for this?

@AlexGhiondea AlexGhiondea removed their assignment Nov 23, 2016
@bradbart
Copy link

@bradbart bradbart commented Nov 28, 2016

I found the following code snippet is functionality equivalent to the usage of directory catalogs:

            // Find and load all the DLLs in the folder 
            var assemblies = Directory.GetFiles(directory, "*.dll")
              .Select(path => AssemblyLoadContext.Default.LoadFromAssemblyPath(path))
              .Where(x => x != null);

            // Add the loaded assemblies to the container 
            var configuration = new ContainerConfiguration()
              .WithAssemblies(assemblies)
              .WithAssembly(this.GetType().GetTypeInfo().Assembly);
            return configuration.CreateContainer(); 

I think this approach works well, though it would be nice to have an extension method on the ConfigurationContainer that does this. So instead of WithAssemblies, use WithAssembliesFromDirectory() which loads the assemblies and adds them to them to the configuration.

@AlexGhiondea
Copy link
Member

@AlexGhiondea AlexGhiondea commented Nov 29, 2016

@bradbart thanks for adding the workaround to the issue.

Since we don't currently have any plans to bring back more APIs for MEF and since we have an acceptable workaround I am closing this.

@AceHack
Copy link

@AceHack AceHack commented Apr 24, 2018

@bradbart how do you avoid the dependent assembly issue and System.IO.FileNotFoundException error when calling LoadFromAssemblyPath?

@bradbart
Copy link

@bradbart bradbart commented Jun 12, 2018

Hi @AceHack can elaborate on the nature of the issue you are encountering? I didn't notice any IO Exceptions occur when I ran this in my project.

@AceHack
Copy link

@AceHack AceHack commented Jun 12, 2018

@bradbart load things that have dependencies or themselves in the nuget/package cache instead of the bin folder and you should see the issue.

@bradbart
Copy link

@bradbart bradbart commented Jul 18, 2018

I suspect that this issue is caused by the application not having permissions to the directory outside of its bin. Doing a ReadFile from that directory should confirm whether that is the issue. Also, might be worth double checking the path if using a relative reference to the directory. Outside of that, I'm not sure why that exception would occur.

@msftgits msftgits transferred this issue from dotnet/corefx Jan 31, 2020
@msftgits msftgits added this to the 2.0.0 milestone Jan 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
6 participants
You can’t perform that action at this time.