상속: IDisposable
예제 #1
0
        private Assembly DefaultResolver(string refname, bool throwOnError)
        {
            Assembly asm = GetDynamicAssembly(refname);

            if (asm != null)
            {
                return(asm);
            }
#if NETSTANDARD
            string dir      = Path.GetDirectoryName(TypeUtil.GetAssembly(typeof(object)).ManifestModule.FullyQualifiedName);
            string filepath = Path.Combine(dir, GetSimpleAssemblyName(refname) + ".dll");
            if (File.Exists(filepath))
            {
                using (RawModule module = OpenRawModule(filepath))
                {
                    AssemblyComparisonResult result;
                    if (module.IsManifestModule && CompareAssemblyIdentity(refname, false, module.GetAssemblyName().FullName, false, out result))
                    {
                        return(LoadAssembly(module));
                    }
                }
            }
            return(null);
#else
            string fileName;
            if (throwOnError)
            {
                try
                {
                    fileName = System.Reflection.Assembly.ReflectionOnlyLoad(refname).Location;
                }
                catch (System.BadImageFormatException x)
                {
                    throw new BadImageFormatException(x.Message, x);
                }
            }
            else
            {
                try
                {
                    fileName = System.Reflection.Assembly.ReflectionOnlyLoad(refname).Location;
                }
                catch (System.BadImageFormatException x)
                {
                    throw new BadImageFormatException(x.Message, x);
                }
                catch (FileNotFoundException)
                {
                    // we intentionally only swallow the FileNotFoundException, if the file exists but isn't a valid assembly,
                    // we should throw an exception
                    return(null);
                }
            }
            return(LoadFile(fileName));
#endif
        }
예제 #2
0
        public Assembly LoadAssembly(RawModule module)
        {
            string   refname = module.GetAssemblyName().FullName;
            Assembly asm     = GetLoadedAssembly(refname);

            if (asm == null)
            {
                asm = module.ToAssembly();
                assemblies.Add(asm);
            }
            return(asm);
        }
예제 #3
0
 public Assembly LoadFile(string path)
 {
     try
     {
         using (RawModule module = OpenRawModule(path))
         {
             return(LoadAssembly(module));
         }
     }
     catch (IOException x)
     {
         throw new FileNotFoundException(x.Message, x);
     }
     catch (UnauthorizedAccessException x)
     {
         throw new FileNotFoundException(x.Message, x);
     }
 }
예제 #4
0
 public Assembly LoadFile(string path)
 {
     try
     {
         if (path.Contains("Windows.Forms"))
         {
             throw new InvalidOperationException("Windows Forms based projects are unsupported!");
         }
         using (RawModule module = OpenRawModule(path))
         {
             return(LoadAssembly(module));
         }
     }
     catch (IOException x)
     {
         throw new FileNotFoundException(x.Message, x);
     }
     catch (UnauthorizedAccessException x)
     {
         throw new FileNotFoundException(x.Message, x);
     }
 }
예제 #5
0
		public Assembly LoadAssembly(RawModule module)
		{
			string refname = module.GetAssemblyName().FullName;
			Assembly asm = GetLoadedAssembly(refname);
			if (asm == null)
			{
				asm = module.ToAssembly();
				assemblies.Add(asm);
			}
			return asm;
		}