Powershell 无法[System.Type]::从程序集System.Configuration获取类型的GetType
我正试图在powershell中以编程方式注册soap扩展,正如前面所述,但我对这一特定方法有问题:Powershell 无法[System.Type]::从程序集System.Configuration获取类型的GetType,powershell,reflection,Powershell,Reflection,我正试图在powershell中以编程方式注册soap扩展,正如前面所述,但我对这一特定方法有问题: [System.Type]::GetType(“System.Configuration.ConfigurationElementCollection,System.Configuration”,$true) 使用“2”参数调用“GetType”时出现异常:“无法加载文件或程序集'System.Configuration'或其依赖项之一。系统找不到指定的文件。” 这是直接在powershell.
[System.Type]::GetType(“System.Configuration.ConfigurationElementCollection,System.Configuration”,$true)
使用“2”参数调用“GetType”时出现异常:“无法加载文件或程序集'System.Configuration'或其依赖项之一。系统找不到指定的文件。”
这是直接在powershell.exe中运行此行时Fusion Log Viewer的输出:
*** Assembly Binder Log Entry (9/20/2013 @ 10:42:57 AM) ***
The operation failed.
Bind result: hr = 0x80070002. The system cannot find the file specified.
Assembly manager loaded from: C:\Windows\Microsoft.NET\Framework64\v2.0.50727\mscorwks.dll
Running under executable C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe
--- A detailed error log follows.
=== Pre-bind state information ===
LOG: User = xxx
LOG: DisplayName = System.Configuration
(Partial)
LOG: Appbase = file:///C:/WINDOWS/system32/WindowsPowerShell/v1.0/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = NULL
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: No application configuration file found.
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v2.0.50727\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: The same bind was seen before, and was failed with hr = 0x80070002.
ERR: Unrecoverable error occurred during pre-download check (hr = 0x80070002).
这是运行此PowerGUI脚本编辑器时Fusion日志查看器的输出:
*** Assembly Binder Log Entry (9/20/2013 @ 10:43:38 AM) ***
The operation failed.
Bind result: hr = 0x80070002. The system cannot find the file specified.
Assembly manager loaded from: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dll
Running under executable C:\Program Files (x86)\PowerGUI\ScriptEditor.exe
--- A detailed error log follows.
=== Pre-bind state information ===
LOG: User = xxx
LOG: DisplayName = System.Configuration
(Partial)
WRN: Partial binding information was supplied for an assembly:
WRN: Assembly Name: System.Configuration | Domain ID: 1
WRN: A partial bind occurs when only part of the assembly display name is provided.
WRN: This might result in the binder loading an incorrect assembly.
WRN: It is recommended to provide a fully specified textual identity for the assembly,
WRN: that consists of the simple name, version, culture, and public key token.
WRN: See whitepaper http://go.microsoft.com/fwlink/?LinkId=109270 for more information and common solutions to this issue.
LOG: Appbase = file:///C:/Program Files (x86)/PowerGUI/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = ScriptEditor.exe
Calling assembly : System.Management.Automation, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Program Files (x86)\PowerGUI\ScriptEditor.exe.Config
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/Program Files (x86)/PowerGUI/System.Configuration.DLL.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/PowerGUI/System.Configuration/System.Configuration.DLL.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/PowerGUI/System.Configuration.EXE.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/PowerGUI/System.Configuration/System.Configuration.EXE.
LOG: All probing URLs attempted and failed.
*** Assembly Binder Log Entry (9/20/2013 @ 10:43:38 AM) ***
The operation failed.
Bind result: hr = 0x80070002. The system cannot find the file specified.
Assembly manager loaded from: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dll
Running under executable C:\Program Files (x86)\PowerGUI\ScriptEditor.exe
--- A detailed error log follows.
=== Pre-bind state information ===
LOG: User = xxx
LOG: DisplayName = System.Configuration
(Partial)
WRN: Partial binding information was supplied for an assembly:
WRN: Assembly Name: System.Configuration | Domain ID: 1
WRN: A partial bind occurs when only part of the assembly display name is provided.
WRN: This might result in the binder loading an incorrect assembly.
WRN: It is recommended to provide a fully specified textual identity for the assembly,
WRN: that consists of the simple name, version, culture, and public key token.
WRN: See whitepaper http://go.microsoft.com/fwlink/?LinkId=109270 for more information and common solutions to this issue.
LOG: Appbase = file:///C:/Program Files (x86)/PowerGUI/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = ScriptEditor.exe
Calling assembly : System.Management.Automation, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Program Files (x86)\PowerGUI\ScriptEditor.exe.Config
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/Program Files (x86)/PowerGUI/System.Configuration.DLL.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/PowerGUI/System.Configuration/System.Configuration.DLL.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/PowerGUI/System.Configuration.EXE.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/PowerGUI/System.Configuration/System.Configuration.EXE.
LOG: All probing URLs attempted and failed.
当然,GAC中有装配:
The Global Assembly Cache contains the following assemblies:
System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL
System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL
如果在上面的powershell行中使用程序集全名,则会出现相同的问题。您需要指定程序集限定类型名称,除非该类型位于当前程序集或mscorlib.dll中。这应该起作用:
[System.Type]::GetType("System.Configuration.ConfigurationElementCollection, System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", $true)
您在哪里看到System.GetType接受两个参数?$true在您的调用中的含义是什么?@DavidBrabant:see,true在找不到类型时引发异常是的,它现在正在工作,但是如果我选择版本4.0.0.0,它会再次引发异常,系统无法找到指定的文件。你知道为什么会发生这种情况吗?@Megan powershell v2.0在2.0 clr上运行。它无法加载4.0版本,因为它使用不同的运行时。它甚至找不到程序集,因为这两个版本有单独的GAC。