尝试使用CoreCon API连接到设备时获取DirectoryNotFoundException

时间:2020-03-05 18:38:47  来源:igfitidea点击:

我正在尝试使用Visual Studio 2008中的CoreCon API来以编程方式启动设备模拟器。当我调用device.Connect()时,我莫名其妙地得到了DirectoryNotFoundException。如果在PowerShell或者CConsole应用程序中尝试它,我会得到它。这是我正在使用的代码:

static void Main(string[] args)
{
     DatastoreManager dm = new DatastoreManager(1033);
     Collection<Platform> platforms = dm.GetPlatforms();

     foreach (var p in platforms)
     {
        Console.WriteLine("{0} {1}", p.Name, p.Id);
     }

     Platform platform = platforms[3];
     Console.WriteLine("Selected {0}", platform.Name);

     Device device = platform.GetDevices()[0];
     device.Connect();
     Console.WriteLine("Device Connected");

     SystemInfo info = device.GetSystemInfo();
     Console.WriteLine("System OS Version:{0}.{1}.{2}",info.OSMajor, info.OSMinor, info.OSBuildNo);

     Console.ReadLine();
}

有人知道为什么我会收到此错误吗?我在WinXP 32位纯简Visual Studio 2008 Pro上运行此程序。我想这是一个配置问题,因为我无法通过控制台应用程序或者PowerShell执行此操作。

这是堆栈跟踪:

System.IO.DirectoryNotFoundException was unhandled

Message="The system cannot find the path specified.\r\n"

Source="Device Connection Manager"

StackTrace:
       at Microsoft.VisualStudio.DeviceConnectivity.Interop.ConManServerClass.ConnectDevice()
       at Microsoft.SmartDevice.Connectivity.Device.Connect()
       at ConsoleApplication1.Program.Main(String[] args) in C:\Documents and Settings\Thomas\Local Settings\Application Data\Temporary Projects\ConsoleApplication1\Program.cs:line 23
       at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()

解决方案

回答

我试过了,它行得通。我们可以粘贴整个异常和堆栈跟踪吗?

更新:奇怪的是,除了在c:\ windows \ assembly \ GAC_MSIL文件夹下之外,我在计算机上都找不到该互操作组件。

为什么不启动SysInternals FileMon或者Process Monitor,它可以节省一些猜测。

回答

我怀疑Microsoft.VisualStudio.DeviceConnectivity.Interop程序集存在问题。我找不到该磁盘上的副本。仅在GAC中。我试图在Reflector中进行检查,但它也需要Interop组件。由于ConManServerClass显然是COM,因此也许必须注册一个COM库?

回答

安装VS 2008 SP 1对我来说已经修复了。

回答

可以在<系统驱动器>:\ Program Files \ Common Files \ Microsoft Shared \ CoreCon \ 1.0 \ Bin中找到它。

这是我们可以获得此dll的路径,因此请将此dll添加到项目中。