re: What's the funniest comment you've encountered in code? VIEW POST


There is a classic SO thread with many, many fine examples:

and from my own hand in a recent app, at least I remembered the references:

        #region Certificate Management
        private object AssociateCertificate(Uri baseAddress, string certfile, string certpass)
            // NB: The following world of pain is why we want to switch to Kestrel - getting HTTP.sys to use a specific cert is awful.
            // Load the cert..
            // Always ensure the private key is exportable & correctly persisted, thanks Windows:
            X509Certificate2 x509 = new X509Certificate2(certfile, certpass, X509KeyStorageFlags.Exportable | X509KeyStorageFlags.PersistKeySet | X509KeyStorageFlags.MachineKeySet);
            // Ensure it's persisted in the right store (LocalMachine\My)
            // NB: We cannot do this without being an administrative account, but then we can't listen for HTTP either, thanks Windows:
            X509Store store = new X509Store(StoreName.My, StoreLocation.LocalMachine);
            if (!store.Certificates.Contains(x509))

                Trace.WriteLine("Adding cert to store");
            // re-bind it to the listen port - always remove then add, thanks Windows:
            ICertificateBindingConfiguration config = new CertificateBindingConfiguration();
            Guid appId = System.Runtime.InteropServices.Marshal.GetTypeLibGuidForAssembly(System.Reflection.Assembly.GetExecutingAssembly());
            IPEndPoint ep = new IPEndPoint(0, baseAddress.Port);
            try { if (config.Query(ep) != null) config.Delete(ep); } catch { }
            config.Bind(new CertificateBinding(x509.Thumbprint, StoreName.My, ep, appId));
            return baseAddress;
code of conduct - report abuse