What does mono-io-layer-error (2) mean, starting a process in Unity?

Viewed 1699

Context is Unity, trying to start a new external process. Code looks like this:

var startinfo = new ProcessStartInfo {
  FileName = RootPath + Executable,
  WorkingDirectory = RootPath,
  UseShellExecute = true,
  WindowStyle = Visible ? ProcessWindowStyle.Normal : ProcessWindowStyle.Hidden,
};
try {
  _process = Process.Start(startinfo);
  return true;
} catch (Exception ex) {
  _global.Fail($"Unable to start engine {startinfo.FileName}.\n{ex.ToString()}");
  return false;
}

This works just fine in the Editor, but Build&Run fails with the following error:

System.ComponentModel.Win32Exception (0x80004005): mono-io-layer-error (2)
  at System.Diagnostics.Process.StartWithShellExecuteEx (System.Diagnostics.ProcessStartInfo startInfo) [0x00102] in <3df7f9ca50404bbc8bd4e7b954e70293>:0 
  at System.Diagnostics.Process.Start () [0x00032] in <3df7f9ca50404bbc8bd4e7b954e70293>:0 
  at (wrapper remoting-invoke-with-check) System.Diagnostics.Process.Start()
  at System.Diagnostics.Process.Start (System.Diagnostics.ProcessStartInfo startInfo) [0x0001b] in <3df7f9ca50404bbc8bd4e7b954e70293>:0 
  at ServerManager.StartServer () [0x00049] in <5143145dfb5b4093ac2347595a160b5c>:0 

What does it mean? I can find nothing like it on the Web.

My guess is that the feature is perhaps not supported in the built version, but I have no way of finding out for sure or where to look for alternative approaches. At the end of the day all I really need is a way to launch an external process from a built Unity project.

1 Answers

This is a rather peculiar error, it might be a Unity bug. I've noticed that this error occurs when you usually try to concatenate or combine paths in the "FileName". The methods used for finding or combining paths dynamically are seem to be causing this problem. In my case, I was trying to find the path like this:

FileName = Directory.GetCurrentDirectory() + @"\SBERT\dist\SBERT\SBERT.exe",

However, I have found a workaround to this problem by assigning a fully hard-coded path in the "FileName" like:

FileName = @"C:\SBERT\dist\SBERT\SBERT.exe",

Hope this helps for someone, as there is no information about this error on the internet.

Related