Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

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

75%
+4 −0
Q&A How to find out which packages target .NET 3.1 in a .NET 5 application?

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

posted 3y ago by Dana‭  ·  edited 3y ago by Alexei‭

Answer
#3: Post edited by user avatar Alexei‭ · 2021-07-11T09:53:54Z (over 3 years ago)
added a fully working example
  • 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 by user avatar FoggyFinder‭ · 2021-07-06T16:25:26Z (over 3 years ago)
fix formatting
  • 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 by user avatar Dana‭ · 2021-07-06T15:30:36Z (over 3 years ago)
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.