none
Getting a Full Trust error calling DataSet.Merge in Framework 4 from desktop application RRS feed

  • Question

  • Not sure if this is the best place to post this, but since it happened during a DataSet.Merge call, I figured I'd start here. In the process of migrating a long-time app from .Net 2 to VS 2010 and .Net 4. Application is WinForms, but with Remoting calls to processes that are started from a Windows Service. Worked fine before upgrade, but now the call to DataSet.Merge throws an exception claiming I need Full Trust. The assemblies are not in the GAC, but are being run from a local drive, so I don't understand why they are not Full Trust. How can I tell .Net that these are Full Trust assemblies?

     

    Tuesday, November 16, 2010 9:59 PM

Answers

  • Although I still have no idea why this problem occurs, I seem to have found a work-around.

    As mentioned, the exception is thrown from the Serialization constructor for the typed DataSet. I added the following lines above that method:

    [SecuritySafeCritical]

    [PermissionSet(SecurityAction.Assert, Unrestricted = true)]

    This did the trick. Since this is a generated dataset, I'll have to fix the code after each generation, or modify the generator itself, but at least I can move on.

    If anyone comes up with why this is needed for code being from the local hard drive, I'd love to hear it!

    • Marked as answer by liurong luo Friday, December 3, 2010 5:24 AM
    Wednesday, December 1, 2010 3:38 PM

All replies

  • Hello,

    Thanks for visiting ADO.NET DataSet forum!

    Would you please provide us more information about the issue? For example, a code snippet where the exception was thrown, or describe the error message as it is.

    If you use CAS(Code Access Security) policy in your application, as far as I know, CAS has a little bit of change in .net framework 4.0. Please take a look at the following article if you are insterested:
    http://www.c-sharpcorner.com/UploadFile/shivprasadk/3950/Default.aspx

    Best regards,


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    If you have any feedback, please tell us.
    Welcome to the All-In-One Code Framework!
    Wednesday, November 17, 2010 4:00 AM
  • The line of code which throws the exception is inside the Serialization constructor for a Typed DataSet, and the line is a call to DataSet.Merge(). The Exception thrown is a SecurityException, with the message "Request Failed." One of the Troubleshooting Tips that pops up is "The application requires Full Trust permissions to run correctly." Most of the exception's members throw the same exception, but the SecurityZone member returns NoZone. The Action member is SecurityAction.Demand, but Demanded just shows an exception.

    I think the important thing is that this TypedDataSet is being used in a Remoting call (which is why it is being de-serialized), and the remoting host is a simple console app which was started from a Windows Service. All executables reside on the local hard drive.

    It seems that somewhere in this convoluted set of executables, one or more are not running under Full Trust, and I just don't know why or how to fix it. Or perhaps there is something about Remoting under Framework 4 that is causing this. As I said, this setup runs just fine under Framework 2, and there were no CAS policy calls or statements needed to do so.

    Wednesday, November 17, 2010 4:13 PM
  • Hi,

    While I do some research into your question, here is an article that discusses changes in .Net Framework 4.0:

    Security Changes in the .Net Framework 4.0 - http://msdn.microsoft.com/en-us/library/dd233103.aspx

    Thanks,

    Cathy Miller

    Microsoft Online Community Support

    Monday, November 22, 2010 2:59 PM
    Moderator
  • Although I still have no idea why this problem occurs, I seem to have found a work-around.

    As mentioned, the exception is thrown from the Serialization constructor for the typed DataSet. I added the following lines above that method:

    [SecuritySafeCritical]

    [PermissionSet(SecurityAction.Assert, Unrestricted = true)]

    This did the trick. Since this is a generated dataset, I'll have to fix the code after each generation, or modify the generator itself, but at least I can move on.

    If anyone comes up with why this is needed for code being from the local hard drive, I'd love to hear it!

    • Marked as answer by liurong luo Friday, December 3, 2010 5:24 AM
    Wednesday, December 1, 2010 3:38 PM
  • Hi JCZ,

    Thanks a lot for sharing your solution! That would be of great benefit for our community members!

    Have a nice day!


    Best Regards,
    Roahn Luo
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg@microsoft.com
    Friday, December 3, 2010 5:24 AM