How to load assemblies located in a folder in .net core console app

前端 未结 8 1082
甜味超标
甜味超标 2020-11-28 07:06

I\'m making a console app on .Net Core platform and was wondering, how does one load assemblies (.dll files) and instantiate classes using C# dynamic features? It seems so m

8条回答
  •  囚心锁ツ
    2020-11-28 07:49

    Using .net core 1.1 / standard 1.6, I found that AssemblyLoader was not available, and

    AssemblyLoadContext.Default.LoadFromAssemblyPath(assemblyPath)
    gave me a "Could not load file or assembly xxx" error.

    Finally this solution below worked for me - purely by adding a step to get the AssemblyName object. Hope it helps anyone who gets stuck:

    var assemblyName = AssemblyLoadContext.GetAssemblyName(assemblyPath);
    var assembly = Assembly.Load(assemblyName);

提交回复
热议问题