'System.Reflection.ReflectionTypeLoadException: 'Unable to load one or more of the requested types. Could not load file or assembly

I am building an API on Visual Studio 2019 net5.0 and I was just adding the lasts controllers and validators when my program suddenly stopped working.

The error that I'm getting:

System.Reflection.ReflectionTypeLoadException: 'Unable to load one or more of the requested types.
Could not load file or assembly 'Crijoya.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. Se ha intentado cargar un programa con un formato incorrecto.
Could not load file or assembly 'Crijoya.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. Se ha intentado cargar un programa con un formato incorrecto.
Could not load file or assembly 'Crijoya.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. Se ha intentado cargar un programa con un formato incorrecto.
Could not load file or assembly 'Crijoya.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. Se ha intentado cargar un programa con un formato incorrecto.
Could not load file or assembly 'Crijoya.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. Se ha intentado cargar un programa con un formato incorrecto.
Could not load file or assembly 'Crijoya.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. Se ha intentado cargar un programa con un formato incorrecto.
Could not load file or assembly 'Crijoya.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. Se ha intentado cargar un programa con un formato incorrecto.
Could not load file or assembly 'Crijoya.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. Se ha intentado cargar un programa con un formato incorrecto.
Could not load file or assembly 'Crijoya.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. Se ha intentado cargar un programa con un formato incorrecto.'

I get this error on my Statup ConfigureServices method when loading the assemblies. Here's the code:

//use and register all the mappings
services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies());

I have tried following these solutions but I can't get to the problem: Error message 'Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.'



Solution 1:[1]

So in my case the dll file Crijoya.Core was in a different format as the error says. After trying everything they said on other questions this is what worked for me.

I have a project with two class libraries like so

enter image description here

I made sure that in the properties of each of them the platform was Any CPU

enter image description here

And finally that on Tools I was using the 64 bit version for IIS Express for web projects

enter image description here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 mml