lukemansell / dotnet-auto-dependency-registration

A package to automatically register dependencies across your solution through attributes above classes. Automatically scans across assemblies.
MIT License
8 stars 2 forks source link

System.BadImageFormatException #11

Closed jepperaskdk closed 1 year ago

jepperaskdk commented 1 year ago

Hey, cool package!

After adding the Microsoft.Azure.Cosmos package to my project, I get the following exception when calling builder.Services.AutoRegisterDependencies();:

System.BadImageFormatException
  HResult=0x80131018
  Message=Could not load file or assembly 'path\to\bin\Debug\net6.0\Cosmos.CRTCompat.dll'. The module was expected to contain an assembly manifest.
  Source=System.Private.CoreLib
  StackTrace:
   at System.Reflection.AssemblyName.nGetFileInformation(String s)
   at System.Reflection.AssemblyName.GetAssemblyName(String assemblyFile) in System.Reflection\AssemblyName.cs:line 343
   at AutoDependencyRegistration.Helpers.RegisterDependenciesHelper.<>c.<GetAssemblies>b__1_0(String x) in AutoDependencyRegistration.Helpers\RegisterDependenciesHelper.cs:line 22
   at System.Linq.Enumerable.SelectArrayIterator`2.MoveNext() in System.Linq\Enumerable.cs:line 1762
   at System.Linq.Enumerable.SelectManySingleSelectorIterator`2.MoveNext() in System.Linq\Enumerable.cs:line 2599
   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext() in System.Linq\Enumerable.cs:line 3354
   at AutoDependencyRegistration.Services.RegisterDependenciesService.RegisterServices(IEnumerable`1 services, IServiceCollection serviceCollection) in AutoDependencyRegistration.Services\RegisterDependenciesService.cs:line 24
   at WebApplication1.Program.Main(String[] args) in path\to\Program.cs:line 18

You can reproduce it by creating a new Web API (.net 6.0), and add Stax.AutoDependencyInjectionRegistration 3.1.0 and Microsoft.Azure.Cosmos 3.35.4.

It looks like something goes wrong while iterating the services here:

image

Let me know if you need more information :)

lukemansell commented 1 year ago

I'll take a look into this one! Thanks for raising the issue

lukemansell commented 1 year ago

This should be fixed in 3.1.1. Thanks for raising the issue!

jepperaskdk commented 1 year ago

Thanks, it seems to work!