MEF Download Plugins from Public Shared Folder

Tearing my hair, trying to understand why I have such a problem, so I hope someone can help.

I have a program that uses MEF to download plugins. I would like the client and server part of the system to be able to use the same plugin store that will be located on the server.

My problem is that when I set the plugin location to " C:\Users\Administrator\Desktop\ClientPlugins ", the plugin loads fine. If I change the location to " \\XRP-SERVER\Users\Administrator\Desktop\ClientPlugins ", the plugin will not load.

When I enter " \\XRP-SERVER\Users\Administrator\Desktop\ClientPlugins " in Windows Explorer, the location will be found, and there will be a dll plugin.

Please help someone.

Let me know if you need more information.

As suggested, I tried changing the configuration to include the following, but this did not fix the problem ....

  <?xml version="1.0" encoding="utf-8" ?> <configuration> <runtime> <loadFromRemoteSources enabled="true"/> </runtime> 

Yours faithfully

Ash

+8
c # mef
source share
4 answers

Yesterday I ran into this problem and narrowed down the problem before MEF loads assemblies. When you create a DirectoryCatalog, it takes turns creating the AssemblyCatalogs collection. Each AssemblyCatalog performs:

  AssemblyName assemblyName = AssemblyName.GetAssembly(); Assembly.Load(assemblyName); 

Calling Assembly.Load throws a sandbox exception (for some reason I can’t explain yet), and therefore no parts have been found since it silently catches the error.

The funny thing is that calling Assembly.LoadFrom(<pathToYourDll>) to return Assembly works fine (no exception is thrown). Combine this with the overloaded AssemblyCatalog constructor, which takes Assembly as its input, and you have a workaround!

So instead of using DirectoryCatalog I list all the DLLs in the path and iteratively create the AssemblyCatalog and add it to my CompositionContainer .

Note. I use the flag loadFromRemoteSources = "true" in my App.Config, and this is necessary, otherwise it always fails.

Hope this helps

+2
source share

Security policies typically disable downloading remote code (which is a collection in an external location).

You can try the following configuration change:

 <runtime> <loadFromRemoteSources enabled="true"/> </runtime> 

Another thing to keep in mind is when you copy files from network locations, they will usually have the Zone indicated in their alternate data stream. In Explorer, this can be removed using the "Unblock" command when viewing file properties.

Alternatively, you can programmatically remove the Zone from an alternate data stream, as shown here on Mike Hadlow's blog .

+8
source share

Just to clarify the work of the sebd responder.

Here is the final code that I used.

 string[] files = Directory.GetFiles(ClientPluginStore, "*.dll", SearchOption.TopDirectoryOnly); AggregateCatalog aggCat = new AggregateCatalog(); aggCat.Catalogs.Add(catalog); foreach ( string file in files ) { Assembly ass = Assembly.LoadFrom(file); AssemblyCatalog assCat = new AssemblyCatalog(ass); aggCat.Catalogs.Add(assCat); } _container = new CompositionContainer(aggCat); 
+2
source share

Try using System.IO.Path.PathSeparator instead of \?

Or can the file be first uploaded to the client location?

I am not very sure of them, but I would try.

0
source share

All Articles