コード例 #1
0
        public DependencyContextAssemblyHelper(string assemblyFolder, DependencyContext dependencyContext, IMessageSink internalDiagnosticsMessageSink)
        {
            this.internalDiagnosticsMessageSink = internalDiagnosticsMessageSink;

            assemblyCache = new DependencyContextAssemblyCache(assemblyFolder, dependencyContext, internalDiagnosticsMessageSink);

            AppDomain.CurrentDomain.AssemblyResolve += OnResolving;
        }
コード例 #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="NetCoreAssemblyDependencyResolver"/> class.
        /// </summary>
        /// <param name="assemblyFileName">The path to the assembly</param>
        /// <param name="internalDiagnosticsMessageSink">An optional message sink for use with internal diagnostics messages;
        /// may pass <c>null</c> for no internal diagnostics messages</param>
        public NetCoreAssemblyDependencyResolver(string assemblyFileName, IMessageSink internalDiagnosticsMessageSink)
        {
            this.internalDiagnosticsMessageSink = internalDiagnosticsMessageSink;

            var assembly          = LoadFromAssemblyPath(assemblyFileName);
            var assemblyFolder    = Path.GetDirectoryName(assemblyFileName);
            var dependencyContext = DependencyContext.Load(assembly);

            assemblyCache = new DependencyContextAssemblyCache(assemblyFolder, dependencyContext, internalDiagnosticsMessageSink);

            Default.Resolving += OnResolving;
        }
コード例 #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="NetCoreAssemblyDependencyResolver"/> class.
        /// </summary>
        /// <param name="assemblyFileName">The path to the assembly</param>
        /// <param name="internalDiagnosticsMessageSink">An optional message sink for use with internal diagnostics messages;
        /// may pass <c>null</c> for no internal diagnostics messages</param>
        public AssemblyHelper(string assemblyFileName, IMessageSink internalDiagnosticsMessageSink)
        {
            this.internalDiagnosticsMessageSink = internalDiagnosticsMessageSink;

            if (!File.Exists(assemblyFileName))
            {
                if (internalDiagnosticsMessageSink != null)
                {
                    internalDiagnosticsMessageSink.OnMessage(new _DiagnosticMessage($"[AssemblyHelper_NetCoreApp..ctor] Assembly file not found: '{assemblyFileName}'"));
                }
                return;
            }

            var assembly = LoadFromAssemblyPath(assemblyFileName);

            if (assembly == null)
            {
                if (internalDiagnosticsMessageSink != null)
                {
                    internalDiagnosticsMessageSink.OnMessage(new _DiagnosticMessage($"[AssemblyHelper_NetCoreApp..ctor] Assembly file could not be loaded: '{assemblyFileName}'"));
                }
                return;
            }

            var dependencyContext = DependencyContext.Load(assembly);

            if (dependencyContext == null)
            {
                if (internalDiagnosticsMessageSink != null)
                {
                    internalDiagnosticsMessageSink.OnMessage(new _DiagnosticMessage($"[AssemblyHelper_NetCoreApp..ctor] Assembly file does not contain dependency manifest: '{assemblyFileName}'"));
                }
                return;
            }

            var assemblyFolder = Path.GetDirectoryName(assemblyFileName);

            assemblyCache = new DependencyContextAssemblyCache(assemblyFolder, dependencyContext, internalDiagnosticsMessageSink);

            Default.Resolving += OnResolving;
        }