Example #1
0
        ///////////////////////////////////////////////////////////////////////

#if APPDOMAINS || ISOLATED_INTERPRETERS || ISOLATED_PLUGINS
        private static string GetBasePath(
            Interpreter interpreter, /* OPTIONAL */
            string packagePath,
            ref Result error
            )
        {
            //
            // NOTE: Fetch the raw base directory for the currently executing
            //       application binary.  It is now possible to override the
            //       value used here via the environment.
            //
            string path0 = AssemblyOps.GetAnchorPath();

            if (path0 == null)
            {
                path0 = GlobalState.GetRawBinaryBasePath();
            }

            //
            // NOTE: First, try to use the effective path to the core library
            //       assembly.  This is used to verify that this candidate
            //       application domain base path contains the core library
            //       assembly somewhere underneath it.
            //
            string path1 = GetAssemblyPath();

            if (PathOps.IsUnderPath(interpreter, path1, path0))
            {
                if ((packagePath == null) ||
                    PathOps.IsUnderPath(interpreter, packagePath, path0))
                {
                    return(path0);
                }
            }

            //
            // NOTE: Second, try to use the raw base path for the assembly.
            //       This is used to verify that this candidate application
            //       domain base path contains the core library assembly
            //       somewhere underneath it.
            //
            string path2 = GlobalState.GetRawBasePath();

            if (PathOps.IsUnderPath(interpreter, path1, path2))
            {
                if ((packagePath == null) ||
                    PathOps.IsUnderPath(interpreter, packagePath, path2))
                {
                    return(path2);
                }
            }

            //
            // NOTE: At this point, we have failed to figure out a base path
            //       for the application domain to be created that actually
            //       contains the core library assembly.
            //
            error = String.Format(
                "cannot determine usable base path for the new application " +
                "domain for interpreter {0}, with the raw binary base path " +
                "{1}, assembly path {2}, and raw base path {3}",
                FormatOps.InterpreterNoThrow(interpreter),
                FormatOps.DisplayPath(path0), FormatOps.DisplayPath(path1),
                FormatOps.DisplayPath(path2));

            return(null);
        }