private static AssemblyNameExtension ProduceAsBoth(string name)
        {
            AssemblyNameExtension result = new AssemblyNameExtension(new AssemblyName(name));

            // Force the string version to be produced too.
            string backToString = result.FullName;

            return(result);
        }
示例#2
0
        /// <summary>
        /// Given an assemblyNameExtension, is that assembly name in the redist list and does that redist name start with Microsoft-Windows-CLRCoreComp which indicates
        /// the redist entry is a framework redist list rather than a 3rd part redist list.
        /// </summary>
        internal bool FrameworkAssemblyEntryInRedist(AssemblyNameExtension assemblyName)
        {
            if (_redistList == null)
            {
                return(false);
            }

            return(_redistList.FrameworkAssemblyEntryInRedist(assemblyName));
        }
 public void VerifyEmptyPublicKeyspecificVersion()
 {
     Assert.Throws <FileLoadException>(() =>
     {
         AssemblyNameExtension fusionName = new AssemblyNameExtension("System, PublicKeyToken=");
         string path = GlobalAssemblyCache.GetLocation(fusionName, SystemProcessorArchitecture.None, getRuntimeVersion, new Version("2.0.50727"), false, new FileExists(MockFileExists), _getPathFromFusionName, _gacEnumerator, true);
     }
                                       );
 }
 public UnifiedAssemblyName(AssemblyNameExtension preUnified, AssemblyNameExtension postUnified, bool isUnified, Microsoft.Build.Tasks.UnificationReason unificationReason, bool isPrerequisite, bool?isRedistRoot, string redistName)
 {
     this.preUnified        = preUnified;
     this.postUnified       = postUnified;
     this.isUnified         = isUnified;
     this.isPrerequisite    = isPrerequisite;
     this.isRedistRoot      = isRedistRoot;
     this.redistName        = redistName;
     this.unificationReason = unificationReason;
 }
示例#5
0
        private static string CheckForFullFusionNameInGac(AssemblyNameExtension assemblyName, string targetProcessorArchitecture, GetPathFromFusionName getPathFromFusionName)
        {
            string fullName = assemblyName.FullName;

            if ((targetProcessorArchitecture != null) && !assemblyName.HasProcessorArchitectureInFusionName)
            {
                fullName = fullName + ", ProcessorArchitecture=" + targetProcessorArchitecture;
            }
            return(getPathFromFusionName(fullName));
        }
示例#6
0
 public void CreateAssemblyNameExtensionWithNoSimpleName2()
 {
     Assert.Throws <FileLoadException>(() =>
     {
         AssemblyNameExtension extension  = new AssemblyNameExtension("Version=2.0.0.0, Culture=en, PublicKeyToken=b03f5f7f11d50a3a");
         AssemblyNameExtension extension2 = new AssemblyNameExtension("A, Version=2.0.0.0, Culture=en, PublicKeyToken=b03f5f7f11d50a3a");
         extension2.PartialNameCompare(extension);
     }
                                       );
 }
        public void CompareBaseNameRealCase1()
        {
            AssemblyNameExtension a1 = ProduceAsBoth("System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a");
            AssemblyNameExtension a2 = ProduceAsString("System.Drawing");

            int result = a1.CompareBaseNameTo(a2);

            // Base names should be equal.
            Assert.Equal(0, result);
        }
示例#8
0
        /// <summary>
        /// We need to check to see if an assembly name is in our remapping list, if it is we should return a new assemblyNameExtension which has been remapped.
        /// Remapping is usually used for portable libraries where we need to turn one assemblyName that is retargetable to another assemblyname.
        /// </summary>
        internal AssemblyNameExtension RemapAssemblyExtension(AssemblyNameExtension assemblyName)
        {
            // Short-circuit in cases where there is no redist list
            if (_redistList == null)
            {
                return(null);
            }

            return(_redistList.RemapAssembly(assemblyName));
        }
示例#9
0
 public UnifiedAssemblyName(AssemblyNameExtension preUnified, AssemblyNameExtension postUnified, bool isUnified, UnificationReason unificationReason, bool isPrerequisite, bool?isRedistRoot, string redistName)
 {
     PreUnified        = preUnified;
     PostUnified       = postUnified;
     IsUnified         = isUnified;
     IsPrerequisite    = isPrerequisite;
     IsRedistRoot      = isRedistRoot;
     RedistName        = redistName;
     UnificationReason = unificationReason;
 }
