Operation could destabilize the runtime

Last post 10-23-2006 8:21 PM by sschack. 16 replies.

Sort Posts:

  • Operation could destabilize the runtime

    04-12-2006, 9:14 AM
    • Contributor
      6,080 point Contributor
    • rodneyjoyce
    • Member since 10-24-2002, 3:45 AM
    • London
    • Posts 1,216
    Hello

    I have a custom web control and get this error when I run under Medium Trust:

    InnerException: Operation could destabilize the runtime.
    Message: DotNetNuke.Services.Exceptions.PageLoadException: Operation could destabilize the runtime. ---> System.Security.VerificationException: Operation could destabilize the runtime. at SmartThinker.DNN.Modules.ModuleFramework.UI.SmartTimePicker.Render(HtmlTextWriter writer) at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) at System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) at System.Web.UI.Control.RenderControl(HtmlTextWriter writer) at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) at

    Can anyone shed any light on it? I need to run in Medium Trust and I am not doing anything fancy in the render method of the control:

            protected override void Render(HtmlTextWriter writer)
            {
                //layout table for control       
                writer.AddAttribute("Cellspacing", "0");
                writer.AddAttribute("Cellpadding", "0");
                writer.AddAttribute("Border", "0");
                writer.RenderBeginTag(HtmlTextWriterTag.Table); //table
                writer.RenderBeginTag(HtmlTextWriterTag.Tr); //tr

                //hrs combo       
                writer.RenderBeginTag(HtmlTextWriterTag.Td); //td
                hrsDD.RenderControl(writer);
                writer.RenderEndTag(); //td
               
                //add hrs label
                writer.RenderBeginTag(HtmlTextWriterTag.Td); //td
                lblHrs.RenderControl(writer);
                writer.RenderEndTag(); //td

                //Add a spacer
                writer.RenderBeginTag(HtmlTextWriterTag.Td); //td
                new LiteralControl(" ").RenderControl(writer);
                writer.RenderEndTag(); //td

                //min combo
                writer.RenderBeginTag(HtmlTextWriterTag.Td); //td
                minsDD.RenderControl(writer);
                writer.RenderEndTag(); //td

                //add mins label
                writer.RenderBeginTag(HtmlTextWriterTag.Td); //td
                lblMins.RenderControl(writer);
                writer.RenderEndTag(); //td

                writer.RenderEndTag(); //tr
                writer.RenderEndTag(); //table
            }


    Much appreciated - I have spent ages searching for a solution to this!


    Rodney

  • Re: Operation could destabilize the runtime

    04-12-2006, 5:02 PM
    • Contributor
      3,067 point Contributor
    • sschack
    • Member since 09-16-2003, 4:06 PM
    • Posts 613
    • AspNetTeam
      Moderator

    We saw this back towards the end of Whidbey for a case where 1.1 DLLs were being used in an ASP.NET 2.0 app.  Apparently the 1.1 compilers for C#/VB.NET had some boundary cases with the IL they emitted.  In 2.0 there were low-level changes in the CLR that made some 1.1 code unverifiable - which leads to the exception you are seeing.  Unfortunately I can't claim to understand what it was the CLR changed - I just know we saw it.

    In our specific case it was a problem with a C# switch statement that had more than 8 conditions - underneath the hood the C# compiler in 1.1 emitted IL code that became unverifiable in 2.0.  I don't see any switch statements in your code above so that's not going to be the specific problem.

    To track down the problem, you should try the old fallback of chopping out all the code except the first line.  Then run the app - see if it fails.  Then uncomment the second line code code - run the app - see if it fails.  Rinse and repeat.  That's literally how we tracked down the issues on our team.

    -Stefan
    ----------------------------------------------------------
    This posting is provided "AS IS" with no warranties, and confers no rights.
  • Re: Operation could destabilize the runtime

    04-12-2006, 8:03 PM
    • Contributor
      6,080 point Contributor
    • rodneyjoyce
    • Member since 10-24-2002, 3:45 AM
    • London
    • Posts 1,216
    Thanks for the reply Stefan - I think you're on to something here. The subcontrol has a large switch statement:


                switch (listType)
                {
                    case ListType.User:
                        UserController userController = new UserController();
                        listDataSource = userController.GetUsers(Utilities.GetModuleUserControl(this).PortalId, true, true);
                        dataValueField = "UserID";
                        dataTextField = "FullName";
                        break;
                    case ListType.ApprovalStatus:
                        listDataSource = listController.GetListEntryInfoCollection("SmartThinker_ApprovalStatus");
                        break;
                    case ListType.CensorStatus:
                        listDataSource = listController.GetListEntryInfoCollection("SmartThinker_Censorship");
                        break;
                    case ListType.GeneralStatus:
                        listDataSource = listController.GetListEntryInfoCollection("SmartThinker_GeneralStatus");
                        break;
                    case ListType.EventCategory:
                        listDataSource = listController.GetListEntryInfoCollection("SmartThinker_EventCategory");
                        break;
                    case ListType.EventDressCode:
                        listDataSource = listController.GetListEntryInfoCollection("SmartThinker_EventDressCode");
                        break;
                    case ListType.EventDuration:
                        listDataSource = listController.GetListEntryInfoCollection("SmartThinker_EventDuration");
                        break;
                    case ListType.EventStatus:
                        listDataSource = listController.GetListEntryInfoCollection("SmartThinker_EventStatus");
                        break;
                    case ListType.EventType:
                        listDataSource = listController.GetListEntryInfoCollection("SmartThinker_EventType");
                        break;
                    case ListType.EventRSVP:
                        listDataSource = listController.GetListEntryInfoCollection("SmartThinker_EventRSVP");
                        break;
                    case ListType.Title:
                        listDataSource = listController.GetListEntryInfoCollection("SmartThinker_Title");
                        break;
                    case ListType.EventInviteType:
                        listDataSource = listController.GetListEntryInfoCollection("SmartThinker_EventInviteType");
                        break;
                    case ListType.QuoteCategory:
                        listDataSource = listController.GetListEntryInfoCollection("SmartThinker_QuoteCategory");
                        break;
                }

    it's late, so I'll only be able to test this in a while, but I'll follow your advice.

    Rodney

  • Re: Operation could destabilize the runtime

    04-12-2006, 9:37 PM
    • Contributor
      3,067 point Contributor
    • sschack
    • Member since 09-16-2003, 4:06 PM
    • Posts 613
    • AspNetTeam
      Moderator

    Heh - looks exactly like what was in our 1.1 assembly - a big switch statement.  Our hack was to change the 1.1 code over to a bunch of if-then statements.  Then we recompiled with VS2003, and were able to successfully use the updated assembly in a partial trust ASP.NET 2.0 app.

    -Stefan
    ----------------------------------------------------------
    This posting is provided "AS IS" with no warranties, and confers no rights.
  • Re: Operation could destabilize the runtime

    04-13-2006, 8:20 AM
    • Contributor
      6,080 point Contributor
    • rodneyjoyce
    • Member since 10-24-2002, 3:45 AM
    • London
    • Posts 1,216
    *sigh* - that didn't work Stefan ;)

    I tried a big list of  "if - else if " stamements with no joy, and then straight "if statements", but no joy... (still same error)

    Any other ideas please?


                if (listType == ListType.User)
                {
                    UserController userController = new UserController();
                    listDataSource = userController.GetUsers(Utilities.GetModuleUserControl(this).PortalId, true, true);
                    dataValueField = "UserID";
                    dataTextField = "FullName";
                }
                if (listType == ListType.ApprovalStatus)
                {
                    listDataSource = listController.GetListEntryInfoCollection("SmartThinker_ApprovalStatus");
                }
                if (listType == ListType.CensorStatus)
                {
                    listDataSource = listController.GetListEntryInfoCollection("SmartThinker_Censorship");
                }
                if (listType == ListType.GeneralStatus)
                {
                    listDataSource = listController.GetListEntryInfoCollection("SmartThinker_GeneralStatus");
                }
                if (listType == ListType.EventCategory)
                {
                    listDataSource = listController.GetListEntryInfoCollection("SmartThinker_EventCategory");
                }
                if (listType == ListType.EventDressCode)
                {
                    listDataSource = listController.GetListEntryInfoCollection("SmartThinker_EventDressCode");
                }
                if (listType == ListType.EventDuration)
                {
                    listDataSource = listController.GetListEntryInfoCollection("SmartThinker_EventDuration");
                }
                if (listType == ListType.EventStatus)
                {
                    listDataSource = listController.GetListEntryInfoCollection("SmartThinker_EventStatus");
                }
                if (listType == ListType.EventType)
                {
                    listDataSource = listController.GetListEntryInfoCollection("SmartThinker_EventType");
                }

                if (listType == ListType.EventRSVP)
                {
                    listDataSource = listController.GetListEntryInfoCollection("SmartThinker_EventRSVP");
                }
                if (listType == ListType.Title)
                {
                    listDataSource = listController.GetListEntryInfoCollection("SmartThinker_Title");
                }
                if (listType == ListType.EventInviteType)
                {
                    listDataSource = listController.GetListEntryInfoCollection("SmartThinker_EventInviteType");
                }
                if (listType == ListType.QuoteCategory)
                {
                    listDataSource = listController.GetListEntryInfoCollection("SmartThinker_QuoteCategory");
                }

    Rodney

  • Re: Operation could destabilize the runtime

    04-13-2006, 9:48 AM
    • Contributor
      6,080 point Contributor
    • rodneyjoyce
    • Member since 10-24-2002, 3:45 AM
    • London
    • Posts 1,216
    Very odd - I've narrowed it down to creating and rendering a LiteralControl in the render method of the custom control - this line:

    new LiteralControl(" ").RenderControl(writer);

    I don't know enough to know why - is that what you would expect?

    Rodney

  • Re: Operation could destabilize the runtime

    04-13-2006, 4:58 PM
    • Contributor
      3,067 point Contributor
    • sschack
    • Member since 09-16-2003, 4:06 PM
    • Posts 613
    • AspNetTeam
      Moderator

    Is this custom control an ASP.NET 1.1 control?  Just wondering because the line of code above works fine in a page on ASP.NET 2.0 running under Medium trust.

    If you remove the line of code you have above, does the custom control work then?

    I don't know why the line of code above would cause the problem - I don't understand the ins and outs of what makes IL verifiable versus not verifiable.  As a long shot - what happens if you first construct the LiteralControl on one line - and then on the next line call RenderControl(..)?

    -Stefan
    ----------------------------------------------------------
    This posting is provided "AS IS" with no warranties, and confers no rights.
  • Re: Operation could destabilize the runtime

    04-14-2006, 2:16 PM
    • Contributor
      6,080 point Contributor
    • rodneyjoyce
    • Member since 10-24-2002, 3:45 AM
    • London
    • Posts 1,216
    Yes, it's a 1.1 control - if  I comment it out it works fine... very strange - I will try your suggestion and get back to you - thanks...
    Rodney

  • Re: Operation could destabilize the runtime

    04-14-2006, 2:46 PM
    • Contributor
      6,080 point Contributor
    • rodneyjoyce
    • Member since 10-24-2002, 3:45 AM
    • London
    • Posts 1,216
    Interesting:

    LiteralControl spacer = new LiteralControl(" ");
    spacer.RenderControl(writer);

    seems to work... so it's the

    new LiteralControl(" ").RenderControl(writer);

    that breaks it!?
    Rodney

  • Re: Operation could destabilize the runtime

    04-14-2006, 3:03 PM
    • Contributor
      3,067 point Contributor
    • sschack
    • Member since 09-16-2003, 4:06 PM
    • Posts 613
    • AspNetTeam
      Moderator
    Beats me why that fixes it!  I'll ask some CLR folks internally if they have any ideas on why rearranging the code in this case fixes the problem.
    -Stefan
    ----------------------------------------------------------
    This posting is provided "AS IS" with no warranties, and confers no rights.
  • Re: Operation could destabilize the runtime

    04-14-2006, 6:15 PM
    • Contributor
      3,067 point Contributor
    • sschack
    • Member since 09-16-2003, 4:06 PM
    • Posts 613
    • AspNetTeam
      Moderator

    Turns out there was a low-level change to how the 2.0 Framework verifies code for a specific type of IL.  And in some cases the older 1.1 compilers emit IL that is now considered unverifiable in 2.0.  This was the response from the CLR gurus:

    The Everett compiler emits the following code for the original 1.1 call:

      IL_0011:  ldloc.0
      IL_0012:  call       instance void [System.Web]System.Web.UI.Control::RenderControl(class [System.Web]System.Web.UI.HtmlTextWriter)

    However RenderControl is a virtual method and due to the stricter requirements for ASP.NET 2.0, this is not considered a safe way to call a virtual method in Whidbey.

    The code change that you made gets emitted as:

      IL_0013:  ldloc.0
      IL_0014:  callvirt   instance void [System.Web]System.Web.UI.Control::RenderControl(class [System.Web]System.Web.UI.HtmlTextWriter)

    From a verification stanpoint, "callvirt" is safe - but "call" isn't.

    -Stefan
    ----------------------------------------------------------
    This posting is provided "AS IS" with no warranties, and confers no rights.
  • Re: Operation could destabilize the runtime

    04-15-2006, 5:02 AM
    • Contributor
      6,080 point Contributor
    • rodneyjoyce
    • Member since 10-24-2002, 3:45 AM
    • London
    • Posts 1,216
    Hmm - interesting - thanks for the help - hopefully this post will  help some other people who run into this obscure problem!

    Rodney

  • Re: Operation could destabilize the runtime

    06-07-2006, 4:45 PM
    • Member
      47 point Member
    • kantreddi
    • Member since 05-01-2006, 4:33 AM
    • Posts 10
    For the last 3 hours I am struggling to solve this "Operation could destabilize the runtime" error. This I encountered when I switched over from Asp.net 1.1 to Asp.net 2.0. After reading the post, I checked my code and changed the SWITCH statement to if else if and now things are running fine.

    Thanks a lot to all.
    Kantreddi
    www.FireCAD.net
  • Re: Operation could destabilize the runtime

    10-15-2006, 9:15 AM
    • Member
      12 point Member
    • pproducts
    • Member since 10-15-2006, 1:08 PM
    • Posts 3

    I have the same error when I want to Render a dataGrid.

      dataGrid.RenderControl(oHtmlTextWriter);

     For the problems mentioned in this thread, a tric did the job. I cannot find the tric for the dataGrid.

    Thanks in advance... I have searched and struggled for days now, but nothing helps... do I have to wait for Delphi 200x, which fully support ASP.NET 2.0, or is there a tric for a dataGrid.Render...

     Regards,

     Peter

  • Re: Operation could destabilize the runtime

    10-16-2006, 2:31 PM
    • Contributor
      3,067 point Contributor
    • sschack
    • Member since 09-16-2003, 4:06 PM
    • Posts 613
    • AspNetTeam
      Moderator
    If you have a sample page with code that reproduces the problem, go ahead and post the sample here.  We can take a look at it.
    -Stefan
    ----------------------------------------------------------
    This posting is provided "AS IS" with no warranties, and confers no rights.
Page 1 of 2 (17 items) 1 2 Next >