我正在尝试在powershell中以编程方式注册soap扩展,就像它描述here一样,但我对这个特定方法有问题:
[System.Type]::GetType("System.Configuration.ConfigurationElementCollection, System.Configuration", $true)
Exception calling "GetType" with "2" argument(s): "Could not load file or assembly 'System.Configuration' or one of its dependencies. The system cannot find the file specified."
直接在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 Log Viewer的输出:
*** 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行中使用程序集全名,则会出现同样的问题。
答案 0 :(得分:2)
除非类型在当前程序集或mscorlib.dll中,否则您需要指定程序集限定的类型名称。这应该有效:
[System.Type]::GetType("System.Configuration.ConfigurationElementCollection, System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", $true)