示例#10
0
        internal static string GetLocation(AssemblyNameExtension strongName, ProcessorArchitecture targetProcessorArchitecture, GetAssemblyRuntimeVersion getRuntimeVersion, Version targetedRuntimeVersion, bool fullFusionName, Microsoft.Build.Shared.FileExists fileExists, GetPathFromFusionName getPathFromFusionName, GetGacEnumerator getGacEnumerator, bool specificVersion)
        {
            string str = null;

            if (((strongName.GetPublicKeyToken() == null) || (strongName.GetPublicKeyToken().Length == 0)) && (strongName.FullName.IndexOf("PublicKeyToken", StringComparison.OrdinalIgnoreCase) != -1))
            {
                return(str);
            }
            getPathFromFusionName = getPathFromFusionName ?? pathFromFusionName;
            getGacEnumerator      = getGacEnumerator ?? gacEnumerator;
            if (!strongName.HasProcessorArchitectureInFusionName)
            {
                if ((targetProcessorArchitecture != ProcessorArchitecture.MSIL) && (targetProcessorArchitecture != ProcessorArchitecture.None))
                {
                    string str2 = ResolveAssemblyReference.ProcessorArchitectureToString(targetProcessorArchitecture);
                    if (fullFusionName)
                    {
                        str = CheckForFullFusionNameInGac(strongName, str2, getPathFromFusionName);
                    }
                    else
                    {
                        str = GetLocationImpl(strongName, str2, getRuntimeVersion, targetedRuntimeVersion, fileExists, getPathFromFusionName, getGacEnumerator, specificVersion);
                    }
                    if ((str != null) && (str.Length > 0))
                    {
                        return(str);
                    }
                }
                if (fullFusionName)
                {
                    str = CheckForFullFusionNameInGac(strongName, "MSIL", getPathFromFusionName);
                }
                else
                {
                    str = GetLocationImpl(strongName, "MSIL", getRuntimeVersion, targetedRuntimeVersion, fileExists, getPathFromFusionName, getGacEnumerator, specificVersion);
                }
                if ((str != null) && (str.Length > 0))
                {
                    return(str);
                }
            }
            if (fullFusionName)
            {
                str = CheckForFullFusionNameInGac(strongName, null, getPathFromFusionName);
            }
            else
            {
                str = GetLocationImpl(strongName, null, getRuntimeVersion, targetedRuntimeVersion, fileExists, getPathFromFusionName, getGacEnumerator, specificVersion);
            }
            if ((str != null) && (str.Length > 0))
            {
                return(str);
            }
            return(null);
        }
示例#11
0
        public void VerifySimpleNamev2057020()
        {
            // We want to pass a very generic name to get the correct gac entries.
            AssemblyNameExtension fusionName = new AssemblyNameExtension("System");


            string path = GlobalAssemblyCache.GetLocation(fusionName, SystemProcessorArchitecture.None, _runtimeVersion, new Version("2.0.57027"), false, new FileExists(MockFileExists), _getPathFromFusionName, _gacEnumerator, false);

            Assert.NotNull(path);
            Assert.True(path.Equals(system2Path, StringComparison.OrdinalIgnoreCase));
        }
        public void VerifyFusionNamev2057020SpecificVersion()
        {
            // We want to pass a very generic name to get the correct gac entries.
            AssemblyNameExtension fusionName = new AssemblyNameExtension("System, Version=2.0.0.0");


            string path = GlobalAssemblyCache.GetLocation(fusionName, SystemProcessorArchitecture.None, _runtimeVersion, new Version("2.0.0"), false, new FileExists(MockFileExists), _getPathFromFusionName, _gacEnumerator, true);

            Assert.NotNull(path);
            Assert.Equal(system2Path, path);
        }
