Unloading AppDomain - c#

Is there a way to unload parent AppDomain?
I am trying to load a different version of an assembly in my new AppDomain, but it keeps loading the version from the parent domain. When I am loading the assembly in the new AppDomain I am showing the correct path.
Or maybe there is another way I can do that?
Thanks in advance.
EDIT
AppDomain MailChimpDomain = AppDomain.CreateDomain("MailChimpDomain");
string path = AppDomain.CurrentDomain.BaseDirectory + "ServiceStack_V3\\ServiceStack.Text.dll";
MailChimpDomain.Load(AssemblyName.GetAssemblyName(path));
EDIT2
Code 2:
var MailDom = AppDomain.CreateDomain("MailChimpDomain");
MailDom.AssemblyLoad += MailDom_AssemblyLoad;
MailDom.AssemblyResolve += new ResolveEventHandler(MailDom_AssemblyResolve);
MailDom.DoCallBack(() =>
{
string name = #"ServiceStack.Text.dll";
var assembly = AppDomain.CurrentDomain.Load(name);
string name2 = #"MailChimp.dll";
var assembly2 = AppDomain.CurrentDomain.Load(name2);
//mailChimp object with API key found in mailChimp profile
MailChimp.MailChimpManager mc = new MailChimp.MailChimpManager("111111111111222f984b9b1288ddf6f0-us1");
//After this line there are both versions of ServiceStack.Text Assembly
MailChimp.Helper.EmailParameter em = new MailChimp.Helper.EmailParameter();
em.Email = strEmailTo;
//Creating email parameters
string CampaignName = "Digest for " + strEmailTo + " " + DateTime.Now.ToShortDateString();
MailChimp.Campaigns.CampaignCreateOptions opt = new MailChimp.Campaigns.CampaignCreateOptions();
opt.ListId = "l338dh";
opt.Subject = strSubject;
opt.FromEmail = strEmailFrom;
opt.FromName = strNameFrom;
opt.Title = CampaignName;
//creating email content
MailChimp.Campaigns.CampaignCreateContent content = new MailChimp.Campaigns.CampaignCreateContent();
content.HTML = strEmailContent;
//Creating new email and sending it
MailChimp.Campaigns.CampaignFilter par = null;
MailChimp.Campaigns.CampaignSegmentOptions SegOpt = null;
MailChimp.Campaigns.CampaignTypeOptions typeOpt = null;
mc.CreateCampaign("regular", opt, content, SegOpt, typeOpt);
MailChimp.Campaigns.CampaignListResult camp2 = mc.GetCampaigns(par, 0, 5, "create_time", "DESC");
foreach (var item in camp2.Data)
{
if (item.Title == CampaignName)
{
mc.SendCampaign(item.Id);
break;
}
}
});
static Assembly MailDom_AssemblyResolve(object sender, ResolveEventArgs args)
{
byte[] rawAssembly = File.ReadAllBytes(Path.Combine(path, args.Name));
return Assembly.Load(rawAssembly);
}

