none
WHY CHANGING FROM 3.5 TO 4.0 FRAME WORK CAUSE PROBLEMS WITH THE System.Net.WebPermission object? RRS feed

  • Question

  • While changing the .net frame work from 3.5 to 4.0 on a project the System.Net.WebPermission object is now throwing exceptions. It appears to happen on the Assert() method. I pasted all the usuals below. When it's recompiled in 3.5 it works as usual.
    I can not find any documentation for System.Net.WebPermission using the 4.0, has it moved, could the program be missing a reference when compiled with 4.0?
     maybe a little more information: this is a call from a desktop application. It is doing what they used to call 'screen scraping', go figure. It logs on the the website and removes all the html tags/characters. Parses out the specifice data between the tags and then displays it. Don't ask me why, I won't be able to explain to you the misery; I guess there is no web service available.  I don't do Web stuff. I do understand what the permissions is all about, the code has not been touched, what changed with using the different frameworks?

    WebPermission myWebPermission = 
    new WebPermission(System.Security.Permissions.PermissionState.Unrestricted);
     
    myWebPermission.Demand();
    myWebPermission.Assert();

    EXCEPTION THROWN: 
    ex message:
    Cannot perform CAS Asserts in Security Transparent methods
     
    - Current
    '(myWebPermission.ConnectList).Current'
    threw an exception of type 'System.InvalidOperationException'
    object {System.InvalidOperationException}
     
    "Enumeration has not started. Call MoveNext."

    Wednesday, October 23, 2013 3:35 PM

Answers

  • Hi,

    .NET 4.0 is a major version update, some settings are not the same. Specify level 1 transparency for compatibility only for code that was developed with .NET 3.5 or earlier. Please refer to http://msdn.microsoft.com/en-us/library/bb397858.aspx to see how to fix this issue.

    Hope can help you.

    Best 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 24, 2013 9:45 AM
    Moderator