示例#13
0
            /// <summary>
            /// Deserializing constuctor.
            /// </summary>
            internal FileState(SerializationInfo info, StreamingContext context)
            {
                ErrorUtilities.VerifyThrowArgumentNull(info, "info");

                lastModified   = info.GetDateTime("lastModified");
                assemblyName   = (AssemblyNameExtension)info.GetValue("assemblyName", typeof(AssemblyNameExtension));
                dependencies   = (AssemblyNameExtension[])info.GetValue("dependencies", typeof(AssemblyNameExtension[]));
                scatterFiles   = (string[])info.GetValue("scatterFiles", typeof(string[]));
                runtimeVersion = (string)info.GetValue("runtimeVersion", typeof(string));
                frameworkName  = (FrameworkName)info.GetValue("frameworkName", typeof(FrameworkName));
            }
示例#14
0
        /// <summary>
        /// Compare two Assembly remapping objects
        /// </summary>
        public override bool Equals(object obj)
        {
            AssemblyNameExtension name = obj as AssemblyNameExtension;

            if (obj == null)
            {
                return(false);
            }

            return(Equals(name));
        }
示例#15
0
        public void ExerciseMiscMethods()
        {
            AssemblyNameExtension a1 = s_producers[0](s_assemblyStrings[0]);

            Version newVersion = new Version(1, 2);

            a1.ReplaceVersion(newVersion);
            Assert.True(a1.Version.Equals(newVersion));

            Assert.NotNull(a1.ToString());
        }
示例#16
0
        /// <summary>
        /// Import assembly dependencies.
        /// </summary>
        /// <returns>The array of assembly dependencies.</returns>
        private AssemblyNameExtension[] ImportAssemblyDependencies()
        {
            ArrayList asmRefs    = new ArrayList();
            IntPtr    asmRefEnum = IntPtr.Zero;

            UInt32[] asmRefTokens = new UInt32[GENMAN_ENUM_TOKEN_BUF_SIZE];
            UInt32   fetched;

            // Ensure the enum handle is closed.
            try
            {
                // Enum chunks of refs in 16-ref blocks until we run out.
                do
                {
                    _assemblyImport.EnumAssemblyRefs(ref asmRefEnum, asmRefTokens, (uint)asmRefTokens.Length, out fetched);

                    for (uint i = 0; i < fetched; i++)
                    {
                        // Determine the length of the string to contain the name first.
                        IntPtr hashDataPtr, pubKeyPtr;
                        UInt32 hashDataLength, pubKeyBytes, asmNameLength, flags;
                        _assemblyImport.GetAssemblyRefProps(asmRefTokens[i], out pubKeyPtr, out pubKeyBytes, null, 0, out asmNameLength, IntPtr.Zero, out hashDataPtr, out hashDataLength, out flags);
                        // Allocate assembly name buffer.
                        char[] asmNameBuf = new char[asmNameLength + 1];
                        IntPtr asmMetaPtr = IntPtr.Zero;
                        // Ensure metadata structure is freed.
                        try
                        {
                            // Allocate metadata structure.
                            asmMetaPtr = AllocAsmMeta();
                            // Retrieve the assembly reference properties.
                            _assemblyImport.GetAssemblyRefProps(asmRefTokens[i], out pubKeyPtr, out pubKeyBytes, asmNameBuf, (uint)asmNameBuf.Length, out asmNameLength, asmMetaPtr, out hashDataPtr, out hashDataLength, out flags);
                            // Construct the assembly name and free metadata structure.
                            AssemblyNameExtension asmName = ConstructAssemblyName(asmMetaPtr, asmNameBuf, asmNameLength, pubKeyPtr, pubKeyBytes, flags);
                            // Add the assembly name to the reference list.
                            asmRefs.Add(asmName);
                        }
                        finally
                        {
                            FreeAsmMeta(asmMetaPtr);
                        }
                    }
                } while (fetched > 0);
            }
            finally
            {
                if (asmRefEnum != IntPtr.Zero)
                {
                    _assemblyImport.CloseEnum(asmRefEnum);
                }
            }

            return((AssemblyNameExtension[])asmRefs.ToArray(typeof(AssemblyNameExtension)));
        }
