VerificationException from in parameters (C# 7.2)


#1

Hey there! I’m having some trouble with code running in a sandboxed appdomain. I was making some structs readonly, passing them via “in”. Here’s some example code:

public readonly struct Vec2
{
public readonly float X;
public readonly float Y;
}

public readonly struct TestTransform
{
public readonly Vec2 Offset;
}

private void DoSomething(in TestTransform test)
{
var diff = test.Offset.X - test.Offset.Y;
}

var t = new TestTransform();
DoSomething(t);

This results in an exception in DoSomething: System.Security.VerificationException: ‘Operation could destabilize the runtime.’

Anyone have a clue what is going on here?


#2

It doesn’t seem like the MSDN for Reference Semantics or C# 7.2 mention anything about managed security.

Can you share an example program that shows setting up the sandboxing?


#3

I bypassed the problem by reworking my security solution. I’m not using managed security at all any more, instead using the Chromium sandbox + running CoreCLR. In case anyone gets this in the future, not sure exactly what the problem was, but I suspect it was related to setting AllowPartiallyTrustedCallers on one of my assemblies. Can’t say if that makes any sense at all, but there you have it.


.NET Foundation Website | Blog | Projects | Code of Conduct