What your code actually does is it loads assembly to your parent domain. If you want to load assembly into child domain you have to do it from inside child domain. This is kind of chicken-egg problem, because the parent assembly (which loads child assembly into child domain) has to be loaded into your child domain as well in order to be executed.
Assuming simple example that you have console application and assembly called MyAssembly.dll it can be done like this:
static void Main(string[] args) {
var domain = AppDomain.CreateDomain("MailChimpDomain");
domain.AssemblyResolve +=new ResolveEventHandler(domain_AssemblyResolve);
domain.DoCallBack(() => {
string path = #"MyAssembly.dll";
var assembly = AppDomain.CurrentDomain.Load(path);
// to do something with the assembly
var type = assembly.GetType("MailChimp.MailChimpManager");
var ctor = type.GetConstructor(new[] { typeof(string) });
var mc = ctor.Invoke(new object[] { "111111111111222f984b9b1288ddf6f0" });
});
}
static Assembly domain_AssemblyResolve(object sender, ResolveEventArgs args) {
byte[] rawAssembly = File.ReadAllBytes(Path.Combine(#"c:\MyAssemblyPath", args.Name));
return Assembly.Load(rawAssembly);
}
In this case child domain has same root directory for resolving assemblies as parent domain (and thus it can execute the code which loads "MyAssembly.dll").
If the code working with reflection is longer than this, you may consider using bootstrapper instead.
I.E. you create new library called MyBootstrapper.dll, you'll reference directly version of ServiceStack.Text.dll and MailChimp.dll you like from MyBootstrapper.dll, and you'll create bootstrap class - lets call it Bootstrapper that will be static and will have single public static method called Run that will do dirty work.
Then inside DoCallBack() method you'll call this bootstrapper instead.
string path = #"MyBootstrapper.dll";
var assembly = AppDomain.CurrentDomain.Load(path);
// to do something with the assembly
var type = assembly.GetType("MyBootstrapper.Bootstrapper");
var method = type.GetMethod("Run", BindingFlags.Static);
method.Invoke(null, null);
// or if the Run method has one parameter of "string" type
var method = type.GetMethod("Run", BindingFlags.Static, Type.DefaultBinder, new[] { typeof(string) }, null);
method.Invoke(null, new object[] { "Parameter to run" });

No, you may not unload the default AppDomain or any assemblies loaded in the default AppDomain.
What you can do, however, is load both versions of the ServiceStack assembly in two child domains. You should be able to unload either of them. However, using types from these domains may prove more difficult than usual. You'll have to do it via remoting.
Given the overhead imposed by this, you should consider using only one version of that assembly (even if this means adapting part of your app, the one that runs in the default domain).

Related

How to use dynamically linked dll in c#

I imported the taglib-sharp dll (that had been copied to the bin/debug folder of my project) in my C# application and then used types and methods from the library in the following way:
using TagLib;
private void method()
{
TagLib.File file = TagLib.File.Create("C:\\temp\\some.mp3");
TagLib.Tag tag = file.GetTag(TagLib.TagTypes.Id3v2);
}
Now I want to link the dll dynamically. How can I implement the same functional in this case?
That, what I've tried:
using System.Reflection
private void method()
{
Assembly TagLib = Assembly.Load("taglib-sharp");
Type TagLibFile = TagLib.GetType("File");
dynamic LibFile = Activator.CreateInstance(TagLibFile);
TagLibFile file = LibFile.Create("c:\\temp\\some.mp3");
}
In this implementation, VisualStudio says that I can't use the tagLibFile variable as a type. I supposed that when I get a type from dll, I will be able to create variables of this type.
By the way, is this approach is correct?
P.S. Also, I tried to use the invoke method, but I was not sure what object I should pass as a first argument.
UPD
Based on #nawfal's awnser below, I've got the following working code:
using System.Reflection
private void method()
{
Assembly TagLib = Assembly.Load("taglib-sharp");
// get the File type
var fileType = TagLib.GetType("TagLib.File");
// get the overloaded File.Create method
var createMethod = fileType.GetMethod("Create", new[] { typeof(string) });
// get the TagTypes method that contains Id3v2 field
Type tagTypes = TagLib.GetType("TagLib.TagTypes");
// get the overloaded File.GetTag method
var getTagMethod = fileType.GetMethod("GetTag", new[] {tagTypes});
// obtain the file
dynamic file = createMethod.Invoke(null, new[] { "C:\\temp\\some.mp3" });
// obtain the Id3v2 field value
FieldInfo Id3TagField = tagTypes.GetField("Id3v2");
var Id3Tag = Id3TagField.GetValue(tagTypes);
// obtain the actual tag of the file
var tag = getTagMethod.Invoke(file, new[] { Id3Tag });
}
You should be doing something like this:
private void method()
{
var assembly = Assembly.Load("taglib");
var type = assembly.GetType("namespace.File"); // namespace qualified class name
// assuming you only have one Create method, otherwise use reflection to resolve overloads
var method = type.GetMethod("Create");
dynamic file = method.Invoke(null, new[] { "C:\\temp\\some.mp3" }); // null for static methods
var tag = file.GetTag(TagLib.TagTypes.Id3v2); // not sure if you can pass those params,
// may be do reflection to get them too
}
Kindly rethink if you want it to be dynamic. If you can reference the dll then you can still get the benefits of strong typing.
Save it as object.
object file = LibFile.Create(fi.FullName);
Should work.
Dynamic loading dlls works much different.

After Unloading AppDomain all assemblies are released EXCEPT ONE

So, after doing a ton of research on how to sandbox a c# script compiler so that the assemblies being loaded are only loaded into the sandbox AppDomain and not my primary AppDomain, I have run into the problem where all of the dll's I created are unloaded upon unloading the sandbox AppDomain EXCEPT FOR ONE. That one is from a script that looks like:
return new Func<List<int>,int>
(
(list) =>
{
var total = 0;
foreach (int i in list)
{
total += i;
}
return total;
}
);
Now what happens with the returns from the scripts is that they are all eventually returned in a dictionary to the primary AppDomain. The rest of the scripts all return simple serializable objects or primitives and as I said all of their assemblies unload correctly and I am able to delete them with the primary domain still active. Is it possible that this particular return has to "pass" back the creating assembly to the primary AppDomain because its value is a Func? Is there no way around this?
The reason I have the sandbox in the first place is so that after a set of scripts runs I can dispose of the object that executed them and that dispose method unloads the sandbox domain and deletes all of the created assemblies. I want to be able to use this in a constantly running environment like a web server where a build up of assemblies is problematic and currently, every time a script set runs with a return of a Func, I am going to have a lingering assembly. I would rather not have an asterisk next to the documentation of using this library, so any ideas would be welcome.
For reference, here is my code that compiles the script:
var provider = new CSharpCodeProvider(new Dictionary<string, string>() { { CompilerOptionName, CompilerOptionVersion } });
var compilerParams = new CompilerParameters { GenerateExecutable = false, GenerateInMemory = false };
compilerParams.ReferencedAssemblies.AddRange(References);
compilerParams.TempFiles = new TempFileCollection(BinPath);
compilerParams.OutputAssembly = Path.Combine(BinPath,
Utilities.AssemblyPrefix + ProfigurationExe.Profiguration.ID + "_" + Action.ID + "_Script" + Utilities.DllExt);
// If no object is returned by user code, enter in a return null to satisfy returning an object for
// default code template. If they do have a return that will return first.
Code = Code + ReturnNull;
var parameterString = BuildParameterString();
parameterString = !String.IsNullOrEmpty(parameterString) ? ", " + parameterString : String.Empty;
// If someone simply imports namespaces separated by spaces, commas, or semicolons, create a proper using statement
if (!String.IsNullOrEmpty(Imports) && !IsUsingRegex.IsMatch(Imports))
{
Imports = String.Join("; ", Imports.Split(" ,;".ToCharArray()).Select(s => Using + " " + s)) + "; ";
}
FinalCode = String.Format(Imports + CodeTemplate,
new object[] {DefaultNamespace, ClassName, DefaultMethod, parameterString, Code});
// This just is a variable of the code that will be compiled, with all spaces and line breaks removed
var debugFriendlierFinalCode = U.CompressWhiteSpaceRegex.Replace(FinalCode.Replace("\r", String.Empty).Replace("\n", String.Empty), U.OneSpace);
// Note that we are adding the import fields to the beginning in case user wants to import namespaces (and not have to always use fully qualified class names)
var results = provider.CompileAssemblyFromSource(compilerParams, FinalCode);
Assembly = results.CompiledAssembly;
if (!results.Errors.HasErrors)
{
return Assembly;
}
// If there were compiler errors, aggregrate them into an exception.
var errors = new StringBuilder("Dynamic Code Compiler Errors :\r\n");
foreach (CompilerError error in results.Errors)
{
errors.AppendFormat("Line {0},{1}\t: {2}\n",
error.Line, error.Column, error.ErrorText);
}
throw new ProfigurationException(errors.ToString());
The Func is serializable and is being copied like you intend. But it points to code that resides inside of the assembly you want to unload. That's why the assembly is being loaded in the parent AppDomain as well.
Not sure what to recommend. I hope it makes sense that you cannot unload code that is being used.

C# - Loading dlls and creating instances

I have a situation and I need to know how to deal with it in the best way.
I have an application (MVC3) and I have couple of integrations for it. I have an interface "IntegrationInterface" and every integration implements it.
I want to load the dlls of the integrations, create a list of them, and run a loop that runs a method for every integration in the list.
For example - let's say I have integrations for facebook, myspace and twitter (for my appliction), and every time the user post a message in my application I want to post a message on his\her facebook, myspace and twitter.
I don't want that the code will know which integrations I have, so if tomorrow I'll create a new integration for google+, I'll just need to add a new DLL without changing the code of my application.
How can I do that?
First, you'll have to find all relevant dlls and classes:
loadedIntegrations.Clear();
if (!Directory.Exists(path))
return;
DirectoryInfo di = new DirectoryInfo(path);
FileInfo[] files = di.GetFiles("*.dll");
foreach (var file in files)
{
Assembly newAssembly = Assembly.LoadFile(file.FullName);
Type[] types = newAssembly.GetExportedTypes();
foreach (var type in types)
{
//If Type is a class and implements the IntegrationInterface interface
if (type.IsClass && (type.GetInterface(typeof(IntegrationInterface).FullName) != null))
loadedIntegrations.Add(type);
}
}
loadedIntegrations is of type List<Type>. Then you can instantiate each integration and call its methods:
foreach(var integrationType in loadedIntegrations)
{
var ctor = integrationType.GetConstructor(new Type[] { });
var integration = ctor.Invoke(new object[] { }) as IntegrationInterface;
//call methods on integration
}
I am doing something similar to what you described in an import utility that wrote. My issue was that I didn't want to load ALL the assemblies. I only wanted to load assemblies that contained types that were requested.
To accomplish this I've used the AppDomain.CurrentDomain.AssemblyResolve event handler.
This event handler is raised just before the AppDomain throw an exception notifying that an assembly is not found. I execute similar code to what Nico suggested in that handler and return the requested assembly.
NOTE: I have a sub-directory called 'Tasks' (think Import Tasks) where I store all of my assemblies I want to load at runtime.
Here is the code:
var tasks = GetTasks();
var basedir = AppDomain.CurrentDomain.BaseDirectory; // Get AppDomain Path
var tasksPath = Path.Combine(basedir, "Tasks"); // append 'Tasks' subdir
// NOTE: Cannot be factored, relies on 'tasksPath' variable (above).
AppDomain.CurrentDomain.AssemblyResolve += (s, e) => // defined 'AssemblyResolve' handler
{
var assemblyname = e.Name + ".dll"; // append DLL to assembly prefix
// *expected* assembly path
var assemblyPath = Path.Combine(tasksPath, assemblyname); // create full path to assembly
if (File.Exists(assemblyPath)) return Assembly.LoadFile(assemblyPath); // Load Assembly as file.
return null; // return Null if assembly was not found. (throws Exception)
};
foreach (var task in tasks.OrderBy(q => q.ExecutionOrder)) // enumerate Tasks by ExecutionOrder
{
Type importTaskType = Type.GetType(task.TaskType); // load task Type (may cause AssemblyResolve event to fire)
if (importTaskType == null)
{
log.Warning("Task Assembly not found");
continue;
}
ConstructorInfo ctorInfo = importTaskType.GetConstructor(Type.EmptyTypes); // get constructor info
IImportTask taskInstance = (IImportTask)ctorInfo.Invoke(new object[0]); // invoke constructor and cast as IImportTask
taskInstances.Add(taskInstance);
}
// rest of import logic omitted...
If u know MEF (Managed extensibility framework) this might help you I personally use it but have to say that using MEF with MVC is not trivial i think for more information please visit
http://msdn.microsoft.com/en-us/library/dd460648.aspx

I've stored form names in a data base. now i want to load forms by using those names

I've stored form names in a data base. Now I want to load forms by using those names.
Here is my table structure:
frmID, Item_Name, formName
Here is my code:
private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
{
//TreeNode node = treeView1.SelectedNode;
string item = Convert.ToString(treeView1.SelectedNode);
int index = item.IndexOf(" ");
if (index > 0)
item = item.Substring(index + 1);
//MessageBox.Show(item);
var selectedFRM = from Menu in dbdata.Menus
where Menu.Item_Name == item
select Menu;
foreach (var pick in selectedFRM.Take(1))
{
string sel = pick.Form_Name;
Assembly asm = typeof(Form).Assembly;
Type type = asm.GetType(sel);
string df = Convert.ToString(type);
MessageBox.Show(df);
AssemblyName assemName = asm.GetName();
MessageBox.Show(assemName.Name);
try
{
Form frmChk = (Form)Activator.CreateInstance(type);
frmChk.Show();
}
catch (Exception)
{
MessageBox.Show("Error in loading form");
}
// MessageBox.Show(sel);
}
upto Assembly asm = typeof(Form).Assembly; code is working properly. How can I load a form by using the "formName" which is in the database
This is the problem, I suspect:
Assembly asm = typeof(Form).Assembly;
Type type = asm.GetType(sel);
That assembly will be the System.Windows.Forms assembly - which obviously doesn't include your specific forms. Just use any of the forms you know is in the right assembly, instead of Form:
// Or whatever you know about, of course...
Assembly asm = typeof(LoginForm).Assembly;
Note that the name will still need to be the namespace-qualified name.
Another (more flexible) alternative is to store the assembly-qualified name of the type which you can obtain via Type.AssemblyQualifiedName. Then you can just use Type.GetType(aqName) - which means your code will still work if you split your forms across multiple assemblies.
I found the solution. the Type type = asm.GetType(sel); line should corrected like this.
Type type = asm.GetType("WindowsFormsApplication6." + sel);
That means
Type type = asm.GetType("Namespace.Class");

Is there a way to force all referenced assemblies to be loaded into the app domain?

My projects are set up like this:
Project "Definition"
Project "Implementation"
Project "Consumer"
Project "Consumer" references both "Definition" and "Implementation", but does not statically reference any types in "Implementation".
When the application starts, Project "Consumer" calls a static method in "Definition", which needs to find types in "Implementation"
Is there a way I can force any referenced assembly to be loaded into the App Domain without knowing the path or name, and preferably without having to use a full-fledged IOC framework?
This seemed to do the trick:
var loadedAssemblies = AppDomain.CurrentDomain.GetAssemblies().ToList();
var loadedPaths = loadedAssemblies.Select(a => a.Location).ToArray();
var referencedPaths = Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory, "*.dll");
var toLoad = referencedPaths.Where(r => !loadedPaths.Contains(r, StringComparer.InvariantCultureIgnoreCase)).ToList();
toLoad.ForEach(path => loadedAssemblies.Add(AppDomain.CurrentDomain.Load(AssemblyName.GetAssemblyName(path))));
As Jon noted, the ideal solution would need to recurse into the dependencies for each of the loaded assemblies, but in my specific scenario I don't have to worry about it.
Update: The Managed Extensibility Framework (System.ComponentModel) included in .NET 4 has much better facilities for accomplishing things like this.
You can use Assembly.GetReferencedAssemblies to get an AssemblyName[], and then call Assembly.Load(AssemblyName) on each of them. You'll need to recurse, of course - but preferably keeping track of assemblies you've already loaded :)
just wanted to share a recursive example. I'm calling the LoadReferencedAssembly method in my startup routine like this:
foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
{
this.LoadReferencedAssembly(assembly);
}
This is the recursive method:
private void LoadReferencedAssembly(Assembly assembly)
{
foreach (AssemblyName name in assembly.GetReferencedAssemblies())
{
if (!AppDomain.CurrentDomain.GetAssemblies().Any(a => a.FullName == name.FullName))
{
this.LoadReferencedAssembly(Assembly.Load(name));
}
}
}
If you use Fody.Costura, or any other assembly merging solution, the accepted answer will not work.
The following loads the Referenced Assemblies of any currently loaded Assembly. Recursion is left to you.
var loadedAssemblies = AppDomain.CurrentDomain.GetAssemblies().ToList();
loadedAssemblies
.SelectMany(x => x.GetReferencedAssemblies())
.Distinct()
.Where(y => loadedAssemblies.Any((a) => a.FullName == y.FullName) == false)
.ToList()
.ForEach(x => loadedAssemblies.Add(AppDomain.CurrentDomain.Load(x)));
Seeing as I had to load an assembly + dependencies from a specific path today I wrote this class to do it.
public static class AssemblyLoader
{
private static readonly ConcurrentDictionary<string, bool> AssemblyDirectories = new ConcurrentDictionary<string, bool>();
static AssemblyLoader()
{
AssemblyDirectories[GetExecutingAssemblyDirectory()] = true;
AppDomain.CurrentDomain.AssemblyResolve += ResolveAssembly;
}
public static Assembly LoadWithDependencies(string assemblyPath)
{
AssemblyDirectories[Path.GetDirectoryName(assemblyPath)] = true;
return Assembly.LoadFile(assemblyPath);
}
private static Assembly ResolveAssembly(object sender, ResolveEventArgs args)
{
string dependentAssemblyName = args.Name.Split(',')[0] + ".dll";
List<string> directoriesToScan = AssemblyDirectories.Keys.ToList();
foreach (string directoryToScan in directoriesToScan)
{
string dependentAssemblyPath = Path.Combine(directoryToScan, dependentAssemblyName);
if (File.Exists(dependentAssemblyPath))
return LoadWithDependencies(dependentAssemblyPath);
}
return null;
}
private static string GetExecutingAssemblyDirectory()
{
string codeBase = Assembly.GetExecutingAssembly().CodeBase;
var uri = new UriBuilder(codeBase);
string path = Uri.UnescapeDataString(uri.Path);
return Path.GetDirectoryName(path);
}
}
For getting referenced assembly by name you can use following method:
public static Assembly GetAssemblyByName(string name)
{
var asm = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault(a => a.FullName == name);
if (asm == null)
asm = AppDomain.CurrentDomain.Load(name);
return asm;
}
Yet another version (based on Daniel Schaffer answer) is the case when you might not need to load all Assemblies, but a predefined number of them:
var assembliesToLoad = { "MY_SLN.PROJECT_1", "MY_SLN.PROJECT_2" };
// First trying to get all in above list, however this might not
// load all of them, because CLR will exclude the ones
// which are not used in the code
List<Assembly> dataAssembliesNames =
AppDomain.CurrentDomain.GetAssemblies()
.Where(assembly => AssembliesToLoad.Any(a => assembly.GetName().Name == a))
.ToList();
var loadedPaths = dataAssembliesNames.Select(a => a.Location).ToArray();
var compareConfig = StringComparison.InvariantCultureIgnoreCase;
var referencedPaths = Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory, "*.dll")
.Where(f =>
{
// filtering the ones which are in above list
var lastIndexOf = f.LastIndexOf("\\", compareConfig);
var dllIndex = f.LastIndexOf(".dll", compareConfig);
if (-1 == lastIndexOf || -1 == dllIndex)
{
return false;
}
return AssembliesToLoad.Any(aName => aName ==
f.Substring(lastIndexOf + 1, dllIndex - lastIndexOf - 1));
});
var toLoad = referencedPaths.Where(r => !loadedPaths.Contains(r, StringComparer.InvariantCultureIgnoreCase)).ToList();
toLoad.ForEach(path => dataAssembliesNames.Add(AppDomain.CurrentDomain.Load(AssemblyName.GetAssemblyName(path))));
if (dataAssembliesNames.Count() != AssembliesToLoad.Length)
{
throw new Exception("Not all assemblies were loaded into the project!");
}
If you have assemblies where no code is referenced at compile time, those assemblies will not be included as a reference to your other assembly, even if you have added the project or nuget package as a reference. This is regardless of Debug or Release build settings, code optimization, etc. In these cases, you must explicitly call Assembly.LoadFrom(dllFileName) to get the assembly loaded.
In my winforms application I give JavaScript (in a WebView2 control) the possibility to call various .NET things, for example methods of Microsoft.VisualBasic.Interaction in the assembly Microsoft.VisualBasic.dll (such as InputBox() etc).
But my application as such does not use that assembly, so the assembly is never loaded.
So to force the assembly to load, I ended up simply adding this in my Form1_Load:
if (DateTime.Now < new DateTime(1000, 1, 1, 0, 0, 0)) { // never happens
Microsoft.VisualBasic.Interaction.Beep();
// you can add more things here
}
The compiler thinks that the assembly might be needed, but in reality this never happens of course.
Not a very sophisticated solution, but quick and dirty.
I created my own based on #Jon Skeet answer with name prefix filtering to avoid loading unnecessary assemblies:
public static IEnumerable<Assembly> GetProjectAssemblies(string prefixName)
{
var assemblies = new HashSet<Assembly>
{
Assembly.GetEntryAssembly()
};
for (int i = 0; i < assemblies.Count; i++)
{
var assembly = assemblies.ElementAt(i);
var referencedProjectAssemblies = assembly.GetReferencedAssemblies()
.Where(assemblyName => assemblyName.FullName.StartsWith(prefixName))
.Select(assemblyName => Assembly.Load(assemblyName));
assemblies.UnionWith(referencedProjectAssemblies);
}
return assemblies;
}

Categories

Resources