2008-08-09 47 views
1

我試圖在Visual Studio 2008中使用CoreCon API以編程方式啓動設備模擬器。當我打電話給device.Connect()時,我莫名得到一個DirectoryNotFoundException。如果我在PowerShell或C#控制檯應用程序中嘗試它,我會得到它。這裏是我使用的代碼:嘗試使用CoreCon API連接到設備時出現DirectoryNotFoundException

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() 

回答

0

它可以在<systemdrive>:\Program files\Common Files\Microsoft Shared\CoreCon\1.0\Bin找到。

這是你可以得到這個dll的路徑,所以把這個dll添加到你的項目中。

0

我想這和它的作品確定。你可以粘貼整個異常和堆棧跟蹤嗎?

更新:奇怪的是我找不到在我的機器上的interop assy,而不是在c:\ windows \ assembly \ GAC_MSIL文件夾下。

爲什麼不啓動SysInternals FileMon或Process Monitor,它可以節省一些猜測。

0

我懷疑我的Microsoft.VisualStudio.DeviceConnectivity.Interop程序集有問題。我沒有找到磁盤上的副本。它僅限於GAC。我試圖在Reflector中檢查,但它也需要Interop程序集。由於ConManServerClass顯然是COM,也許有一個COM庫需要註冊?

相關問題