如何解决如何在 gacutil.exe 不可用的 GAC 中安装 System.Management.dll
我的问题
如何在主机服务器上没有 gacutil.exe 的情况下将 System.Management.dll 安装/添加到 GAC。
问题描述
我有一个 C#.NET 3.5 应用程序,我在其中使用 System.Management 命名空间来读取 USB 串行设备。以下代码在开发机器上运行良好,但是当我们在 System.Management.dll 可用于目标框架目录的服务器上部署此 exe 时,它在 GAC 位置(file:///C:/windows/assembly/GAC_MSIL)丢失/System.Management/2.0.0.0__b03f5f7f11d50a3a/System.Management.dll ).
**StackTrace**
System.Management
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.8766 (QFE.050727-8700)
CodeBase: file:///C:/windows/assembly/GAC_MSIL/System.Management/2.0.0.0__b03f5f7f11d50a3a/System.Management.dll
**Exception with StackTrace**
System.Management.ManagementException: Not found
at System.Management.ManagementScope.Initialize()
at System.Management.ManagementObjectSearcher.Initialize()
at System.Management.ManagementObjectSearcher.Get()
at ComPort.Form1.GetUSBDevices() in E:\NPPC\PRAVEEN\POC\ComPort\ComPort\Form1.cs:line 46
at ComPort.Form1.BindDDL() in E:\NPPC\PRAVEEN\POC\ComPort\ComPort\Form1.cs:line 28
at ComPort.Form1.button1_Click(Object sender,EventArgs e) in E:\NPPC\PRAVEEN\POC\ComPort\ComPort\Form1.cs:line 36
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.onmouseup(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m,MouseButtons button,Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd,Int32 msg,IntPtr wparam,IntPtr lparam)
using System.Management;
ManagementObjectCollection collection;
using (var searcher = new ManagementObjectSearcher(@"Select * From Win32_SerialPort"))
{
string paytmUPIPort = "";
collection = searcher.Get();
foreach (var serialDevice in collection)
{
paytmUPIPort = string.Format("{0}",serialDevice.GetPropertyValue("deviceid"));
if(paytmUPIPort.toupper().Contains("COM"))
{
collection.dispose();
return paytmUPIPort;
}
}
}
collection.dispose();
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。