dotnet / dotnet/docs

Suggested change to code sample to address likely issue

Open
#28,002 1 comment 0 reactions 0 assignees View on GitHub
:watch: Not Triaged dotnet-fundamentals/svc
Dominant language
No language data
Stars
4.8k
Forks
6.1k
Avg merge
15h 21m
Merged PRs (30d)
370

Description

In the "Load plugins" example...

the addition of the 1st if check resolves the error message **TypeLoadException 'Method 'M' in type 'T' from assembly 'A' does not have an implementation'.**
that can occur if a framework type like System.Text.Json.JsonDocument is a parameter on the shared interface AND the resolver find System.Text.Json in the nuget cache and loads it into the new AssemblyLoadContext

```
protected override Assembly Load(AssemblyName assemblyName)
{
// This will fallback to loading the assembly from default context.
if (AssemblyLoadContext.Default.Assemblies.Any(a => a.FullName == assemblyName.FullName))
{
System.Diagnostics.Debug.WriteLine($"Load from default context => [{assemblyName.FullName}]");
return null;
}

string assemblyPath = _resolver.ResolveAssemblyToPath(assemblyName);

if (assemblyPath != null)
{
return LoadFromAssemblyPath(assemblyPath);
}

return null;
}

```
---
#### Document Details

⚠ *Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.*

* ID: 06023407-704f-0ace-e89a-eedd9f95a007
* Version Independent ID: f25a6e1a-cb10-867b-0522-a377bf9d016b
* Content: [Create a .NET Core application with plugins - .NET](https://docs.microsoft.com/en-us/dotnet/core/tutorials/creating-app-with-plugin-support)
* Content Source: [docs/core/tutorials/creating-app-with-plugin-support.md](https://github.com/dotnet/docs/blob/main/docs/core/tutorials/creating-app-with-plugin-support.md)
* Product: **dotnet-fundamentals**
* GitHub Login: @jkoritzinsky
* Microsoft Alias: **jekoritz**

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.