title: CIL: "Operation could destabilize the runtime" exception
body: <p>I've been playing with PostSharp a bit and I ran into a nasty problem.</p>
  
  <p>Following IL in Silverlight assembly:</p>
  
  <pre><code>.method public hidebysig specialname newslot virtual final instance void 
  set_AccountProfileModifiedAt(valuetype [mscorlib]System.DateTime 'value') cil managed
  {
      .maxstack 2
      .locals (
          [0] bool ~propertyHasChanged,
          [1] bool CS$4$0000)
      L_0000: nop 
      L_0001: nop 
      L_0002: ldarg.0 
      L_0003: call instance valuetype [mscorlib]System.DateTime 
  
  Accounts.AccountOwner::get_AccountProfileModifiedAt()
      L_0008: ldarg.1 
      L_0009: call bool [mscorlib]System.DateTime::op_Inequality(valuetype 
  
  [mscorlib]System.DateTime, valuetype [mscorlib]System.DateTime)
      L_000e: stloc.0 
      L_000f: ldarg.0 
      L_0010: ldarg.1 
      L_0011: stfld valuetype [mscorlib]System.DateTime 
  
  Accounts.AccountOwner::accountProfileModifiedAt
      L_0016: br.s L_0018
      L_0018: ldloc.0 
      L_0019: ldc.i4.0 
      L_001a: ceq 
      L_001c: stloc.1 
      L_001d: ldloc.1 
      L_001e: brtrue.s L_002b
      L_0020: ldarg.0 
      L_0021: ldstr "AccountProfileModifiedAt"
      L_0026: call instance void 
  
  Accounts.AccountOwner::NotifyPropertyChanged(string)
      L_002b: nop 
      L_002c: leave.s L_002e
      L_002e: ret 
  }
  </code></pre>
  
  <p>triggers System.Security.VerificationException: Operation could destabilize the runtime. exception.
  Reflector parses it OK. What could be wrong with it?</p>
  
  <p><b>Update 1</b>
  Code is intended to work as follows:</p>
  
  <pre><code>public void set_AccountProfileModifiedAt(DateTime value)
  {
      bool propertyHasChanged = this.AccountProfileModifiedAt != value;
      this.accountProfileModifiedAt = value;
      if (propertyHasChanged)
      {
          this.NotifyPropertyChanged("AccountProfileModifiedAt");
      }
  }
  </code></pre>
  
  <p><b>Update 2</b>
  I get specified exception inside the setter itself</p>
  
  <p><b>Update 3</b>
  Making non-static calls as callvirt (NotifyPropertyChanged) does not help</p>
  
  <p><b>Update 4</b>
  Commenting out (for test purposes) code:</p>
  
  <pre><code>L_0018: ldloc.0 
  L_0019: ldc.i4.0 
  L_001a: ceq 
  L_001c: stloc.1 
  L_001d: ldloc.1 
  </code></pre>
  
  <p>and replacing L_001e: brtrue.s L_002b with L_001e: br.s L_002b does the trick but it's an unconditional return - not what I want.</p>
  
  <p><b> Update 5</b>
  If I use C# compiler to mimic required behavior (I still need to do that with Postsharp)
  I get following IL:</p>
  
  <pre><code>.method public hidebysig specialname newslot virtual final instance void 
  
  set_AccountProfileModifiedAt(valuetype [mscorlib]System.DateTime 'value') cil managed
  {
      .maxstack 2
      .locals init (
          [0] bool val,
          [1] bool CS$4$0000)
      L_0000: nop 
      L_0001: ldarg.0 
      L_0002: call instance valuetype [mscorlib]System.DateTime 
  
  Accounts.AccountOwner::get_AccountProfileModifiedAt()
      L_0007: ldarg.1 
      L_0008: call bool [mscorlib]System.DateTime::op_Inequality(valuetype 
  
  [mscorlib]System.DateTime, valuetype [mscorlib]System.DateTime)
      L_000d: stloc.0 
      L_000e: ldarg.0 
      L_000f: ldarg.1 
      L_0010: stfld valuetype [mscorlib]System.DateTime 
  
  Accounts.AccountOwner::accountProfileModifiedAt
      L_0015: ldloc.0 
      L_0016: ldc.i4.0 
      L_0017: ceq 
      L_0019: stloc.1 
      L_001a: ldloc.1 
      L_001b: brtrue.s L_0029
      L_001d: ldarg.0 
      L_001e: ldstr "AccountProfileModifiedAt"
      L_0023: call instance void 
  
  Accounts.AccountOwner::NotifyPropertyChanged(string)
      L_0028: nop 
      L_0029: ret 
  }
  </code></pre>
  
  <p>Note there are minor differences - extra br.s jump at L_0016 and some strange jump  L_001e: brtrue.s L_002b. In compiler version I get direct jump to ret.</p>