locked
CAS policy problem RRS feed

  • Question

  • Cannot open any form created in VS 2008 due to error:
    This method uses CAS policy, which has been obsoleted by the .NET Framework. In order to enable CAS policy for compatibility reasons, please use the legacyCasPolicy configuration switch. Please see http://go2.microsoft.com/fwlink/?LinkId=131738 for more information.

    My suggestion is thatVS conversion wizard should take care of it during converting previous version project.
    Conversion project wizard says at finish that project was converted succesfuly but clearly is not. If it was I would be able to open form in designer with no errors.

    Why I'm suggesting like that:.
    I visited  http://go2.microsoft.com/fwlink/?LinkId=131738 but I did not understand anything at all what was written over there. As single developer I do not know about everything Microsoft ever did. Do I have to have such knowledge?
    Its just too much to learn for one person all of stuff that Microsoft made( Microsoft hires thousands of developers in many areas )
     
    If you present a link to solution for problem (http://go2.microsoft.com/fwlink/?LinkId=131738) then please give some solution like step by step tutorial how where and when...

    I hope this thought will help you improve the new VS 2010. By the way, On the error page there is a question "Why I'm seeing this page?"
    Well, why?


    Saturday, May 23, 2009 4:19 AM

Answers

  • Rather than using the environment variable from that blog (which is not officially supported), you'll want to make an .exe.config file to opt your process back into the legacy CAS environment until all of the code that uses old CAS APIs is replaced.

    To do that, each process that uses one of these APIs needs a configuration file that looks like this:
    <configuration>
       <runtime>
         <legacyCasPolicy enabled="true" />
       </runtime>
     </configuration>
    So if your application was named YourApp.exe, you would put a YourApp.exe.config file next to YourApp.exe with those contents.

    Similarly, if you're running into problems with Visual Studio loading custom controls that still use legacy CAS policy, you could update devenv.exe.config (in the Visual Studio 10 installation directory next to devenv.exe) to have the same contents.

    -Shawn Farkas [MS]
    http://blogs.msdn.com/shawnfa
    Monday, June 8, 2009 4:34 PM

All replies

  • Hi, Jerzy62!
    I have the problem "This method uses CAS policy, which has been obsoleted by the .NET Framework" in my projects, too.
    I read this link
    http://blogs.rev-net.com/ddewinter/2009/05/20/opting-out-of-security-changes-in-net-4/
    and add system variable variable COMPLUS_LegacyCASPolicy set to 1 to a system variables.
    But, I dont understand how to make configuration change
    <legacyCasPolicy enabled="true" />
    May be, you can help me, too?
    Excuse me my english.

    Thank you!

    WBR,

    Konstantin


    Sunday, May 24, 2009 4:37 PM
  • Rather than using the environment variable from that blog (which is not officially supported), you'll want to make an .exe.config file to opt your process back into the legacy CAS environment until all of the code that uses old CAS APIs is replaced.

    To do that, each process that uses one of these APIs needs a configuration file that looks like this:
    <configuration>
       <runtime>
         <legacyCasPolicy enabled="true" />
       </runtime>
     </configuration>
    So if your application was named YourApp.exe, you would put a YourApp.exe.config file next to YourApp.exe with those contents.

    Similarly, if you're running into problems with Visual Studio loading custom controls that still use legacy CAS policy, you could update devenv.exe.config (in the Visual Studio 10 installation directory next to devenv.exe) to have the same contents.

    -Shawn Farkas [MS]
    http://blogs.msdn.com/shawnfa
    Monday, June 8, 2009 4:34 PM
  • I tried the above, didnt work at all.

    I updated the app.config in my project and I also updated the devenv.exe.config - it didnt help.

    I tried both legacyCasPolicy and NetFx40_LegacySecurityPolicy , rebuild and restarted Visual Studio - nothing helped...
    Saturday, August 1, 2009 5:37 PM
  • Adding
        <runtime>
            <legacyCasPolicy enabled="true"/>
        </runtime>
    to app.config did not help. However, after adding same configuration options into
    %windir%\Microsoft.NET\Framework\v4.0.30319\Config\machine.config
    did the trick. Enjoy.
    Wednesday, May 12, 2010 1:35 AM