示例#17
0
 internal AssemblyEntry FindHighestVersionInRedistList(AssemblyNameExtension assemblyName)
 {
     foreach (AssemblyEntry entry in this.redistList.FindAssemblyNameFromSimpleName(assemblyName.Name))
     {
         if (entry.AssemblyNameExtension.EqualsIgnoreVersion(assemblyName))
         {
             return(entry);
         }
     }
     return(null);
 }
 public void CreateAssemblyNameExtensionWithNoSimpleName()
 {
     // Mono does not throw on this string
     if (!NativeMethodsShared.IsMono)
     {
         Assert.Throws <FileLoadException>(() =>
         {
             AssemblyNameExtension extension = new AssemblyNameExtension("Version=2.0.0.0, Culture=en, PublicKeyToken=b03f5f7f11d50a3a", true);
         }
                                           );
     }
 }
 public override bool Resolve(AssemblyNameExtension assemblyName, string rawFileNameCandidate, bool isPrimaryProjectReference, bool wantSpecificVersion, string[] executableExtensions, string hintPath, string assemblyFolderKey, ArrayList assembliesConsideredAndRejected, out string foundPath, out bool userRequestedSpecificFile)
 {
     if (((hintPath != null) && (hintPath.Length > 0)) && base.ResolveAsFile(hintPath, assemblyName, isPrimaryProjectReference, wantSpecificVersion, true, assembliesConsideredAndRejected))
     {
         userRequestedSpecificFile = true;
         foundPath = hintPath;
         return(true);
     }
     foundPath = null;
     userRequestedSpecificFile = false;
     return(false);
 }
        public override bool Resolve(AssemblyNameExtension assemblyName, string rawFileNameCandidate, bool isPrimaryProjectReference, bool wantSpecificVersion, string[] executableExtensions, string hintPath, string assemblyFolderKey, ArrayList assembliesConsideredAndRejected, out string foundPath, out bool userRequestedSpecificFile)
        {
            foundPath = null;
            userRequestedSpecificFile = false;
            string str = base.ResolveFromDirectory(assemblyName, isPrimaryProjectReference, wantSpecificVersion, executableExtensions, base.searchPathElement, assembliesConsideredAndRejected);

            if (str != null)
            {
                foundPath = str;
                return(true);
            }
            return(false);
        }
示例#21
0
        public void ExerciseMiscMethods()
        {
            AssemblyNameExtension a1 = producers[0](assemblyStrings[0]);

            Assertion.AssertNotNull(a1.GetHashCode());

            Version newVersion = new Version(1, 2);

            a1.ReplaceVersion(newVersion);
            Assertion.Assert(a1.Version.Equals(newVersion));

            Assertion.AssertNotNull(a1.ToString());
        }
示例#22
0
 /// <summary>
 /// Resolve a reference to a specific file name.
 /// </summary>
 /// <param name="assemblyName">The assemblyname of the reference.</param>
 /// <param name="sdkName">The name of the sdk to resolve.</param>
 /// <param name="rawFileNameCandidate">The reference's 'include' treated as a raw file name.</param>
 /// <param name="isPrimaryProjectReference">Whether or not this reference was directly from the project file (and therefore not a dependency)</param>
 /// <param name="wantSpecificVersion">Whether an exact version match is requested.</param>
 /// <param name="executableExtensions">Allowed executable extensions.</param>
 /// <param name="hintPath">The item's hintpath value.</param>
 /// <param name="assemblyFolderKey">Like "hklm\Vendor RegKey" as provided to a reference by the &lt;AssemblyFolderKey&gt; on the reference in the project.</param>
 /// <param name="assembliesConsideredAndRejected">Receives the list of locations that this function tried to find the assembly. May be "null".</param>
 /// <param name="foundPath">The path where the file was found.</param>
 /// <param name="userRequestedSpecificFile">Whether or not the user wanted a specific file (for example, HintPath is a request for a specific file)</param>
 /// <returns>True if the file was resolved.</returns>
 public abstract bool Resolve
 (
     AssemblyNameExtension assemblyName,
     string sdkName,
     string rawFileNameCandidate,
     bool isPrimaryProjectReference,
     bool wantSpecificVersion,
     string[] executableExtensions,
     string hintPath,
     string assemblyFolderKey,
     ArrayList assembliesConsideredAndRejected,
     out string foundPath,
     out bool userRequestedSpecificFile
 );
