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 #8348

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

Comments

Projects
None yet
7 participants
@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

This comment has been minimized.

Show comment
Hide comment
@AlexGhiondea

AlexGhiondea Nov 23, 2016

Member

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

Member

AlexGhiondea commented Nov 23, 2016

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

@AlexGhiondea AlexGhiondea removed their assignment Nov 23, 2016

@bradbart

This comment has been minimized.

Show comment
Hide comment
@bradbart

bradbart 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.

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

This comment has been minimized.

Show comment
Hide comment
@AlexGhiondea

AlexGhiondea Nov 29, 2016

Member

@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.

Member

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.

@karelz karelz modified the milestones: Future, 1.2.0 Dec 3, 2016

@AceHack

This comment has been minimized.

Show comment
Hide comment
@AceHack

AceHack Apr 24, 2018

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

AceHack commented Apr 24, 2018

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

@bradbart

This comment has been minimized.

Show comment
Hide comment
@bradbart

bradbart 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.

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

This comment has been minimized.

Show comment
Hide comment
@AceHack

AceHack 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.

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

This comment has been minimized.

Show comment
Hide comment
@bradbart

bradbart 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.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment