【问题标题】:Getting DirectoryNotFoundException when trying to Connect to Device with CoreCon API尝试使用 CoreCon API 连接到设备时出现 DirectoryNotFoundException
【发布时间】:2010-09-05 15:13:38
【问题描述】:

我正在尝试使用 Visual Studio 2008 中的 CoreCon API 以编程方式启动设备模拟器。当我打电话给device.Connect() 时,我莫名其妙地得到了一个 DirectoryNotFoundException。如果我在 PowerShell 或 C# 控制台应用程序中尝试它,我会得到它。这是我正在使用的代码:

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# visual-studio windows-mobile compact-framework corecon


    【解决方案1】:

    可以在&lt;systemdrive&gt;:\Program files\Common Files\Microsoft Shared\CoreCon\1.0\Bin找到。

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

    【讨论】:

      【解决方案2】:

      安装 VS 2008 SP 1 为我修复了它。

      【讨论】:

        【解决方案3】:

        我怀疑我的 Microsoft.VisualStudio.DeviceConnectivity.Interop 程序集有问题。我找不到磁盘上的副本。它仅在 GAC 中。我试图在 Reflector 中进行检查,但它也需要 Interop 程序集。既然ConManServerClass明明就是COM,那可能是需要注册一个COM库吧?

        【讨论】:

          【解决方案4】:

          我试过了,它工作正常。你能粘贴整个异常和堆栈跟踪吗?

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

          为什么不启动 SysInternals FileMon 或 Process Monitor,这样可以省去一些猜测。

          【讨论】:

            猜你喜欢
            • 2016-11-23
            • 2017-07-29
            • 1970-01-01
            • 1970-01-01
            • 2018-08-04
            • 1970-01-01
            • 1970-01-01
            • 2021-09-05
            • 2021-04-13
            相关资源
            最近更新 更多