[70184 Closed] Getting System.Security.VerificationException: Operation could destabilize the runtime

I have this code:

 procedure EditObservationViewModel.SaveUserSettingsToUseForNextObservation;
       
      var
         UserSettings : System.IO.IsolatedStorage.IsolatedStorageSettings;

      procedure StoreID( id : nullable Guid; key : string );
         begin
         if id <> nil then begin
            UserSettings[ key ] := id;
            end;
         end;

      begin
      try
         UserSettings := GetUserSettings;
         if UserSettings = nil then exit; 

         StoreID( Categories.SelectedCategory1:ID, 'Category1ID' );
         StoreID( Categories.SelectedCategory2:ID, 'Category2ID' );
         StoreID( Categories.SelectedCategory3:ID, 'Category3ID' );

         StoreID( Categories.SelectedSubCategory1:ID, 'SubCategory1ID' );
         StoreID( Categories.SelectedSubCategory2:ID, 'SubCategory2ID' );
         StoreID( Categories.SelectedSubCategory3:ID, 'SubCategory3ID' );

         StoreID( SelectedPerson:ID, 'ObserverID' );

         UserSettings.Save;
      except
         on E : IsolatedStorageException do begin
            ShowIsolatedStorageException( e.Message );
            end;
         on e: Exception do raise;
         end;
      end;

That gets this error:

+		e	{System.Security.VerificationException: Operation could destabilize the runtime.
   at Guardian.EditObservation.ViewModels.EditObservationViewModel.SaveUserSettingsToUseForNextObservation()}	System.Security.VerificationException

This occurs on trying to execute this line and does NOT go into the StoreID procedure:

     StoreID( SelectedPerson:ID, 'ObserverID' );

Neither the SelectedPerson, nor the ID are nil. Other calls above it do have nils, but seem to execute just fine.

Do you have some more code for me? Specifically the definition of Categories (and their sub properties). The verification exception generally means the compiler generates bad code.

Luckily, I don’t have to give you information on Categories. I commented out all the lines except the one that failed before and it still fails. So it is only that one line that is bad.

Here is PersonBase:

type
      PersonBase = public partial class( Object )
         {$REGION Private Section}
         private
            function GetIsEnabled             : boolean;
            function IsProperSecurityLevel    : Boolean;
            function LastTrainingDateOk       : boolean;
            function IsAllowedToObserve       : Boolean;
            function IsTrainedButNotObserving : boolean;
            function HasLastTrainingDate      : boolean;
            function IsBlankOne               : boolean;
         private
            method GetObserverTooltip: String;
            method GetEnabledTooltip: String;
         private
            function GetIsValidObserver: boolean;
         private
            function GetFirstnameLastname: String;
            function GetLastnameFirstname: String;
         {$ENDREGION}
         public
            property LastnameFirstname : String   read GetLastnameFirstname;
            property FirstnameLastname : String   read GetFirstnameLastname;

            property IsValidObserver   : boolean  read GetIsValidObserver;          notify;
            property IsEnabled         : Boolean  read GetIsEnabled;                notify;

            property ObserverTooltip   : String   read GetObserverTooltip;          notify;
            property EnabledTooltip    : String   read GetEnabledTooltip;           notify;

            property Settings : Settings read GetSettings; notify;

            property IsAdmin   : Boolean read GetIsAdmin;
            property IsManager : Boolean read GetIsManager;

            class GlobalSettings : Settings;
         private
            method GetIsManager: Boolean;
            method GetIsAdmin: Boolean;
            method GetSettings: Settings;
         end;

Don’t know if you need more than the definitions. The wsdl generated code for the service class has the rest of the partial class.

Here is the rest of the generated class:

[System.Diagnostics.DebuggerStepThroughAttribute]
[System.CodeDom.Compiler.GeneratedCodeAttribute('System.Runtime.Serialization', '4.0.0.0')]
[System.Runtime.Serialization.DataContractAttribute(Name := 'PersonBase', &Namespace := 'http://schemas.datacontract.org/2004/07/Guardian.EditObservation.DataContracts')]
[System.Runtime.Serialization.KnownTypeAttribute(typeOf(Guardian.EditObservation.DataContracts.Person))]
Guardian.EditObservation.DataContracts.PersonBase = public partial class(System.Object)
private 
    var EmailField: System.String;
    method get_Email: System.String;
    method set_Email(value: System.String);
    var EnabledField: System.Nullable<System.Boolean>;
    method get_Enabled: System.Nullable<System.Boolean>;
    method set_Enabled(value: System.Nullable<System.Boolean>);
    var FirstnameField: System.String;
    method get_Firstname: System.String;
    method set_Firstname(value: System.String);
    var IDField: System.Nullable<System.Guid>;
    method get_ID: System.Nullable<System.Guid>;
    method set_ID(value: System.Nullable<System.Guid>);
    var LastTrainingDateField: System.Nullable<System.DateTime>;
    method get_LastTrainingDate: System.Nullable<System.DateTime>;
    method set_LastTrainingDate(value: System.Nullable<System.DateTime>);
    var LastTrainingDateTimeZoneIDField: System.String;
    method get_LastTrainingDateTimeZoneID: System.String;
    method set_LastTrainingDateTimeZoneID(value: System.String);
    var LastnameField: System.String;
    method get_Lastname: System.String;
    method set_Lastname(value: System.String);
    var SecurityLevelField: Guardian.EditObservation.Enums.SecurityLevel;
    method get_SecurityLevel: Guardian.EditObservation.Enums.SecurityLevel;
    method set_SecurityLevel(value: Guardian.EditObservation.Enums.SecurityLevel);
    var TrainedButNotObservingField: System.Nullable<System.Boolean>;
    method get_TrainedButNotObserving: System.Nullable<System.Boolean>;
    method set_TrainedButNotObserving(value: System.Nullable<System.Boolean>);
public 
    [System.Runtime.Serialization.DataMemberAttribute]
    property Email: System.String read get_Email write set_Email;
    [System.Runtime.Serialization.DataMemberAttribute]
    property Enabled: System.Nullable<System.Boolean> read get_Enabled write set_Enabled;
    [System.Runtime.Serialization.DataMemberAttribute]
    property Firstname: System.String read get_Firstname write set_Firstname;
    [System.Runtime.Serialization.DataMemberAttribute]
    property ID: System.Nullable<System.Guid> read get_ID write set_ID;
    [System.Runtime.Serialization.DataMemberAttribute]
    property LastTrainingDate: System.Nullable<System.DateTime> read get_LastTrainingDate write set_LastTrainingDate;
    [System.Runtime.Serialization.DataMemberAttribute]
    property LastTrainingDateTimeZoneID: System.String read get_LastTrainingDateTimeZoneID write set_LastTrainingDateTimeZoneID;
    [System.Runtime.Serialization.DataMemberAttribute]
    property Lastname: System.String read get_Lastname write set_Lastname;
    [System.Runtime.Serialization.DataMemberAttribute]
    property SecurityLevel: Guardian.EditObservation.Enums.SecurityLevel read get_SecurityLevel write set_SecurityLevel;
    [System.Runtime.Serialization.DataMemberAttribute]
    property TrainedButNotObserving: System.Nullable<System.Boolean> read get_TrainedButNotObserving write set_TrainedButNotObserving;
end;

I changed the SelectedPerson:ID to SelectedPerson.ID and the problem went away. But it only works because I know in the current case that SelectedPerson is not null. I will change my code to just check for null instead of using the “:” syntax. I’ve used that syntax a lot through the code. Don’t know what is different about this one.

Although it might be because it is a partial class. Don’t think I did “:” any place on other partial classes. Not sure, but thought that information might help you.

… time passes …

