I have a visual studi console app that searches for data about serial ports, and it works great every time. Even if I build the project as a class library (.dll) I can use it in other visual studio projects. But when I try to run it in Unity: System.Management.ManagementObjectSearcher returns null.
My .net project target framework is 3.5 which is as high unity will allow. My unity api compatibility level is .net 2.o. I have a using System.Management; reference and the System.Management.dll is from unity\Editor\Data\Mono\lib\mono\2.0 folder. Any sugestions. I really need this to work.
Here is a test Method:(it returns bad language when not working)
public string TestFindPorts()
{//@testing
try
{
ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_PnPEntity");
List<ManagementObject> objects = new List<ManagementObject>();
foreach (ManagementObject obj in searcher.Get())
{
objects.Add(obj);
}
return "found some----------------+++++++--------";
}
catch (Exception e)
{
//Console.WriteLine("root\\CIMV2 returned no usable results, bluetooth/serial port info is inaccsessible on this computer: " + e);
return "crap idiot code---------------++++++--------";
}
}