Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Post History
You could start to track down the problem by using Assembly.LoadFrom() to attempt loading each library individually. I have a routine in a .NET 5 solution that performs some analysis on assemblies...
Answer
#3: Post edited
- You could start to track down the problem by using Assembly.LoadFrom() to attempt loading each library individually.
- I have a routine in a .NET 5 solution that performs some analysis on assemblies deployed with my application. I retooled it a bit here to make something that would work as part of a console application your could run in your .NET 5 only environment as a step in the debugging process.
- ```cs
- // Look for DLL plugins
- foreach (string pluginDll in Directory.GetFiles(".", "*.dll", SearchOption.AllDirectories))
- {
- try
- {
- Console.WriteLine("Attempting to load " + pluginDll);
- Assembly.LoadFrom(pluginDll);
- Console.WriteLine(pluginDll + " Loaded");
- }
- catch (Exception ex)
- {
- Console.WriteLine("Error: " + ex);
- }
- }
- ```
If you run this from the location of your application, it will try to load all dlls and will give you feedback about which ones can and can't load.
- You could start to track down the problem by using Assembly.LoadFrom() to attempt loading each library individually.
- I have a routine in a .NET 5 solution that performs some analysis on assemblies deployed with my application. I retooled it a bit here to make something that would work as part of a console application your could run in your .NET 5 only environment as a step in the debugging process.
- ```cs
- // Look for DLL plugins
- foreach (string pluginDll in Directory.GetFiles(".", "*.dll", SearchOption.AllDirectories))
- {
- try
- {
- Console.WriteLine("Attempting to load " + pluginDll);
- Assembly.LoadFrom(pluginDll);
- Console.WriteLine(pluginDll + " Loaded");
- }
- catch (Exception ex)
- {
- Console.WriteLine("Error: " + ex);
- }
- }
- ```
- If you run this from the location of your application, it will try to load all dlls and will give you feedback about which ones can and can't load.
- ---
- A full working code in .NET 5 that shows a meaningful string to identify the target framework:
- static void Main(string[] args)
- {
- var dirPath = "full path to directory containing all assemblies";
- var loadedDlls = new HashSet<string>();
- foreach (string pluginDll in Directory.GetFiles(dirPath, "*.dll", SearchOption.AllDirectories))
- {
- string filename = Path.GetFileName(pluginDll);
- if (loadedDlls.Contains(filename))
- {
- Console.WriteLine($"{filename} already loaded");
- continue;
- }
- try
- {
- Console.WriteLine("Attempting to load " + pluginDll);
- var assembly = Assembly.LoadFrom(pluginDll);
- var targetFwk = assembly.CustomAttributes.FirstOrDefault(a => a.AttributeType == typeof(TargetFrameworkAttribute));
- Console.WriteLine($"{pluginDll}: Target fwk = {targetFwk?.ConstructorArguments[0].Value}");
- loadedDlls.Add(filename);
- }
- catch (Exception ex)
- {
- Console.WriteLine("Error: " + ex);
- }
- }
- }
#2: Post edited
- You could start to track down the problem by using Assembly.LoadFrom() to attempt loading each library individually.
- I have a routine in a .NET 5 solution that performs some analysis on assemblies deployed with my application. I retooled it a bit here to make something that would work as part of a console application your could run in your .NET 5 only environment as a step in the debugging process.
```// Look for DLL plugins- foreach (string pluginDll in Directory.GetFiles(".", "*.dll", SearchOption.AllDirectories))
- {
- try
- {
- Console.WriteLine("Attempting to load " + pluginDll);
- Assembly.LoadFrom(pluginDll);
- Console.WriteLine(pluginDll + " Loaded");
- }
- catch (Exception ex)
- {
- Console.WriteLine("Error: " + ex);
- }
}```- If you run this from the location of your application, it will try to load all dlls and will give you feedback about which ones can and can't load.
- You could start to track down the problem by using Assembly.LoadFrom() to attempt loading each library individually.
- I have a routine in a .NET 5 solution that performs some analysis on assemblies deployed with my application. I retooled it a bit here to make something that would work as part of a console application your could run in your .NET 5 only environment as a step in the debugging process.
- ```cs
- // Look for DLL plugins
- foreach (string pluginDll in Directory.GetFiles(".", "*.dll", SearchOption.AllDirectories))
- {
- try
- {
- Console.WriteLine("Attempting to load " + pluginDll);
- Assembly.LoadFrom(pluginDll);
- Console.WriteLine(pluginDll + " Loaded");
- }
- catch (Exception ex)
- {
- Console.WriteLine("Error: " + ex);
- }
- }
- ```
- If you run this from the location of your application, it will try to load all dlls and will give you feedback about which ones can and can't load.
#1: Initial revision
You could start to track down the problem by using Assembly.LoadFrom() to attempt loading each library individually. I have a routine in a .NET 5 solution that performs some analysis on assemblies deployed with my application. I retooled it a bit here to make something that would work as part of a console application your could run in your .NET 5 only environment as a step in the debugging process. ```// Look for DLL plugins foreach (string pluginDll in Directory.GetFiles(".", "*.dll", SearchOption.AllDirectories)) { try { Console.WriteLine("Attempting to load " + pluginDll); Assembly.LoadFrom(pluginDll); Console.WriteLine(pluginDll + " Loaded"); } catch (Exception ex) { Console.WriteLine("Error: " + ex); } }``` If you run this from the location of your application, it will try to load all dlls and will give you feedback about which ones can and can't load.