Why Unity crashes?

When i run below code Unity crashes,Why?

using UnityEngine;
using System;
using System.Collections.Generic;
using System.Management;

public class SerialPortTest1 : MonoBehaviour {
	
	
	ManagementObjectSearcher mSearch; 
	ManagementObjectCollection mReturn; 
	// Use this for initialization
	void Start () {
		mSearch= new ManagementObjectSearcher("Select * from Win32_SerialPort"); 
		mReturn = mSearch.Get();
		foreach (ManagementObject mObj in mReturn)
		{
			print(mObj["Name"].ToString());
		}
			
	}
	
	// Update is called once per frame
	void Update () {
	
	}
	
	
}

please help me…

Probably because System.Management name space isn’t supported. I don’t see it on unity’s Mono Compatibility support page.

From the header of the document:

You can use .NET class libraries in the scripts you write for Unity. Depending on your .NET Compatibility level selected in your project settings, Unity supports more, or less of the full class libraries. This page contains a list of which classes and methods are available for each .NET compatibility level setting.

You can try and see if switching the compatibility level from just in case you are using the subset, but again, it isn’t listed on the page.

For your own information, you may want to hit up the (if in windows) the Event Viewer after unity crashes and see if an event is logged in applications for you own knowledge.

thanks Landern.

But is there any way to solve this problem…