尝试使用 CoreCon API 连接到设备时出现 DirectoryNotFoundException
我正在尝试使用 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()
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:
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.
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()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
可以在
:\Program files\Common Files\Microsoft Shared\CoreCon\1.0\Bin
中找到它。这是您可以获取此 dll 的路径,因此将此 dll 添加到您的项目中。
It can be found at
<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.
我怀疑我的 Microsoft.VisualStudio.DeviceConnectivity.Interop 程序集有问题。 我在磁盘上找不到该文件的副本。 仅在 GAC 中。 我尝试在 Reflector 中进行检查,但它也需要互操作程序集。 由于ConManServerClass显然是COM,也许有一个必须注册的COM库?
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?
安装 VS 2008 SP 1 为我解决了这个问题。
Installing VS 2008 SP 1 fixed it for me.
我尝试过这个,效果很好。 您可以粘贴整个异常和堆栈跟踪吗?
更新: 奇怪的是,除了 c:\windows\ assembly\GAC_MSIL 文件夹下之外,我在我的计算机上找不到该互操作组件。
为什么不启动 SysInternals FileMon 或 Process Monitor,这样可以省去一些猜测。
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.
Why not fire up SysInternals FileMon or Process Monitor, it'd save some guesswork.