示例#23
0
 /// <summary>
 /// Given a strong name, find its path in the GAC.
 /// </summary>
 /// <param name="strongName">The strong name.</param>
 /// <param name="targetProcessorArchitecture">Like x86 or IA64\AMD64.</param>
 /// <param name="getRuntimeVersion">Delegate to get the runtime version from a file path</param>
 /// <param name="targetedRuntimeVersion">What version of the runtime are we targeting</param>
 /// <param name="fullFusionName">Are we guranteed to have a full fusion name. This really can only happen if we have already resolved the assembly</param>
 /// <returns>The path to the assembly. Empty if none exists.</returns>
 internal static string GetLocation
 (
     AssemblyNameExtension strongName,
     ProcessorArchitecture targetProcessorArchitecture,
     GetAssemblyRuntimeVersion getRuntimeVersion,
     Version targetedRuntimeVersion,
     bool fullFusionName,
     FileExists fileExists,
     GetPathFromFusionName getPathFromFusionName,
     GetGacEnumerator getGacEnumerator,
     bool specificVersion
 )
 {
     return(GetLocation(null, strongName, targetProcessorArchitecture, getRuntimeVersion, targetedRuntimeVersion, fullFusionName, fileExists, getPathFromFusionName, getGacEnumerator, specificVersion));
 }
        public void TestAssemblyPatialMatchSimpleName()
        {
            AssemblyNameExtension assemblyNameToMatch    = new AssemblyNameExtension("System.Xml");
            AssemblyNameExtension assemblyNameToNotMatch = new AssemblyNameExtension("System.Xmla");

            foreach (string assembly in s_assembliesForPartialMatch)
            {
                AssemblyNameExtension assemblyToCompare = new AssemblyNameExtension(assembly);

                Assert.True(assemblyNameToMatch.PartialNameCompare(assemblyToCompare));
                Assert.True(assemblyNameToMatch.PartialNameCompare(assemblyToCompare, PartialComparisonFlags.SimpleName));
                Assert.False(assemblyNameToNotMatch.PartialNameCompare(assemblyToCompare));
                Assert.False(assemblyNameToNotMatch.PartialNameCompare(assemblyToCompare, PartialComparisonFlags.SimpleName));
            }
        }
        /// <summary>
        /// Resolve a reference to a specific file name.
        /// </summary>
        /// <param name="assemblyName">The assembly name object of the assembly.</param>
        /// <param name="sdkName"></param>
        /// <param name="rawFileNameCandidate">The reference's 'include' treated as a raw file name.</param>
        /// <param name="isPrimaryProjectReference">Whether or not this reference was directly from the project file (and therefore not a dependency)</param>
        /// <param name="wantSpecificVersion">Whether an exact version match is requested.</param>
        /// <param name="executableExtensions">Allowed executable extensions.</param>
        /// <param name="hintPath">The item's hintpath value.</param>
        /// <param name="assemblyFolderKey">Like "hklm\Vendor RegKey" as provided to a reference by the <AssemblyFolderKey> on the reference in the project.</param>
        /// <param name="assembliesConsideredAndRejected">Receives the list of locations that this function tried to find the assembly. May be "null".</param>
        /// <param name="foundPath">The path where the file was found.</param>
        /// <param name="userRequestedSpecificFile">Whether or not the user wanted a specific file (for example, HintPath is a request for a specific file)</param>
        /// <returns>True if the file was resolved.</returns>
        public override bool Resolve
        (
            AssemblyNameExtension assemblyName,
            string sdkName,
            string rawFileNameCandidate,
            bool isPrimaryProjectReference,
            bool wantSpecificVersion,
            string[] executableExtensions,
            string hintPath,
            string assemblyFolderKey,
            ArrayList assembliesConsideredAndRejected,
            out string foundPath,
            out bool userRequestedSpecificFile
        )
        {
            foundPath = null;
            userRequestedSpecificFile = false;

            if (assemblyName != null)
            {
                // {GAC} was passed in.
                string gacResolved = _getAssemblyPathInGac(assemblyName, targetProcessorArchitecture, getRuntimeVersion,
                                                           targetedRuntimeVersion, fileExists, fullFusionName: false, specificVersion: wantSpecificVersion);

                if (!string.IsNullOrEmpty(gacResolved) && fileExists(gacResolved))
                {
                    foundPath = gacResolved;
                    return(true);
                }
                else
                {
                    // Record this as a location that was considered.
                    if (assembliesConsideredAndRejected != null)
                    {
                        var considered = new ResolutionSearchLocation
                        {
                            FileNameAttempted = assemblyName.FullName,
                            SearchPath        = searchPathElement,
                            AssemblyName      = assemblyName,
                            Reason            = NoMatchReason.NotInGac
                        };
                        assembliesConsideredAndRejected.Add(considered);
                    }
                }
            }

            return(false);
        }
