0

This error is sporadic, always on different place. It usually shows when application starts.

Full error:

System.Reflection.ReflectionTypeLoadException: 'Unable to load one or more of the requested types.
Could not load type 'Castle.Proxies.ProductionDataProxy' from assembly 'DynamicProxyGenAssembly2, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'.
Could not load type 'Castle.Proxies.Invocations.ProductionData_set_ProductionDataType' from assembly 'DynamicProxyGenAssembly2, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'.'

It's always different type, mostly in EFCore context. Sometimes in other places where types are loading.

at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
at System.Reflection.Assembly.GetTypes()
at System.Linq.Enumerable.SelectManySingleSelectorIterator`2.MoveNext()
at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
at BaseDbContext..ctor(DbContextOptions options)
at XXX.DatioContext..ctor(DbContextOptions`1 options) in 
C:\XXX\DatioContext.cs:line 36

My projects are .NET 7 projects with few hosted services and controllers. I have no idea what's the problem. Is it a .NET 7 bug?

Thanks!

Qing Guo
  • 6,041
  • 1
  • 2
  • 10
wh1sp3r
  • 1,640
  • 2
  • 17
  • 30
  • Retrieve the LoaderExceptions property for more information. You can find this by examining the exception in the debugger. Have a look at [this answer](https://stackoverflow.com/questions/1091853/error-message-unable-to-load-one-or-more-of-the-requested-types-retrieve-the-l/8824250#8824250). – Qing Guo Jan 03 '23 at 02:36
  • @QingGuo LoadExceptions contains the "full error" i sent. I looks like it's mostly lazy loading proxies making this exceptions, but in random order. – wh1sp3r Jan 03 '23 at 08:20

1 Answers1

0

I solved the problem!

A library I am using for entity framework configuration tried to search loaded assemblies (from AppDomain) for certain interfaces. When It finds a "DynamicProxyGenAssembly2" and calls assembly.GetTypes(), it ends with these exceptions mentioned above.

It was sporadic, because AppDomain assemblies only contain loaded assembly in a memory and sometimes there was "DynamicProxyGenAssembly2" loaded and sometimes not.

I hope it helps to someone who will get same problems as me.

wh1sp3r
  • 1,640
  • 2
  • 17
  • 30