Giter Site home page Giter Site logo

assemblyloader's Introduction

AssemblyLoader

Assembly Information & Loader via Reflection


  • CREATED BY: Latency McLaughlin
  • FRAMEWORK: .NET 4.5 / 4.7.2; .NET Standard 2.0; .NET Core 2.1
  • SUPPORTS: Visual Studio 2017, 2015, 2013, 2012, 2010, 2008
  • UPDATED: 11/25/2018
  • TAGS: C# .NET AssemblyInfo AssemblyLoader API
  • VERSION: v1.1.3

Navigation


Gets assembly information at runtime commonly found in Properties within .NET assemblies. Dynamically loads / unloads assemblies and their dependencies within a proxy for validation.

Trying to get information out of an assembly without loading it into the current application domain is not that simple. There is no way to get custom assembly attributes without loading it into the current AppDomain. There is a special assembly loading method, Assembly.ReflectionOnlyLoad(), which uses a "reflection-only" load context. This lets you load assemblies that cannot be executed, but can have their metadata read. You cannot get typed attributes from this kind of assembly, only CustomAttributeData. That class doesn't provide any good way to filter for a specific attribute.

Even worse, a reflection-only load does not load any dependency assemblies, but it forces you to do it manually. That makes it objectively worse than Assembly.Load() which at least gets the dependencies to load automatically.

MEF includes a whole ton of custom reflection code to make this work.

Ultimately, you cannot unload an assembly once it has been loaded. You need to unload the entire app domain, as described in this MSDN article.

Based on the following premises:

Creating an assembly proxy (or wrapper), derived from MarshalByRefObject, so that the CLR can marshal it by reference across AppDomain boundaries. Loading the assembly within this proxy. Performing the reflection inside this proxy and return the data you need. Creating a temporary AppDomain and instantiating the assembly proxy in this AppDomain (AppDomain.CreateInstanceFrom). Unloading the AppDomain as soon as you finished reflecting.

However, you have to keep in mind that reflection on the assembly loaded this way is only possible inside the proxy (the one derived from MarshalByRefObject). It is not possible to return any "reflection object" (anything defined in the System.Reflection namespace, such as Type, MethodInfo, etc.). Trying to access these from another AppDomain (the caller's domain) would result in exceptions.

  • Types called across AppDomain boundaries must inherit MarshalByRefObject.
  • Types called across AppDomain boundaries must be called via an interface.
  • The property LoaderOptimization must be set to LoaderOptimization.MultiDomainHost.
  • Construct a proxy manager that loads assemblies into AppDomains, performs queries, and unloads AppDomains.

This library can be installed using NuGet found here.

GNU LESSER GENERAL PUBLIC LICENSE - Version 3, 29 June 2007

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.