System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Could not load file or assembly 'Microsoft.AspNetCore.Mvc.Core
- Dominant language
- C#
- Stars
- 3.7k
- Forks
- 5.1k
- Avg merge
- 9h 11m
- Merged PRs (30d)
- 1
Description
**Example: samples/core/extensions/AppWithPlugin/**
**net5.0**
Check the .NET target framework(s) being used, and include the version number(s).
- [ x] .NET Core
- [ ] .NET Framework
- [ ] .NET Standard
If using the .NET Core SDK, include `dotnet --info` output. If using .NET Framework without the .NET Core SDK, include info from Visual Studio's **Help** > **About Microsoft Visual Studio** dialog.
dotnet --info output or About VS info
```console
.NET SDK (reflecting any global.json):
Version: 5.0.200-preview.20601.7
Commit: b3b934bbf2
Runtime Environment:
OS Name: Windows
OS Version: 10.0.18362
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\5.0.200-preview.20601.7\
Host (useful for support):
Version: 5.0.0
Commit: cf258a14b7
.NET SDKs installed:
3.1.102 [C:\Program Files\dotnet\sdk]
3.1.201 [C:\Program Files\dotnet\sdk]
3.1.202 [C:\Program Files\dotnet\sdk]
3.1.300 [C:\Program Files\dotnet\sdk]
5.0.100-rc.2.20479.15 [C:\Program Files\dotnet\sdk]
5.0.100 [C:\Program Files\dotnet\sdk]
5.0.200-preview.20601.7 [C:\Program Files\dotnet\sdk]
.NET runtimes installed:
Microsoft.AspNetCore.All 2.1.23 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.23 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 5.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.1.23 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 5.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.1.2 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 3.1.4 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 3.1.9 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 5.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
```
If the XcopyablePlugin is extended with a reference to `Microsoft.AspNetCore.Mvc.NewtonsoftJson`
the example give an error.
```console
System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types.
Could not load file or assembly 'Microsoft.AspNetCore.Mvc.Core, Version=5.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. Het systeem kan het opgegeven bestand niet vinden.
```
.csproj
```xml
net5.0
true
false
runtime
```
XcopyableJsonPlugin.cs
```c#
using System;
using Microsoft.AspNetCore.Mvc.Filters;
using Newtonsoft.Json;
using PluginBase;
namespace XcopyablePlugin
{
public class XcopyableJsonPlugin : ICommand
{
public string Name => "xcopyable-json";
public string Description => "Outputs JSON value.";
public int Execute()
{
var jsonAssembly = typeof(JsonConvert).Assembly;
var info = new Info
{
JsonVersion = jsonAssembly.FullName,
JsonLocation = jsonAssembly.Location,
Machine = Environment.MachineName,
User = Environment.UserName,
Date = DateTime.Now
};
Console.WriteLine(JsonConvert.SerializeObject(info, Formatting.Indented));
return 0;
}
private struct Info
{
public string JsonVersion;
public string JsonLocation;
public string Machine;
public string User;
public DateTime Date;
}
}
public class ValidationFilter : ActionFilterAttribute
{
}
}
```
Contributor guide
Assessment
This issue has not been assessed yet.