我的目標是從PowerShell調用Google Admin SDK Directory更新。我從一個可用的.NET應用程序開始,並將其轉換爲一個類庫(我測試過 - 它可以工作)。我加載的模塊清單與'DotNetOpenAuth.Logger'的類型初始值設定項引發異常
RequiredAssemblies = @('My.GoogleAdminSDK.Directory.dll')
我GET-GoogleSDKUser功能的新對象我的類和調用的getUser。而我得到:
Exception calling "GetUser" with "1" argument(s): "The type initializer for
'DotNetOpenAuth.Logger' threw an exception."
At C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules\My.googleadminsdkdirectory.admin\My.GoogleA
dminSDKDirectory.Admin.psm1:56 char:9
+ $service.GetUser($googleUserName)
+ ~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : TypeInitializationException
我已經嘗試添加已產生的空日誌文件,但沒有幫助log4net的配置文件。
注意:爲了遠得到這個,我不得不添加
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Net.Http.Primitives" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="log4net" publicKeyToken="669e0ddf0bb1aa2a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.2.12.0" newVersion="1.2.12.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
到powershell_ise.exe.config防止錯誤:
"Could not load file or assembly 'System.Net.Http.Primitives, Version=1.5.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified."
這是很不理想。
編輯
爲PowerShell的呼喚 - 我的DLL版本的InnerException是:
Could not load file or assembly 'log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=1b44e1d426115821' or one of its dependencies. The system cannot find the file specified.
花了挖掘,找到的InnerException的位。我周圍有一些雪貂,並且找到了使用Fuslogvw的建議,所以我試了一下。我關閉並重新打開了PowerShell,啓動了Fusion Log Viewer(這是我第一次使用它),並找到了三個log4net條目。的描述是:
- log4net的
- log4net的,版本= 1.2.12.0文化=中性公鑰= 669e0ddf0bb1aa2a
- log4net的,版本= 1.2.10.0文化=中性公鑰= 1b44e1d426115821
當我打開它們時,前兩個'手術成功'。作爲第二行文字。第三個是'操作失敗。綁定結果:hr = 0x80070002。該系統找不到指定的文件。'
當我深入到該日誌,我發現:
LOG: Assembly download was successful. Attempting setup of file: C:\windows\system32\windowspowershell\v1.0\Modules\JLP.GoogleAdminSDKDirectory.Admin\log4net.dll
LOG: Entering run-from-source setup phase.
LOG: Assembly Name is: log4net, Version=1.2.12.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a
WRN: Comparing the assembly name resulted in the mismatch: Build Number
ERR: The assembly reference did not match the assembly definition found.
我試圖從Visual Studio運行一遍。 fuslogvw中還有三個條目,第三個條目有相同的錯誤。但是VS輸出中沒有任何內容表示問題。
您應該能夠看到導致類型初始值設定項異常的內部異常。這將有更多關於哪裏出錯的信息。 –
謝謝。 innerException顯示它無法加載文件,因爲版本不同,並且配置文件中的程序集重定向用於不同的PublicKeyToken。每個版本都改變它是否正常?有沒有辦法繞過它? – user2871239
我不是這方面的專家,但我認爲*這聽起來像作者已經改變了他們用來簽署它的密鑰。我建議你看看你能否得到正確的原始版本。 –