0

我的问题

如何在主机服务器上没有 gacutil.exe 的情况下将 System.Management.dll 安装/添加到 GAC 中。

问题描述

我有一个 C#.NET 3.5 应用程序,我在其中使用System.Management命名空间来读取USB Serial Device。以下代码在开发机器上运行良好,但是当我们在 System.Management.dll 可用于目标框架目录但在 GAC 位置(file:///C:/windows/assembly/GAC_MSIL)的服务器上部署此 exe 时/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();
4

0 回答 0