src/sys/dotnet/fanx/tools/Tool.cs
/// <summary>
/// Resolve an assembly that cannot be found in
/// the current AppDomain.
/// </summary>
Resolve an assembly that cannot be found in
the current AppDomain.
Resolve an assembly that cannot be found in the current AppDomain .
public static Assembly resolveAssembly(object sender, ResolveEventArgs args)
    {
      string asmName = getAssemblyName(args.Name);
      AppDomain domain = AppDomain.CurrentDomain;
      Assembly[] current = domain.GetAssemblies();
      for (int i=0; i<current.Length; i++)
        if (asmName == current[i].GetName().Name)
          return current[i];
      string libDir = FileUtil.combine(Sys.m_homeDir, "lib", "dotnet");
      string dll = FileUtil.combine(libDir, asmName + ".dll");
      FileInfo f = new FileInfo(dll);
      if (!f.Exists)
      {
        string tmpDir = FileUtil.combine(Sys.m_homeDir, "lib", "tmp");
        dll = FileUtil.combine(tmpDir, asmName + ".dll");
        f = new FileInfo(dll);
      }
      if (!f.Exists)
      {
        Pod pod = Pod.find(asmName, true);
        return FTypeEmit.emitPod(pod.fpod, true, null);
      }
      if (!asmName.EndsWith("Native_") && !FTypeEmit.isEmitted(asmName))
      {
        Pod pod = Pod.find(asmName, true);
        return FTypeEmit.emitPod(pod.fpod, true, null);
      }
      BinaryReader fIn = new BinaryReader(f.OpenRead());
      byte[] asm = fIn.ReadBytes((int)f.Length);
      fIn.Close();
      if (asm.Length != f.Length)
        throw new Exception("Could not read " + dll + ": " + asm.Length + " != " + f.Length);
      Assembly result = domain.Load(asm);
      return result;
    }
public static Assembly resolveAssembly ( object sender , ResolveEventArgs args ) { string asmName = getAssemblyName ( args . Name ) ; AppDomain domain = AppDomain . CurrentDomain ; Assembly [ ] current = domain . GetAssemblies ( ) ; for ( int i = 0 ; i < current . Length ; i ++ ) if ( asmName == current [ i ] . GetName ( ) . Name ) return current [ i ] ; string libDir = FileUtil . combine ( Sys . m_homeDir , " " , " " ) ; string dll = FileUtil . combine ( libDir , asmName + " " ) ; FileInfo f = new FileInfo ( dll ) ; if ( ! f . Exists ) { string tmpDir = FileUtil . combine ( Sys . m_homeDir , " " , " " ) ; dll = FileUtil . combine ( tmpDir , asmName + " " ) ; f = new FileInfo ( dll ) ; } if ( ! f . Exists ) { Pod pod = Pod . find ( asmName , true ) ; return FTypeEmit . emitPod ( pod . fpod , true , null ) ; } if ( ! asmName . EndsWith ( " " ) && ! FTypeEmit . isEmitted ( asmName ) ) { Pod pod = Pod . find ( asmName , true ) ; return FTypeEmit . emitPod ( pod . fpod , true , null ) ; } BinaryReader fIn = new BinaryReader ( f . OpenRead ( ) ) ; byte [ ] asm = fIn . ReadBytes ( ( int ) f . Length ) ; fIn . Close ( ) ; if ( asm . Length != f . Length ) throw new Exception ( " " + dll + " " + asm . Length + " " + f . Length ) ; Assembly result = domain . Load ( asm ) ; return result ; }
Resolve an assembly that cannot be found in
the current AppDomain.
Resolve an assembly that cannot be found in the current AppDomain .
// check if already loaded // otherwise load it from disk // check tmp dir // not emitted yet, emit // the file may have been generated by another process, so // check if we need to emit to flush out things this process // will need from FTypeEmit
sender
object
args
ResolveEventArgs