C# 尝试使用 CoreCon API 连接到设备时获取 DirectoryNotFoundException
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6904/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Getting DirectoryNotFoundException when trying to Connect to Device with CoreCon API
提问by ageektrapped
I'm trying to use the CoreCon API in Visual Studio 2008 to programmatically launch device emulators. When I call device.Connect()
, I inexplicably get a DirectoryNotFoundException. I get it if I try it in PowerShell or in C# Console Application. Here's the code I'm using:
我正在尝试使用 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();
}
Does anyone know why I'm getting this error? I'm running this on WinXP 32-bit, plain jane Visual Studio 2008 Pro. I imagine it's some config issue since I can't do it from a Console app or PowerShell.
有谁知道我为什么会收到这个错误?我在 WinXP 32 位普通 jane Visual Studio 2008 Pro 上运行它。我想这是一些配置问题,因为我无法从控制台应用程序或 PowerShell 执行此操作。
Here's the stack trace:
这是堆栈跟踪:
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()
采纳答案by PrateekSaluja
It can be found at <systemdrive>:\Program files\Common Files\Microsoft Shared\CoreCon\1.0\Bin
.
它可以在<systemdrive>:\Program files\Common Files\Microsoft Shared\CoreCon\1.0\Bin
。
This is the path where you can get this dll, so add this dll to your project.
这是你可以得到这个dll的路径,所以把这个dll添加到你的项目中。
回答by Kev
I tried this and it works ok. Can you paste in the whole exception and stack trace?
我试过这个,它工作正常。你能粘贴整个异常和堆栈跟踪吗?
Updated:Strangely I can't find that interop assy on my machine either other than under the c:\windows\assembly\GAC_MSIL folders.
更新:奇怪的是,除了在 c:\windows\assembly\GAC_MSIL 文件夹下之外,我在我的机器上找不到那个互操作组件。
Why not fire up SysInternals FileMon or Process Monitor, it'd save some guesswork.
为什么不启动 SysInternals FileMon 或 Process Monitor,它会节省一些猜测。
回答by ageektrapped
I suspect there is a problem with my Microsoft.VisualStudio.DeviceConnectivity.Interop assembly. There is no copy of that on disk that I can find. It's in the GAC only. I tried to inspect in Reflector, but it needs that Interop assembly also. Since ConManServerClass is obviously COM, maybe there's a COM library that has to be registered?
我怀疑我的 Microsoft.VisualStudio.DeviceConnectivity.Interop 程序集有问题。我在磁盘上找不到它的副本。它仅在 GAC 中。我尝试在 Reflector 中进行检查,但它也需要该 Interop 程序集。既然ConManServerClass 显然是COM,那么也许有一个必须注册的COM 库?
回答by ageektrapped
Installing VS 2008 SP 1 fixed it for me.
安装 VS 2008 SP 1 为我修复了它。