I changed the StoreID method to be a method of the class and that didn’t change the failure. Now I have this code which still fails:

   procedure EditObservationViewModel.SaveUserSettingsToUseForNextObservation;
       
      var
         UserSettings : System.IO.IsolatedStorage.IsolatedStorageSettings;


      begin
      try
         UserSettings := GetUserSettings;
         if UserSettings = nil then exit; 

         //StoreID( Categories.SelectedCategory1:ID, 'Category1ID' );
         //StoreID( Categories.SelectedCategory2:ID, 'Category2ID' );
         //StoreID( Categories.SelectedCategory3:ID, 'Category3ID' );
//
         //StoreID( Categories.SelectedSubCategory1:ID, 'SubCategory1ID' );
         //StoreID( Categories.SelectedSubCategory2:ID, 'SubCategory2ID' );
         //StoreID( Categories.SelectedSubCategory3:ID, 'SubCategory3ID' );

         var x := SelectedPerson:id;

         StoreID( UserSettings, x, 'ObserverID' );

         UserSettings.Save;
      except
         on E : IsolatedStorageException do begin
            ShowIsolatedStorageException( e.Message );
            end;
         on e: Exception do raise;
         end;
      end;

When I look at this in Reflector, I see:

method EditObservationViewModel.SaveUserSettingsToUseForNextObservation;
begin
    // This item is obfuscated and can not be translated.
    try
        var UserSettings: IsolatedStorageSettings := self.GetUserSettings;
        if (UserSettings <> nil) then begin
            var selectedPerson: PersonBase := self.SelectedPerson;
            if (selectedPerson <> nil) then 
                {pseudo} goto Label_001F;
            var iD: &Nullable<Guid> := selectedPerson.ID;
            var x: &Nullable<Guid> := nil;
            self.StoreID(UserSettings, x, 'ObserverID');
            UserSettings.Save
        end
    except
        on E: IsolatedStorageException do
            self.ShowIsolatedStorageException(E.Message);
        on e: Exception do
            raise new Exception
    end
end;

In case that helps you.

Not sure why the generated code sets iD to something when it isn’t used anywhere since a simple nil is going to passed into the routine as x. But I suppose the Label_001F is the part that was “destabilizing” the runtime.

And my compiler version is OLD. Here is all the version information, in case that helps you:

Microsoft Visual Studio 2010
Version 10.0.40219.1 SP1Rel
Microsoft .NET Framework
Version 4.0.30319 SP1Rel

Installed Version: Professional

Microsoft Office Developer Tools   01018-532-2002102-70042
Microsoft Office Developer Tools

Microsoft Visual Basic 2010   01018-532-2002102-70042
Microsoft Visual Basic 2010

Microsoft Visual C# 2010   01018-532-2002102-70042
Microsoft Visual C# 2010

Microsoft Visual C++ 2010   01018-532-2002102-70042
Microsoft Visual C++ 2010

Microsoft Visual F# 2010   01018-532-2002102-70042
Microsoft Visual F# 2010

Microsoft Visual Studio 2010 Team Explorer   01018-532-2002102-70042
Microsoft Visual Studio 2010 Team Explorer

Microsoft Visual Web Developer 2010   01018-532-2002102-70042
Microsoft Visual Web Developer 2010

Critical Update for Microsoft Visual Studio 2010 Professional - ENU (KB2938807)   KB2938807
This critical update is for Microsoft Visual Studio 2010 Professional - ENU.
If you later install a more recent service pack, this critical update will be uninstalled automatically.
For more information, visit http://support.microsoft.com/kb/2938807.

Crystal Reports Templates for Microsoft Visual Studio 2010   
Crystal Reports Templates for Microsoft Visual Studio 2010

