If the objective is just to get exception text to the user you could.
Write it to a text file then open it.
using System.IO
File.WriteAllText(fullFilePath, text);
Then directly open that text file to display to the user.
using System.Diagnostics;
Process.Start(fullFilePath);
Basically something like this sorry this is just super old code its ugly.
/// <summary>
/// WriteExceptionStack
/// </summary>
public static void WriteStackFramesToFile(string errmsg, int numberOfFramesToTrace)
{
string log_tempstring = "\n";
log_tempstring += ("\n Exception Thrown");
log_tempstring += ("\n _______________________________________________________");
log_tempstring += ("\n " + errmsg);
log_tempstring += ("\n _______________________________________________________");
log_tempstring += ("\n StackTrace As Follows \n");
try
{
// Create a StackTrace that captures filename,
// linepieces number and column information.
StackTrace st = new StackTrace(1, true);
int count = st.FrameCount;
if (numberOfFramesToTrace > count) { numberOfFramesToTrace = count; }
//
for (int i = 0; i < numberOfFramesToTrace; i++)
{
StackFrame sf = st.GetFrame(i);
log_tempstring += " \n stack # " + i.ToString();
log_tempstring += " File: " + Path.GetFileNameWithoutExtension( sf.GetFileName() );
log_tempstring += " Method: " + sf.GetMethod().ToString();
log_tempstring += " Line: " + sf.GetFileLineNumber().ToString();
log_tempstring += " Column: " + sf.GetFileColumnNumber().ToString();
// output the full stack frame
}
throw new Exception();
}
catch (Exception e)
{
string fullpath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "ErrorLog.txt");
File.WriteAllText(fullpath, log_tempstring);
Process.Start(fullpath);
throw e;
}
}
Text File Output…
Exception Thrown
_______________________________________________________
We threw this on purpose to get the stack frames
_______________________________________________________
StackTrace As Follows
stack # 0 File: Game1 Method: Void Update(Microsoft.Xna.Framework.GameTime) Line: 66 Column: 13
stack # 1 File: Method: Void DoUpdate(Microsoft.Xna.Framework.GameTime) Line: 0 Column: 0
stack # 2 File: Method: Void Run(Microsoft.Xna.Framework.GameRunBehavior) Line: 0 Column: 0
stack # 3 File: Program Method: Void Main() Line: 17 Column: 17