none
Does web.config support runtime/legacyCorruptedStateExceptionsPolicy? RRS feed

  • Question

  • I'm developing under Windows 7 IIS 7.5.7600.16385 with VS2013 and .net 4.5.1.

    Using a combination of C#, managed C++ and native C++.

    I need to catch memory access violation exceptions thrown by the native C++ code in the C# code.  Under .net 2.0 the memory access violation exceptions were caught without problem.

    For .net 4.0 the exception behavior for "Corrupted State Exceptions" (like memory access violation) has changed.  By default, they are no longer caught by the application code.

      <runtime>
        <legacyCorruptedStateExceptionsPolicy enabled="true" />
      </runtime>

    is supposed to restore the pre .net 4.0 behavior.

    If I place the legacyCorruptedStateExceptionsPolicy lines above in the web applications web.config it seems to be ignored.  A forced memory access violation is not caught and terminates the web server.

    I know I am modifying the correct web.config because if I introduce an error in the web.config IIS tells me there is an error and the path is that of my web.config.  I've checked my entire system, there are no other .config files that set the element to "false".

    If I place the legacyCorruptedStateExceptionsPolicy lines above in the .net 4.0 machine.config it works.  The exception will be caught by my code.

    If I create a test application and place the legacyCorruptedStateExceptionsPolicy lines above in app.config it will also catch memory access violation exceptions.

    Using [HandleProcessCorruptedStateExceptionsAttribute()] also works, but in the short term it is not practical to modify all the calling code.

    I must be missing something.

    It seems that the legacyCorruptedStateExceptionsPolicy is not supported by web.config?

    Does the element belong in a different location than in machine.config or app.config?

    Is there some other way of restoring the pre .net 4.0 "Corrupted State Exceptions" behavior?

    Thanks.

    John


    Tuesday, October 28, 2014 5:05 PM

Answers

  • Hello John,

    Thanks for your clarification for this issue, I would try to reproduce this issue with the provided code, this may take some time and as soon as we get any result, we will tell you. And temperately, you could set this feature in Machine.config as a workaround.

    Update:

    With your provided code, I tested it and reproduced the scenario with the web.config file. Not sure if this is by designed in the web.config file i would suggest that you coudl ask it at the web forum so that web experts might know this scenario. And the solution to modify the machine.config should be a simple way since it does not need to modify the source code.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.



    • Edited by Fred BaoModerator Wednesday, November 5, 2014 9:30 AM
    • Marked as answer by JggDev Monday, November 10, 2014 3:00 PM
    Monday, November 3, 2014 8:52 AM
    Moderator

All replies

  • Hello JggDev,

    >>It seems that the legacyCorruptedStateExceptionsPolicy is not supported by web.config?

    Being not sure about this since we cannot reproduce this scenario, could you please share some related code so that we can make a test with it?

    >>Does the element belong in a different location than in machine.config or app.config?

    According to the description of the MSDN document, the location should under <configuration>  <runtime>… whether it is a web.config or app.config.

    >>Is there some other way of restoring the pre .net 4.0 "Corrupted State Exceptions" behavior?

    The MSDN document already lists all ways of restoring the behavior which you already tried. Maybe you could try to Recompile as a .NET 3.5 assembly and run it in .NET 4.0.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, October 30, 2014 3:37 AM
    Moderator
  • Thank you for your answer.

    The native code I use to simulate the exception that is sometime thrown is;

    char *ptr = 0;

    *ptr = 0;

    This will produce a memory access violation exception.

    It would be best if no Corrupted State Exceptions is ever thrown, but we can't control the 3rd party code.  Nor can we easily replace if the code occasionally throws Corrupted State Exceptions.

    In the C# code there is;

    try

    {

    // call into native code above

    }

    catch(Exception e)

    {

    // handle exception here

    }

    In .net 2.0 the handler would catch a System.AccessViolationException.

    Under .net 4.0 if I place this;

       <runtime>
          <legacyCorruptedStateExceptionsPolicy enabled="true" />
       </runtime>
    </configuration>

    at the bottom of machine.config the code will also catch the exception.

    The same lines as the bottom of the web.config do not have the same effect.  The exception is not caught.

    If I break the web.config (ex., by misspelling the </runtime> as </run>) a configuration error is produced which points to my web config.  So, the modifications are being made to correct file.

    In the machine.config I notice the line in <configSections>;

            <section name="runtime" type="System.Configuration.IgnoreSection, System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" allowLocation="false"/>

    The same line added to web.config have no impact.

    Hope that is of some help.

    Thanks.

    John


    Friday, October 31, 2014 2:58 PM
  • Hello John,

    Thanks for your clarification for this issue, I would try to reproduce this issue with the provided code, this may take some time and as soon as we get any result, we will tell you. And temperately, you could set this feature in Machine.config as a workaround.

    Update:

    With your provided code, I tested it and reproduced the scenario with the web.config file. Not sure if this is by designed in the web.config file i would suggest that you coudl ask it at the web forum so that web experts might know this scenario. And the solution to modify the machine.config should be a simple way since it does not need to modify the source code.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.



    • Edited by Fred BaoModerator Wednesday, November 5, 2014 9:30 AM
    • Marked as answer by JggDev Monday, November 10, 2014 3:00 PM
    Monday, November 3, 2014 8:52 AM
    Moderator
  • Thanks.

    I'm glad you were able to duplicate the issue.

    I'll ask in the web forum as you suggest.

    John

    Monday, November 10, 2014 3:00 PM