Embarcadero Delphi Prism   4.0.27.843
Embarcadero Delphi Prism
Powered by the RemObjects Oxygene Compiler
Copyright © 2008-2010 Embarcadero Technologies, Inc. All rights reserved. 
All Embarcadero brand and product names are trademarks or registered trademarks of Embarcadero Technologies, Inc. in the United States and other countries. Oxygene is a trademark of RemObjects Software, LLC in the United States and other countries. All other marks are the property of their respective owners.

Dedicated to Rick Wright (1943-2008).
Enjoy the Great Gig in the Sky.

Entity Framework 4.1 Power Tools   1.0
Adds useful design-time DbContext features to the Visual Studio Solution Explorer context menu. 

When right-clicking on a file containing a derived DbContext class, the following context menu functions are supported:

1) View Entity Data Model - Displays the underlying Code First model in the Entity Framework designer.
2) View Entity Data Model XML - Displays the EDMX XML representing the underlying Code First model.
3) Optimize Entity Data Model - Generates pre-compiled views used by the EF runtime to improve start-up performance. Adds the generated views file to the containing project.

Git Source Control Provider   1.0.0.0


Hotfix for Microsoft Visual Studio 2010 Professional - ENU (KB2529927)   KB2529927
This hotfix is for Microsoft Visual Studio 2010 Professional - ENU.
If you later install a more recent service pack, this hotfix will be uninstalled automatically.
For more information, visit http://support.microsoft.com/kb/2529927.

Hotfix for Microsoft Visual Studio 2010 Professional - ENU (KB2548139)   KB2548139
This hotfix is for Microsoft Visual Studio 2010 Professional - ENU.
If you later install a more recent service pack, this hotfix will be uninstalled automatically.
For more information, visit http://support.microsoft.com/kb/2548139.

Hotfix for Microsoft Visual Studio 2010 Professional - ENU (KB2549864)   KB2549864
This hotfix is for Microsoft Visual Studio 2010 Professional - ENU.
If you later install a more recent service pack, this hotfix will be uninstalled automatically.
For more information, visit http://support.microsoft.com/kb/2549864.

Hotfix for Microsoft Visual Studio 2010 Professional - ENU (KB2565057)   KB2565057
This hotfix is for Microsoft Visual Studio 2010 Professional - ENU.
If you later install a more recent service pack, this hotfix will be uninstalled automatically.
For more information, visit http://support.microsoft.com/kb/2565057.

Hotfix for Microsoft Visual Studio 2010 Professional - ENU (KB2635973)   KB2635973
This hotfix is for Microsoft Visual Studio 2010 Professional - ENU.
If you later install a more recent service pack, this hotfix will be uninstalled automatically.
For more information, visit http://support.microsoft.com/kb/2635973.

Hotfix for Microsoft Visual Studio 2010 Professional - ENU (KB2736182)   KB2736182
This hotfix is for Microsoft Visual Studio 2010 Professional - ENU.
If you later install a more recent service pack, this hotfix will be uninstalled automatically.
For more information, visit http://support.microsoft.com/kb/2736182.

Hotfix for Microsoft Visual Studio 2010 Professional - ENU (KB2890573)   KB2890573
This hotfix is for Microsoft Visual Studio 2010 Professional - ENU.
If you later install a more recent service pack, this hotfix will be uninstalled automatically.
For more information, visit http://support.microsoft.com/kb/2890573.

Microsoft Visual Studio 2010 Professional - ENU Service Pack 1 (KB983509)   KB983509
This service pack is for Microsoft Visual Studio 2010 Professional - ENU.
If you later install a more recent service pack, this service pack will be uninstalled automatically.
For more information, visit http://support.microsoft.com/kb/983509.

Microsoft Visual Studio 2010 SharePoint Developer Tools   10.0.40219
Microsoft Visual Studio 2010 SharePoint Developer Tools

NuGet Package Manager   1.4.20615.9020
NuGet Package Manager in Visual Studio. For more information about NuGet, visit http://docs.nuget.org/.

Oracle Developer Tools for Visual Studio   11.2.0.1.2
Oracle Developer Tools for Visual Studio Copyright (c) 2005, 2010

