nug Createrun NuGet

System.Reflection.MetadataLoadContext

8.0.1 50 download(s)
public

Provides read-only reflection on assemblies in an isolated context with support for assemblies that target different processor architectures and runtimes. Using MetadataLoadContext enables you to inspect assemblies without loading them into the main execution context. Assemblies in MetadataLoadContext are treated only as metadata, that is, you can read information about their members, but cannot execute any code contained in them.

PackageReference
<PackageReference Include="System.Reflection.MetadataLoadContext" Version="8.0.1" />
.NET CLI
dotnet add package System.Reflection.MetadataLoadContext --version 8.0.1

Dependencies

net462
Package Version range
System.Collections.Immutable [8.0.0, )
System.Memory [4.5.5, )
System.Reflection.Metadata [8.0.1, )
net6.0
Package Version range
System.Collections.Immutable [8.0.0, )
System.Reflection.Metadata [8.0.1, )
net7.0
Package Version range
System.Collections.Immutable [8.0.0, )
System.Reflection.Metadata [8.0.1, )
netstandard2.0
Package Version range
System.Collections.Immutable [8.0.0, )
System.Memory [4.5.5, )
System.Reflection.Metadata [8.0.1, )

Readme

## About

<!-- A description of the package and where one can find more documentation -->

Provides read-only reflection on assemblies in an isolated context with support for assemblies that target different processor architectures and runtimes. Using MetadataLoadContext enables you to inspect assemblies without loading them into the main execution context. Assemblies in MetadataLoadContext are treated only as metadata, that is, you can read information about their members, but cannot execute any code contained in them.

## How to Use

<!-- A compelling example on how to use this package with code, as well as any specific guidelines for when to use the package -->

The following example shows how to print the list of types defined in an assembly.

```cs
using System;
using System.Reflection;

class Program
{
    static void Main()
    {
        string inspectedAssembly = "Example.dll";
        var resolver = new PathAssemblyResolver(new string[] {inspectedAssembly, typeof(object).Assembly.Location});
        using var mlc = new MetadataLoadContext(resolver, typeof(object).Assembly.GetName().ToString());

        // Load assembly into MetadataLoadContext
        Assembly assembly = mlc.LoadFromAssemblyPath(inspectedAssembly);
        AssemblyName name = assembly.GetName();

        // Print types defined in assembly
        Console.WriteLine($"{name.Name} has following types: ");

        foreach (Type t in assembly.GetTypes())
        {
            Console.WriteLine(t.FullName);
        }
    }
}
```

## Main Types

<!-- The main types provided in this library -->

The main types provided by this library are:

* `System.Reflection.MetadataLoadContext`
* `System.Reflection.MetadataAssemblyResolver`

## Additional Documentation

<!-- Links to further documentation -->

* [How to: Inspect assembly contents using MetadataLoadContext](https://docs.microsoft.com/dotnet/standard/assembly/inspect-contents-using-metadataloadcontext)
* [System.Reflection.MetadataLoadContext](https://docs.microsoft.com/dotnet/api/system.reflection.metadataloadcontext)
* [System.Reflection.MetadataAssemblyResolver](https://docs.microsoft.com/dotnet/api/system.reflection.metadataassemblyresolver)

## Feedback & Contributing

<!-- How to provide feedback on this package and contribute to it -->

System.Reflection.MetadataLoadContext is released as open source under the [MIT license](https://licenses.nuget.org/MIT). Bug reports and contributions are welcome at [the GitHub repository](https://github.com/dotnet/runtime).

Versions

Target frameworks

net462 net6.0 net7.0 netstandard2.0

Metadata

Published
Size
598.11 KB
Authors
Microsoft
License
MIT
Repository
https://github.com/dotnet/runtime commit 81cabf2857a01351e5ab578947c7403a5b128ad1
Flags
SemVer 1
SHA512
LdldCp5mgUbTK1rWuwkAPUkzOxUUQSWWLC//jgoLAuYveUr067UxJXwRSz+qFB5P+ye3CHtqPbRKy48H5MIxzw==

Release notes

https://go.microsoft.com/fwlink/?LinkID=799421