0

I have a C# project runs on both .NET framework 4.6.2 and .NET core 3.1 with a most sharable code. When running in .NET framework, It is loading both the assembly and its parts definition from the x86 bin path using the AssemblyCatalog class. But, when the code runs in .NET Core which is loading the assemblies from the netstandard2.0, here the parts definition is empty and only getting the assembly information (If the API is unavailable in core and standard, how am I getting the assembly information in the first place?).

Image: Parts loading from framework assembly

Image: Parts are not loading from core assembly

I am using the AssemblyCatalog (namespace :System.ComponentModel.Composition.Hosting) for the Net framework but from the micrososft .NET API browser this managed API is not available in .NET core/ .NET standard.

If this API is not ported in Core, how am I able to see the assembly information at least? Can some one help me to get the parts definition from the assembly in .NET core. Below is the sample .NET Core project code that am currently trying to achieve the work.

using System;
using System.Reflection;
using System.ComponentModel.XXXXXX

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            // path to dll: F:/projFolder/bin/x86/debug/netstandar2.0/*.dll
            // catalog should return both Assembly information and Parts
            SafeAssemblyCatalog catalog = new SafeAssemblyCatalog("path to dll");
        }

        internal class SafeAssemblyCatalog : AssemblyCatalog //<== cant inherit 
        {
            private bool _isAssemblyLoad;

            public SafeAssemblyCatalog(string dllPath) : base(Assembly.LoadFrom(dllPath))
            {
                _isAssemblyLoad = true;
            }
        }
    }
}

ope your expertise helps me here to resolve the issue I am facing here.

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
SSA
  • 1
  • Take a look at the [Assembly class](https://learn.microsoft.com/en-us/dotnet/api/microsoft.visualbasic.applicationservices.assemblyinfo?view=net-5.0). – Alessandro D'Andria Jun 09 '21 at 07:45
  • Hi, @AlessandroD'Andria, Thanks for the comment, but how does an Assembly class help here in my situation. Can you please elaborate how can use it to get the assembly parts for a .NET core application thanks :) – SSA Jun 09 '21 at 08:32
  • If my 'parts' you mean the types assembly defines you can just get those using assembly variable.GetTypes() to get a collection of Types that an assembly defines. – DekuDesu Jun 09 '21 at 12:19
  • @DekuDesu, yes GetTypes() returns all available definedTypes, but where the parts definition is a composable part catalog definition which is different among the defined types. No idea how it returns these parts. If you see the image in the question it returns 14parts where the defined types are more than 500. I'm very new to these stuff and understanding is somewhat difficult. please forgive me if i didn't explain clearly what i needed here! :) – SSA Jun 09 '21 at 14:38
  • AssemblyCatalog/MEF _is_ available in .NET Core, but its library (System.ComponentModel.Composition) ships as a NuGet package rather than being implemented in the 'standard' set of assemblies that come with Core. See [this question](https://stackoverflow.com/q/53097067/3791245) and answer for more info. – Sean Skelly Jul 16 '21 at 21:43

0 Answers0