Microsoft.Diagnostics.Runtime throw excepton on iOS

Girish Kumar Sharma 1 Reputation point

I am looking for the Stack traces for all the threads in the current process. The following code works fine for windows but throws an exception when the same code runs on the iOS platform.

using (var target = DataTarget.CreateSnapshotAndAttach(Process.GetCurrentProcess().Id))
var runtime = target.ClrVersions.First().CreateRuntime();

            // We can't get the thread name from the ClrThead objects, so we'll look for
            // Thread instances on the heap and get the names from those.    
            var threadNameLookup = new Dictionary<int, string>();
            foreach (var obj in runtime.Heap.EnumerateObjects())
                if (!(obj.Type is null) && obj.Type.Name == "System.Threading.Thread")
                    var threadId = obj.ReadField<int>("m_ManagedThreadId");
                    var threadName = obj.ReadStringField("m_Name");
                    threadNameLookup[threadId] = threadName;
            foreach (var thread in runtime.Threads)
                threadNameLookup.TryGetValue(thread.ManagedThreadId, out string threadName);
                    $"ManagedThreadId: {thread.ManagedThreadId}, Name: {threadName}, OSThreadId: {thread.OSThreadId}, Thread: IsAlive: {thread.IsAlive}, IsBackground: {thread.IsBackground} \n");

                foreach (var clrStackFrame in thread.EnumerateStackTrace())



For iOS, it throw error at CreateSnapshotAndAttach

Please suggest a solution.

.NET Runtime
.NET Runtime
.NET: Microsoft Technologies based on the .NET software framework.Runtime: An environment required to run apps that aren't compiled to machine language.
1,115 questions
{count} votes