docs:programming:c_sharp

C# (c sharp)

C# is the programming language of choice for developing .Net applications on Windows.

  • the “Terminal Services” service needs set to “manual”
  • FIXME (move to another page) the Express edition of Visual Studio C++ always builds against the .Net framework (NOT 32-bit native)

.Net is by default configured with CAS (code access security). This causes the executable to throw an exception if security permissions are not configured properly. If the application does not handle this exception, then the user will see an error that lacks information, and gives the appearance that your application is broken (your fault).

To remedy the situation, you need to do something about CAS. The recommended solution is to handle the error.

edit program.cs...

// standard namespaces (for this app)
using System;
using System.Collections.Generic;
using System.Windows.Forms;

// add the following namespaces
using System.Security;
using System.Security.Permissions;

// modify the class to handle the error, similar to the following:
namespace ChecksumUtility
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {

            try
            {
                // Demand full trust permissions
                PermissionSet fullTrust = new
                                PermissionSet(PermissionState.Unrestricted);
                fullTrust.Demand();

                // Perform normal application logic
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new Form1());

                // Report that permissions were not full trust
            }
            catch (SecurityException)
            {
                MessageBox.Show("This application requires full-trust " +
                    "security permissions to execute." +
                    "(maybe you are trying to run this from a network?)");
            } 




        }
    }
}
  • docs/programming/c_sharp.txt
  • Last modified: 2008/08/03 00:25
  • by 127.0.0.1