示例#26
0
        /// <summary>
        /// Unify an assembly name according to the fx retarget rules.
        /// </summary>
        /// <param name="assemblyName">The unify-from assembly name.</param>
        /// <param name="unifiedVersion">The new version number.</param>
        /// <param name="isPrerequisite">Whether this assembly will be available on target machines.</param>
        /// <param name="isRedistRoot">May be true, false or null. Null means there was no IsRedistRoot in the redist list.</param>
        /// <param name="redistName">Name of the corresponding Resist specified in the redist list.</param>
        internal void GetInfo
        (
            AssemblyNameExtension assemblyName,
            out Version unifiedVersion,
            out bool isPrerequisite,
            out bool?isRedistRoot,
            out string redistName
        )
        {
            unifiedVersion = assemblyName.Version;
            isPrerequisite = false;
            isRedistRoot   = null;
            redistName     = null;


            // Short-circuit in cases where there is no redist list.
            if (_redistList == null)
            {
                return;
            }

            // If there's no version, for example in a simple name, then no remapping is possible,
            // and this is not a prerequisite.
            if (assemblyName.Version == null)
            {
                return;
            }

            AssemblyEntry highestVersionFromRedistList = FindHighestVersionInRedistList(assemblyName);

            // Could not find the assembly in the redist list. Return as there has been no redist list unification
            if (highestVersionFromRedistList == null)
            {
                return;
            }

            // Dont allow downgrading of reference version due to redist unification because this is automatic rather than something like an appconfig which
            // has to be manually set. However if the major version is 255 then we do want to unify down the version number.
            if (assemblyName.Version <= highestVersionFromRedistList.AssemblyNameExtension.Version || assemblyName.Version.Major == 255)
            {
                unifiedVersion = highestVersionFromRedistList.AssemblyNameExtension.Version;
                isPrerequisite = _redistList.IsPrerequisiteAssembly(highestVersionFromRedistList.FullName);
                isRedistRoot   = _redistList.IsRedistRoot(highestVersionFromRedistList.FullName);
                redistName     = _redistList.RedistName(highestVersionFromRedistList.FullName);

                return;
            }
        }
示例#27
0
        private Assembly ResolveAssembly(AssemblyLoadContext assemblyLoadContext, AssemblyName assemblyName)
#endif
        {
            // Is this our task assembly?
            if (_taskAssemblyFile != null)
            {
                if (FileSystems.Default.FileExists(_taskAssemblyFile))
                {
                    try
                    {
#if FEATURE_APPDOMAIN
                        AssemblyNameExtension taskAssemblyName = new AssemblyNameExtension(AssemblyName.GetAssemblyName(_taskAssemblyFile));
                        AssemblyNameExtension argAssemblyName  = new AssemblyNameExtension(args.Name);

                        if (taskAssemblyName.Equals(argAssemblyName))
                        {
#if (!CLR2COMPATIBILITY)
                            return(Assembly.UnsafeLoadFrom(_taskAssemblyFile));
#else
                            return(Assembly.LoadFrom(_taskAssemblyFile));
#endif
                        }
#else // !FEATURE_APPDOMAIN
                        AssemblyNameExtension taskAssemblyName = new AssemblyNameExtension(AssemblyLoadContext.GetAssemblyName(_taskAssemblyFile));
                        AssemblyNameExtension argAssemblyName  = new AssemblyNameExtension(assemblyName);
                        if (taskAssemblyName.Equals(argAssemblyName))
                        {
                            return(AssemblyLoadContext.Default.LoadFromAssemblyPath(_taskAssemblyFile));
                        }
#endif
                    }
                    // any problems with the task assembly? return null.
                    catch (FileNotFoundException)
                    {
                        return(null);
                    }
                    catch (BadImageFormatException)
                    {
                        return(null);
                    }
                }
            }

            // otherwise, have a nice day.
            return(null);
        }
