Propagate error writer to hostfxr during delegate acquisition.
authorAaron Robinson <arobins@microsoft.com>
Thu, 18 Jul 2019 22:39:36 +0000 (15:39 -0700)
committerAaron Robinson <arobins@microsoft.com>
Fri, 19 Jul 2019 21:11:53 +0000 (14:11 -0700)
Commit migrated from https://github.com/dotnet/core-setup/commit/92fb649965eb488cf5918d371cc1d73d323af2ff

src/installer/corehost/cli/fxr_resolver.h

index 643aa82..eec02cc 100644 (file)
@@ -77,21 +77,27 @@ int load_fxr_and_get_delegate(hostfxr_delegate_type type, THostPathToConfigCallb
         dotnet_root.c_str()
     };
 
-    hostfxr_handle context;
-    int rc = hostfxr_initialize_for_runtime_config(config_path.c_str(), &parameters, &context);
-    if (!STATUS_CODE_SUCCEEDED(rc))
-        return rc;
-
-    rc = hostfxr_get_runtime_delegate(context, type, reinterpret_cast<void**>(delegate));
+    hostfxr_set_error_writer_fn set_error_writer_fn = reinterpret_cast<hostfxr_set_error_writer_fn>(pal::get_symbol(fxr, "hostfxr_set_error_writer"));
 
-    int rcClose = hostfxr_close(context);
-    if (rcClose != StatusCode::Success)
     {
-        assert(false && "Failed to close host context");
-        trace::verbose(_X("Failed to close host context: 0x%x"), rcClose);
-    }
+        propagate_error_writer_t propagate_error_writer_to_hostfxr(set_error_writer_fn);
+
+        hostfxr_handle context;
+        int rc = hostfxr_initialize_for_runtime_config(config_path.c_str(), &parameters, &context);
+        if (!STATUS_CODE_SUCCEEDED(rc))
+            return rc;
+
+        rc = hostfxr_get_runtime_delegate(context, type, reinterpret_cast<void**>(delegate));
 
-    return rc;
+        int rcClose = hostfxr_close(context);
+        if (rcClose != StatusCode::Success)
+        {
+            assert(false && "Failed to close host context");
+            trace::verbose(_X("Failed to close host context: 0x%x"), rcClose);
+        }
+
+        return rc;
+    }
 }
 
 #endif //_COREHOST_CLI_FXR_RESOLVER_H_