RemObjects Everwood   3.0.17.257
RemObjects Everwood for .NET
Copyright 2003-2010 RemObjects Software, LLC. All rights reserved.
http://www.remobjects.com/everwood

RemObjects Oxygene   4.0.27.843
RemObjects Oxygene
Copyright 2003-2011 RemObjects Software, LLC. All rights reserved.
http://www.remobjects.com/oxygene

Security Update for Microsoft Visual Studio 2010 Professional - ENU (KB2645410)   KB2645410
This security update is for Microsoft Visual Studio 2010 Professional - ENU.
If you later install a more recent service pack, this security update will be uninstalled automatically.
For more information, visit http://support.microsoft.com/kb/2645410.

SQL Server Data Tools   10.3.20905.0
Microsoft SQL Server Data Tools

VisualStudioIntegration2010   1.0
Information about my package

Git Extensions
Git Extensions is a graphical interface for Git
For more information about Git Extensions, see the Git Extensions website at
http://code.google.com/p/gitextensions/
Copyright © 2012 Henk Westhuis

Thanks, logged as bugs://70184: Getting System.Security.VerificationException: Operation could destabilize the runtime

That is a VERY old version. I tried to reproduce this in latest using the following and that seems to work fine. CAn you try with a newer version? Note that Reflector/Ilspy does not properly support our : operator, so having weird jumps in there is to be expected.

unit issue70184test;

interface



uses

  System.Linq, System.Collections.Generic;



type

  ConsoleApp = public class

  public

    class method Main;

    class property SelectedPerson: PersonBase ;

  end;

  PersonBase  = public class

  private

    fID: System.Nullable<Guid>;

  public

      property ID: System.Nullable<Guid> read fID write fID;

  end;



implementation



class method ConsoleApp.Main;

       //var

         //UserSettings : System.IO.IsolatedStorage.IsolatedStorageSettings;



      procedure StoreID( id : nullable Guid; key : string );

         begin

         if id <> nil then begin

            //UserSettings[ key ] := id;

            end;

         end;



      begin

         StoreID( SelectedPerson:ID, 'ObserverID' );

       end;

end.

bugs://70184 got closed as fixed

Yes, I KNOW it is old :slight_smile: I have a newer version, but I can’t move forward to it on our current project. AND on the machine I put the new version on, I can’t seem to get VS installed properly. It keeps thinking it is some sort of trial that has expired. Haven’t tried to resolve that. So I can’t try the new version at the moment.

I’m not surprised that you weren’t able to reproduce it. Remember that the original code had a BUNCH of StoreID calls and all the first ones were fine. There was just something about that last one. And I don’t see what it is. Other than the partial class that I mentioned and which you did not duplicate in your test case. Can’t imagine what the proper case is to construct for it. That was why I at least showed the Reflector code.

Also, I’m not sure why you would make SelectedPerson be a “class property” rather than just a property. I would think that would generate quite different IL.

Also, perhaps I didn’t mention it, but my app is a Silverlight app in case that makes a difference.

Partial couldn’t have done this. Odds are it’s related to the nullable guid (could be the others were wrong too but just didn’t fail).

No the others worked and worked properly with nil values and without nil values. All combinations were present in those calls. That is what seems particularly odd about that one failing, even when the others weren’t present.

ALMOST seemed like it was the LAST one that was the problem though I didn’t play around with that possibility. And of course, your example has it as the “last and only” one. Mystery to me.

I’ve got the nullable guids spread all over the code with no problems like this elsewhere. Although it does seem like I had some sort of problem like this a long time ago. Can’t remember any details.

I definitely DID have some issues with nullable guid versus System.Nullable<System.Guid> that gets generated from the wsdl, but this is a variable declared in my code and not a generated one. And I think the problem before was just a compiler error message.

Strange. I’m glad you found a workaround though. What issue is keeping you from updating btw?