Exemplo n.º 1
0
        public bool TryGetAssemblyPath(MetadataAssemblyReference assemblyReference, out string path)
        {
            foreach (var resolver in resolvers)
            {
                if (resolver.TryGetAssemblyPath(assemblyReference, out path))
                {
                    return(true);
                }
            }

            path = null;
            return(false);
        }
Exemplo n.º 2
0
        public bool TryGetAssemblyPath(MetadataAssemblyReference assemblyReference, out string path)
        {
            if (assemblyReference != null)
            {
                var baseDirectoryPath = Path.Combine(baseDirectory, assemblyReference.Name + ".dll");

                if (File.Exists(baseDirectoryPath))
                {
                    path = baseDirectoryPath;
                    return(true);
                }
            }

            path = null;
            return(false);
        }
        private bool TryGetCachedInfo(MetadataTypeReference typeReference, out CachedInfo cachedInfo)
        {
            var(assemblyReference, typeName) = NameSpec.FromMetadataTypeReference(typeReference);

            if (assemblyReference == null)
            {
                if (currentAssemblyLoader == null)
                {
                    currentAssemblyLoader = new AssemblyLazyLoader(currentAssemblyStreamFactory.Invoke());
                }

                if (currentAssemblyLoader.TryGetInfo(typeName, this, out cachedInfo))
                {
                    return(true);
                }

                // Attribute values containing enum type references serialize the string.
                // So far all mscorlib enum references I've seen include the assembly name,
                // but this is just in case.

                if (currentAssemblyMscorlibReference == null)
                {
                    currentAssemblyMscorlibReference = GetMscorlibReference(currentAssemblyStreamFactory.Invoke());
                }

                assemblyReference = currentAssemblyMscorlibReference;
            }

            var fullName = assemblyReference.FullName;

            if (!assemblyLoadersByFullName.TryGetValue(fullName, out var loader))
            {
                loader = assemblyResolver.TryGetAssemblyPath(assemblyReference, out var path) ? new AssemblyLazyLoader(File.OpenRead(path)) : null;
                assemblyLoadersByFullName.Add(fullName, loader);
            }

            if (loader == null)
            {
                // We couldn't locate the assembly.
                cachedInfo = default;
                return(false);
            }

            return(loader.TryGetInfo(typeName, this, out cachedInfo));
        }
        public bool TryGetAssemblyPath(MetadataAssemblyReference assemblyReference, out string path)
        {
            if (fusionNotAvailable || assemblyReference?.Version == null || assemblyReference.PublicKeyToken == null)
            {
                path = null;
                return(false);
            }

            try
            {
                if (TryLocate(assemblyReference.FullName, out path))
                {
                    return(true);
                }
            }
            catch (Exception ex) when(
                ex is DllNotFoundException || // CoreCLR
                ex is MarshalDirectiveException)    // Mono
            {
                fusionNotAvailable = true;
                path = null;
                return(false);
            }

            // Ran into this
            if (assemblyReference.CultureName == string.Empty)
            {
                var withoutCultureNeutral = new AssemblyName(assemblyReference.FullName)
                {
                    CultureName = null
                };

                return(TryLocate(withoutCultureNeutral.FullName, out path));
            }

            return(false);
        }
 public TopLevelTypeReference(MetadataAssemblyReference assembly, string @namespace, string name)
 {
     Assembly  = assembly;
     Namespace = @namespace;
     Name      = name;
 }