Ich habe eine App, die eine Reihe von DLLs auf dem Dateisystem und in der GAC öffnet, und die eine Sperre für diese Dateien hält. Wie kann ich diese Punkte explizit freigeben, damit ich sie in Visual Studio neu erstellen kann, ohne meine App zu schließen?C#: Warum schließt meine App nicht die Dateigriffe?
-Code folgt:
private void BuildTabPage_AssemblyTree(string filename, string foldername)
{
Assembly assembly;
try
{
assembly = Assembly.LoadFrom(filename);
}
catch (Exception ex)
{
MessageBox.Show("Error loading assembly " + filename + "\n" + ex.Message);
return;
}
TreeNode tRoot = BuildNode(assembly, foldername);
tvAssemblies.Nodes.Add(tRoot);
tvAssemblies.ExpandAll();
txtResults.Text =
RefsFound.ToString() + " References Located in Filesystem\r\n" +
RefsInFramework.ToString() + " References Located in Framework\r\n" +
RefsInGac.ToString() + " References Located in GAC\r\n" +
RefsNotFound.ToString() + " References Not Found: \r\n\r\n";
foreach (string s in MissingFiles)
txtResults.Text += s + "\r\n";
}
private TreeNode BuildNode(Assembly assembly, string foldername)
{
TreeNode tn = new TreeNode(assembly.GetName().Name);
tn.ToolTipText = assembly.FullName + "\n" + assembly.CodeBase;
AssemblyName[] assemblies = assembly.GetReferencedAssemblies();
foreach (AssemblyName a in assemblies)
{
string filename2 = foldername + a.Name + ".dll";
TreeNode tn2;
if (System.IO.File.Exists(filename2))
{ // File found in folder
RefsFound++;
Assembly assy = Assembly.LoadFile(filename2);
tn2 = BuildNode(assy, foldername);
}
else if (a.Name.StartsWith("System"))
{ // Framework assemblies not included
RefsInFramework++;
tn2 = new TreeNode();
tn2.Text = a.Name;
tn2.ForeColor = System.Drawing.Color.Green;
tn2.ToolTipText += "\n.NET Framework File";
}
else
{
try
{ // Find file in GAC
Assembly assy = Assembly.Load(a);
tn2 = new TreeNode(a.Name);
tn.ToolTipText = assembly.FullName + "\n" + assembly.CodeBase + "\nFile detected in GAC";
tn2.Text = "(" + filename2.Substring(filename2.LastIndexOf("\\") + 1) + ")";
tn2.ForeColor = System.Drawing.Color.Green;
RefsInGac++;
}
catch (System.IO.FileNotFoundException)
{ // File not Found
RefsNotFound++;
if (!MissingFiles.Contains(a.Name))
MissingFiles.Add(a.Name);
tn2 = new TreeNode();
tn2.Text = "(" + filename2.Substring(filename2.LastIndexOf("\\") + 1) + ")";
tn2.ToolTipText = "File Not Found";
tn2.ForeColor = System.Drawing.Color.Red;
}
}
tn.Nodes.Add(tn2);
}
return tn;
}
dieser Code "riecht" .... BuildNode() hat mehrere Verantwortlichkeiten, die nichts mit dem Aufbau eines Knotens zu tun haben ... –