I am working on a project to upgrade our app to .Net 4.8 (from 4.5.2). As you can imagine, this has been pretty fun. Due to some dependency changes in other areas we also needed to update the version of Autofac that we are using - We were at 4.9.2, and I bumped it up to 6.1 cause, why not :)
I have been able to address changes to how pipeline events are handled (setting up middleware and all that), but now I am stuck with an issue with registrations. Basically, somewhere during the .Build()
call a NoConstructorsFoundException
is being thrown.
I understand, in general, why this is happening; the class in question is public, but the only constructor is internal. This is in an assembly that is external to the project (though I do control it) - I have looked through the registration code within the "external" assembly to see if there was something there that could be changed, but not seeing anything obvious. I have tried using the .PublicOnly()
extension, but I still end up with the same error.
builder
.RegisterAssemblyTypes(Assembly.Load("MYASSEMBLY"))
.PublicOnly()
.AsImplementedInterfaces()
.InstancePerDependency();
FYI - this is called from the main app as:
builder.RegisterModule<MYASSEMBLY.RegistrationModule>();
Ive also looked through the, literally, hundreds of registrations that are happening within the main app, and not seeing anything obvious.
Lastly, I did try changing the constructor to be public - which works. That class no longer causes this error - the next class that has only an internal constructor, though, does...
I saw this issue, which is a few years old, which seems so similar, but not only does it not seem to apply here, it was fixed in a version earlier than what we had been using before when everything worked as expected.
Thoughts? As a secondary - is there a way to easily see what has changed between 4.9.2 and 6.1 that might impact this?
I expect you want to add your own IConstructorFinder
that includes 'internal' constructors in the list.
See this previous answer for instructions on how to do it.
As for the change in behaviour, in v6 we changed it so constructors are located at container build time, rather than the first time the component was resolved.