Operation could destabilize the runtime in StructureMap

I am getting this error in one of my ASP.NET 4.5 MVC application on my local machine. Other applications setup with ASP.NET 4.5 and using StructureMap work fine.
Error Message

Any help/solution on this would be highly appreciated.
The line of code that causes this is:

using StructureMap;
using StructureMap.Graph;

namespace Management.Web.DependencyResolution
{
    public static class IoC
    {
        public static IContainer Initialize()
        {
            ObjectFactory.Initialize(x =>
            {
                x.Scan(scan =>
                {
                    scan.TheCallingAssembly();
                    scan.WithDefaultConventions();
                    scan.Assembly("Management.Core");
                    scan.Assembly("Management.DAL");
                    scan.Assembly("Management.BusinessServices");
                    scan.Assembly("Management.Infrastructure");
                });
                x.For<INavigationService>().Use<NavigationService>();
            });
            return ObjectFactory.Container;
        }
    }
}

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

There is a .Net update that fixes this issue.
KnowledgeBase 2748645

When you use some third-party controls, you may receive a
System.Security.VerificationException exception. This issue
occurs if the following conditions are true:

The third-party controls use the generic types.

The CLR verifier is enabled by declaring an assembly that is marked as
security-transparent.

The issue is described in more detail in this blog post.

The problem exists on the IL level and is only detected when the CLR
Verifier is executed on the code. The verifier makes sure that the IL
is type safe before it’s sent to the JIT Compiler and if it detects
and issue (like this) it will bark at you.

Method 2

KB2748645 does not apply for Windows 8/8.1/10. In this case, you can try : Run -> Turn Windows features on or off -> reinstall .NET Framework 4.5 & IIS .

Note: if you have ANTS 8.5 Performance Profiler, disable & de-attach it.

It helped in my case.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x