Exemple #1
0
 internal SessionAssemblyInfo(AssemblyInfoPacket packet)
 {
     m_Packet = packet;
 }
Exemple #2
0
        /// <summary>
        /// Create a new assembly information object with information from the provided assembly.
        /// </summary>
        /// <param name="target"></param>
        /// <param name="includeLocation">Whether to include the assembly's full path location.</param>
        public SessionAssemblyInfo(Assembly target, bool includeLocation)
        {
            m_Packet          = new AssemblyInfoPacket();
            m_Packet.FullName = target.FullName;

#if NET461 || NET462 || NET47 || NET471 || NET472 || NET48
            m_Packet.GlobalAssemblyCache = target.GlobalAssemblyCache;
#endif
            m_Packet.ImageRuntimeVersion = target.ImageRuntimeVersion;

            // Location path could contain user identity, so suppress it in privacy mode.
            if (includeLocation)
            {
#if !NETSTANDARD2_0
                if (target.ManifestModule is System.Reflection.Emit.ModuleBuilder == false)
                {
#endif
                //location can be iffy.
                try
                {
#if NET461 || NET462 || NET47 || NET471 || NET472 || NET48
                    m_Packet.Location = target.CodeBase;
#else
                    m_Packet.Location = target.Location;
#endif
                }
                // ReSharper disable EmptyGeneralCatchClause
                catch
                // ReSharper restore EmptyGeneralCatchClause
                {
                }
#if !NETSTANDARD2_0
            }
#endif
            }

            AssemblyName targetName = target.GetName();
            m_Packet.Name = targetName.Name;
            m_Packet.ProcessorArchitecture = targetName.ProcessorArchitecture; // Note: Could be null (or meaningless) under Mono?
            m_Packet.CultureName           = targetName.CultureInfo.Name;
            m_Packet.Version = targetName.Version.ToString();

            //and now try to get the file version.  This is risky.
            try
            {
                //use the new get custom attributes static function to avoid problems with getting
                //types loaded via ReflectionOnlyGetType
                IList <CustomAttributeData> attributes = CustomAttributeData.GetCustomAttributes(target);
                foreach (CustomAttributeData attribute in attributes)
                {
                    //we need to find the assembly file version attribute, if there is one..
                    if (attribute.Constructor.ReflectedType == typeof(AssemblyFileVersionAttribute))
                    {
                        m_Packet.FileVersion = attribute.ConstructorArguments[0].Value as string;
                        break;
                    }
                }
            }
            catch
            {
            }
        }