How to read the parts definition of Assembly from an AssemblyCatalog

297 views Asked by At

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.

0

There are 0 answers