Operation Could Destabilize the Runtime

Operation could destabilize the runtime?

I believe it is an issue of covariance or contravariance as noted by this forum post.

See Covariance and Contravariance in C#, Part Two: Array Covariance and the rest of the Covariance and Contravariance series at Eric Lippert's blog.

Although he is dealing with Arrays in the article I linked, I believe a similar problem presents itself here. With your first example, you are returning an IEnumerable that could contain objects that implement an interface that is larger than ISomeTable (i.e. - you could put a Turtle into an Animals IEnumerable when that IEnumerable can only contain Giraffes). I think the reason it works when you return IQueryable is because that is larger/wider than anything you could return, so you're guaranteed that what you return you will be able to handle(?).

In the second example, OfType is ensuring that what gets returned is an object that stores all the information necessary to return only those elements that can be cast to Giraffe.

I'm pretty sure it has something to do with the issues of type safety outlined above, but as Eric Lippert says Higher Order Functions Hurt My Brain and I am having trouble expressing precisely why this is a co/contravariant issue.

Operation could destabilize the runtime in StructureMap

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.

Petapoco: Operation could destabilize the runtime

I think this is because the hosting environment is set to medium trust. Because PetaPoco generates IL code during normal operations, medium trust hosting environment will not allow it and will throw an exception.

Log4Net.Error throws VerificationException - Operation could destabilize the runtime

System.Security.VerificationException: Operation could destabilize the runtime. This exception will be thrown if the .Net Security system identifies the code as not type safe.

If you run peverify.exe against the log4net.dll version 1.2.11(latest version at this time), you will get the below error.

log4net.Plugin.RemoteLoggingServerPlugin::Attach][offset 0x0000002C] Method is not visible.
1 Error(s) Verifying log4net.dll.

You can find more details on how to make the log4net code to pass the verification in this stackoverflow thread.

System.Security.VerificationException: Operation could destabilize the runtime. (Subsonic 2.2)

Does this fix the problem?

private static void ApplyConfig(System.Collections.Specialized.NameValueCollection config, ref bool parameterValue, string configName)
{
if(config[configName] != null)
{
string val = config[configName];
parameterValue = Convert.ToBoolean(val);
}
}

If not, then try

string val = config[configName];
if (val.ToLower() == "false")
parameterValue = false;
else
parameterValue = true;

There may be 2 reasons why the original code fails. First, earlier version of .NET (probably 1.1) had some type issue. I don't know what exactly, but I suspect it might have failed to identify the type of the value passed straight from the NameValueCollection into ToBoolean. The second possibility is that the value is not "true" or "false", but something else. Again, these 2 may or may not be the reason. I can't know for sure because I don't have SubSonic 2.2.

Unity IoC: Operation could destabilize the runtime

The issue is that Unity automatic factories only support Func<T> and not any other of the Func generics.

You could register the Func you want with Unity and then it will be resolved:

Func<SysConfig, IFileLoader> func = config => container.Resolve<IFileLoader>();
container.RegisterType<Func<SysConfig, IFileLoader>>(new InjectionFactory(c => func));

var processor = container.Resolve<IMyProcessor>();

There are some other solutions out there such as this: Unity's automatic abstract factory



Related Topics



Leave a reply



Submit