示例#28
0
            /// <summary>
            /// Deserializing constuctor.
            /// </summary>
            internal FileState(SerializationInfo info, StreamingContext context)
            {
                ErrorUtilities.VerifyThrowArgumentNull(info, nameof(info));

                lastModified   = new DateTime(info.GetInt64("mod"), (DateTimeKind)info.GetInt32("modk"));
                assemblyName   = (AssemblyNameExtension)info.GetValue("an", typeof(AssemblyNameExtension));
                dependencies   = (AssemblyNameExtension[])info.GetValue("deps", typeof(AssemblyNameExtension[]));
                scatterFiles   = (string[])info.GetValue("sfiles", typeof(string[]));
                runtimeVersion = (string)info.GetValue("rtver", typeof(string));
                if (info.GetBoolean("fn"))
                {
                    var frameworkNameVersion = (Version)info.GetValue("fnVer", typeof(Version));
                    var frameworkIdentifier  = info.GetString("fnId");
                    var frameworkProfile     = info.GetString("fmProf");
                    frameworkName = new FrameworkName(frameworkIdentifier, frameworkNameVersion, frameworkProfile);
                }
            }
        private AssemblyNameExtension[] ImportAssemblyDependencies()
        {
            ArrayList list = new ArrayList();
            IntPtr    zero = IntPtr.Zero;

            uint[] asmRefs = new uint[0x10];
            try
            {
                uint num;
                do
                {
                    this.assemblyImport.EnumAssemblyRefs(ref zero, asmRefs, (uint)asmRefs.Length, out num);
                    for (uint i = 0; i < num; i++)
                    {
                        IntPtr ptr2;
                        IntPtr ptr3;
                        uint   num3;
                        uint   num4;
                        uint   num5;
                        uint   num6;
                        this.assemblyImport.GetAssemblyRefProps(asmRefs[i], out ptr3, out num4, null, 0, out num5, IntPtr.Zero, out ptr2, out num3, out num6);
                        char[] strName = new char[num5 + 1];
                        IntPtr amdInfo = IntPtr.Zero;
                        try
                        {
                            amdInfo = this.AllocAsmMeta();
                            this.assemblyImport.GetAssemblyRefProps(asmRefs[i], out ptr3, out num4, strName, (uint)strName.Length, out num5, amdInfo, out ptr2, out num3, out num6);
                            AssemblyNameExtension extension = this.ConstructAssemblyName(amdInfo, strName, num5, ptr3, num4, num6);
                            list.Add(extension);
                        }
                        finally
                        {
                            this.FreeAsmMeta(amdInfo);
                        }
                    }
                }while (num > 0);
            }
            finally
            {
                if (zero != IntPtr.Zero)
                {
                    this.assemblyImport.CloseEnum(zero);
                }
            }
            return((AssemblyNameExtension[])list.ToArray(typeof(AssemblyNameExtension)));
        }
示例#30
0
        public void VerifyAssemblyNameExSerializationByTranslator(string assemblyName)
        {
            AssemblyNameExtension assemblyNameOriginal     = new AssemblyNameExtension(assemblyName);
            AssemblyNameExtension assemblyNameDeserialized = null;

            MemoryStream serializationStream = new MemoryStream();
            ITranslator  writeTranslator     = BinaryTranslator.GetWriteTranslator(serializationStream);

            writeTranslator.Translate(ref assemblyNameOriginal, (ITranslator t) => new AssemblyNameExtension(t));

            serializationStream.Seek(0, SeekOrigin.Begin);
            ITranslator readTranslator = BinaryTranslator.GetReadTranslator(serializationStream, null);

            readTranslator.Translate(ref assemblyNameDeserialized, (ITranslator t) => new AssemblyNameExtension(t));

            assemblyNameDeserialized.ShouldBe(assemblyNameOriginal);
        }