3

My Windows Form Application NOT starting due to System.Security.SecurityException. Here is code on Program.cs

 [STAThread]
    static void Main()
    {

        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        Application.Run(new BaseForm());
    }

Stacktrace as below.

StackTrace:
       System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet)
       System.Security.CodeAccessPermission.Demand()
       System.Windows.Forms.Application.add_ThreadException(ThreadExceptionEventHandler value)
       MyApp._0.Program.Main()

I have no idea to solving this... Any hints are appreciated.

1
  • whats in your forms startup?
    – BugFinder
    Oct 27, 2017 at 7:41

2 Answers 2

4

I was struggling a lot on passing this security exception. Read loads of blogs, involved in discussions but nothing worked out.

Finally found 'Enable ClickOnce Security Settings' in msdn. I just followed those steps and disabled the Security Setting in Project properties.

Here is a link hope this helps some: http://msdn.microsoft.com/en-us/library/1sfbfyk0.aspx

2

Solving by myself.

checking my_project app.config, appended unknown security policy settings as below.

<runtime>
   <NetFx40_LegacySecurityPolicy enabled="true" />
</runtime>
<system.web>
<membership defaultProvider="ClientAuthenticationMembershipProvider">
  <providers>
    <add name="ClientAuthenticationMembershipProvider" type="System.Web.ClientServices.Providers.ClientFormsAuthenticationMembershipProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" />
  </providers>
</membership>
<roleManager defaultProvider="ClientRoleProvider" enabled="true">
  <providers>
    <add name="ClientRoleProvider" type="System.Web.ClientServices.Providers.ClientRoleProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" cacheTimeout="86400" />
  </providers>
</roleManager>
</system.web>

Erased ALL, then winform application startup on Visual Studio debug mode.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.