private void FillSharePointCSOMInfo(DiagnosticInfo result)
        {
            // hitting CSOM assembly?
            WithSafeAccess(() =>
            {
                var spType = AppDomain.CurrentDomain
                                        .GetAssemblies()
                                        .SelectMany(a => a.GetTypes())
                                        .FirstOrDefault(t => t.FullName == "Microsoft.SharePoint.Client.Field");

                if (spType != null)
                {
                    result.IsCSOMDetected = true;

                    result.CSOMFileLocation = spType.Assembly.Location;

                    var fileInfo = FileVersionInfo.GetVersionInfo(result.CSOMFileLocation);

                    result.CSOMFileVersion = fileInfo.FileVersion;
                    result.CSOMProductVersion = fileInfo.ProductVersion;
                }
                else
                {
                    result.IsCSOMDetected = false;
                }
            }, e =>
            {
                result.SSOMFileVersion = e.ToString();
                result.SSOMProductVersion = e.ToString();
            });
        }
        public virtual DiagnosticInfo GetDiagnosticInfo()
        {
            var result = new DiagnosticInfo();

            FillSPMeta2Info(result);

            FillSharePointSSOMInfo(result);
            FillSharePointCSOMInfo(result);

            return result;
        }
        protected virtual void FillSPMeta2Info(DiagnosticInfo result)
        {
            // assembly location
            WithSafeAccess(() =>
            {
                result.SPMeta2FileLocation = typeof(FieldDefinition).Assembly.Location;
            }, e =>
            {
                result.SPMeta2FileLocation = e.ToString();
            });

            // assembly file version
            WithSafeAccess(() =>
            {
                var fileInfo = FileVersionInfo.GetVersionInfo(result.SPMeta2FileLocation);

                result.SPMeta2FileVersion = fileInfo.FileVersion;
                result.SPMeta2ProductVersion = fileInfo.ProductVersion;
            }, e =>
            {
                result.SPMeta2FileVersion = e.ToString();
                result.SPMeta2ProductVersion = e.ToString();
            });
        }
        private static void ValidateDiagnosticInfo(DiagnosticInfo info)
        {
            Assert.IsNotNull(info);

            Assert.IsNotNull(info.SPMeta2FileLocation);
            Assert.IsNotNull(info.SPMeta2FileVersion);
            Assert.IsNotNull(info.SPMeta2ProductVersion);

            Assert.IsTrue(info.IsSSOMDetected);
            Assert.IsNotNull(info.SSOMFileLocation);
            Assert.IsNotNull(info.SSOMFileVersion);
            Assert.IsNotNull(info.SSOMProductVersion);

            Assert.IsTrue(info.IsCSOMDetected);
            Assert.IsNotNull(info.CSOMFileLocation);
            Assert.IsNotNull(info.CSOMFileVersion);
            Assert.IsNotNull(info.CSOMProductVersion);
        }