Try our conversational search powered by Generative AI!

Structure Map randomly not being able to find a concrete instance

Vote:
 

Has anyone had Structure Map randomly not be able to find a concrete instance? I have an Episerver website I work on, and occasionally we get an error related to Activation Error Occurred While Trying to Get Instance of Type [insert-type-here].

It's sporadic and a site restart fixes the problem. The last concrete instance that was failed to be found was one that was registered using the ServiceConfiguration attribute which can be found here https://world.optimizely.com/documentation/developer-guides/CMS/initialization/dependency-injection/.

#271303
Feb 07, 2022 15:28
Vote:
 

I've had some issues with classes that try to do too much in constructor like creating new http clients and setting headers etc. Removing that part of the code outside of constructor helped in my case. (One method had a lock() somewhere in the internal .NET native code for adding headers to httpclient that went bananas on one server)

#272728
Feb 22, 2022 12:29
Vote:
 

@Ryan, do you register instances as singleton? In that case, there's a risk that when some dependency is created, it's created in a faulty state and that faulty state will be used until you restart (or the instance is recreated for some reason). On restart, the singleton instance will be created again and if you're lucky - maybe in the correct state.

I don't think it has anything to do with being registered without a interface, it should work equally good to register just the concrete type.

#276852
Mar 22, 2022 11:27
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.