简体   繁体   中英

WCF with StructureMap: Operation could destabilize the runtime

I encountered this weird error when I used WCF with StructureMap.

I also tried to search the stack and there are some answers that recommend to install a hotfix: Operation could destabilize the runtime in StructureMap

But I cannot install the hotfix due to "Software Update KB2748645 Installation Wizard does not apply, or is blocked by another condition on your computer. Please click the link below for more details."

public class StructureMapInstanceProvider : IInstanceProvider
{
    private readonly Type _serviceType;
    public StructureMapInstanceProvider(Type serviceType)
    {
        _serviceType = serviceType;
    }
    public object GetInstance(InstanceContext instanceContext, Message message)
    {
        return ObjectFactory.GetInstance(_serviceType); // error thrown here
    }
}

An exception of type 'StructureMap.StructureMapConfigurationException' occurred in StructureMap.dll but was not handled in user code. 
Operation could destabilize the runtime.

Additional information:
Attempting to create a build plan for concrete type ProfileService
1.) Attempting to create a BuildPlan for Instance of ProfileService -- ProfileService
2.) Container.GetInstance(ProfileService)

Stacktrace

   at StructureMap.Building.ConcreteType.SourceFor(String ctorOrSetter, String name, Type dependencyType, Object value) in c:\BuildAgent\work\996e173a8ceccdca\src\StructureMap\Building\ConcreteType.cs:line 200
   at StructureMap.Building.ConcreteType.<>c__DisplayClass4.<BuildConstructorStep>b__3(ParameterInfo x) in c:\BuildAgent\work\996e173a8ceccdca\src\StructureMap\Building\ConcreteType.cs:line 112
   at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
   at StructureMap.StringExtensions.Each[T](IEnumerable`1 enumerable, Action`1 action) in c:\BuildAgent\work\996e173a8ceccdca\src\StructureMap\Extensions.cs:line 10
   at StructureMap.Building.ConstructorStep.Add(IEnumerable`1 dependencies) in c:\BuildAgent\work\996e173a8ceccdca\src\StructureMap\Building\ConstructorStep.cs:line 79
   at StructureMap.Building.ConcreteType.BuildConstructorStep(Type pluggedType, ConstructorInfo constructor, DependencyCollection dependencies, Policies policies) in c:\BuildAgent\work\996e173a8ceccdca\src\StructureMap\Building\ConcreteType.cs:line 115
   at StructureMap.Building.ConcreteType.BuildSource(Type pluggedType, ConstructorInfo constructor, DependencyCollection dependencies, Policies policies) in c:\BuildAgent\work\996e173a8ceccdca\src\StructureMap\Building\ConcreteType.cs:line 27

I really don't understand the error, and I also cannot find where it is from. So I'm opening for suggestion.

After a day of messing around, this is the workaround (not actually a resolution):

In Visual Studio (I'm using 2013), go to:

Tools -> Options -> IntelliTrace -> General -> Unchoose IntelliTrace events and call information (Or Choose IntelliTrace events only )

I don't know why this option caused the problem. But this workaround worked fine for me. You can find a same problem here: https://www.devexpress.com/Support/Center/Question/Details/Q512306

Quoted

outro56 2 years ago
Ok, I think I may have found a workaround as per Q262635, it has to do with IntelliTrace; 
simply changing the IntelliTrace settings to "IntelliTrace events only" was able to get 
around this problem (i.e. Tools->Options->IntelliTrace->General)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM