如何在 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 (将#修改为@)