////////////////////////////////////////////////////////////////////////// // Stub ////////////////////////////////////////////////////////////////////////// public static void stub(string podName, DirectoryInfo outDir, bool verbose) { writeLine(" .NET Stub [" + podName + "]"); string fanHome = SysProps.getProperty("fan.home"); string podPath = fanHome + "\\lib\\fan\\" + podName + ".pod"; string target = new FileInfo(outDir + "\\" + podName + ".dll").FullName; if (verbose) { writeLine(" <- " + podPath); Pod pod = Pod.doFind(podName, true, null); List list = pod.types(); string pre = "Fan." + FanUtil.upper(podName) + "."; for (int i = 0; i < list.sz(); i++) { writeLine(" " + pre + (list.get(i) as Type).name()); } writeLine(" -> " + target); } FStore store = new FStore(new ZipFile(podPath)); FPod fpod = new FPod(podName, store); fpod.read(); FTypeEmit.emitPod(fpod, false, target); }
/// <summary> /// Resolve an assembly that cannot be found in /// the current AppDomain. /// </summary> public static Assembly resolveAssembly(object sender, ResolveEventArgs args) { string asmName = getAssemblyName(args.Name); AppDomain domain = AppDomain.CurrentDomain; // check if already loaded Assembly[] current = domain.GetAssemblies(); for (int i = 0; i < current.Length; i++) { if (asmName == current[i].GetName().Name) { return(current[i]); } } // otherwise load it from disk string libDir = FileUtil.combine(Sys.m_homeDir, "lib", "dotnet"); string dll = FileUtil.combine(libDir, asmName + ".dll"); FileInfo f = new FileInfo(dll); if (!f.Exists) { // check tmp dir string tmpDir = FileUtil.combine(Sys.m_homeDir, "lib", "tmp"); dll = FileUtil.combine(tmpDir, asmName + ".dll"); f = new FileInfo(dll); } if (!f.Exists) { // not emitted yet, emit Pod pod = Pod.find(asmName, true); return(FTypeEmit.emitPod(pod.fpod, true, null)); } // 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 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); }