ClickOnce, partial trust and APTCA issue with System.ComponentModel.DataAnnotations

I have a 32bit WinForms application targetting .NET 4 which uses some DevExpress stuff. I deploy the application using ClickOnce. At some point, DevExpress tries to make use of DataAnnotations (specially DisplayAttribute), and at that point the application crashes on target computers, but only when launched via ClickOnce. When I launch the application directly (digging out the exe from user local appdata) everything works fine.

I managed to debug the issue and found that a TypeAccessException is thrown from DevExpress code complaining about security and trust levels. I guess launching through ClickOnce sets up some special AppDomain, but can’t see it all clearly yet.

I tried to add this at the entry point, but no success, when I debug it locally it even doesn’t set the property, somehow it remains null after the assignment line.

[STAThread]
static void Main()
{
   AppDomain.CurrentDomain.SetupInformation.PartialTrustVisibleAssemblies = new[] { "System.ComponentModel.DataAnnotations, PublicKey=0024000004800000940000000602000000240000525341310004000001000100b5fc90e7027f67871e773a8fde8938c81dd402ba65b9201d60593e96c492651e889cc13f1415ebb53fac1131ae0bd333c5ee6021672d9718ea31a8aebd0da0072f25d87dba6fc90ffd598ed4da35e44c398c454307e8e33b8426143daec9f596836f97c8f74750e5975c64e2189f45def46b2a2b1247adc3652bf5c308055da9" };
...
}

I’ve extracted (I guess) the correct public key from the .NET 4.0 version.

I’m quite hopeless currently and would like to ask you all if anyone had anything similar with ClickOnce and WinForms. What else could I try to make it work?


Source: .net

Leave a Reply