2010-11-30 16 views
1

私はPowerShell v2でこの単純な.NET 4関数を呼び出しようとしています。その定義は次のようになります:PowerShellはASP.NET DLLから単純な関数を呼び出すことができません

Public Shared Function currentSchoolYear() As String Member of NM4.SiteAdmin.Logic.Subscription

その関数を含むDLLファイルにパスを追加しましょう。それはASP.NET MVCウェブアプリケーションのDLLファイルです。

PS > Add-Type -Path C:\xxx\bin\xxxWebApp.dll

のは、(FAIL!)それを試してみましょう:

PS >
[NM4.SiteAdmin.Logic.Subscription]::currentSchoolYear()
Exception calling "currentSchoolYear"
with "0" argument(s): "The type
initializer for
'NM4.SiteAdmin.Logic.Subscription'
threw an exception." At line:1 char:54
+ [NM4.SiteAdmin.Logic.Subscription]::currentSchoolYear
<<<<()
+ CategoryInfo : NotSpecified: (:) [],
MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException

のは、PowerShellのからクラスを観察してみましょう:

PS >
[NM4.SiteAdmin.Logic.Subscription]

IsPublic IsSerial Name
BaseType

-------- -------- ---- -------- True False Subscription
System.Object

のは、PowerShellの

PS >
[NM4.SiteAdmin.Logic.Subscription]::currentSchoolYear


MemberType : Method
OverloadDefinitions : {static string
currentSchoolYear()} TypeNameOfValue
:
System.Management.Automation.PSMethod
Value : static string
currentSchoolYear() Name
: currentSchoolYear IsInstance
: True

なぜから機能を観察してみましょうなぜああ?それは私にとっては医者のようだ。

答えて

2

私は、エラーの詳細を取得するには、このコマンドを使用:

System.NullReferenceException: Object
reference not set to an instance of an
object.
at
NM4.SiteAdmin.GlobalFunctions.EstMachineProduction()
in
C:\xxx\Old_App_Code\DataModel\GlobalFunctions.vb:line
17

そして、私はそれがweb.configファイルへの呼び出しがわかりました。その後、このより正確な例をthrowed

$error | Format-List -force

失敗しました:

Return
ConfigurationManager.ConnectionStrings.Item("test_DBNM4").ConnectionString

PowerShellで読み込まれたDLLファイルは、通常、通常のWebコンテキストにありません。私はそれをテストするためにConnectionStringをハードコードしました(一時的で、良いセキュリティの習慣ではありません)。

0

静的コンストラクタまたはの例外のようですが、NM4.SiteAdmin.Logic.Subscriptionが依存する型をロードできませんでした。私は "C:\ xxx \ bin \ xxxWebApp.dll"と仮定していて、友人はGACにいないので、 "C:\ xxx \ bin \"から実行していないので、powershellは依存関係を解決できません。これを "C:\ xxx \ bin \"から実行してみてください。

+0

私はcd C:\ xxx \ bin \を試しましたが、同じエラーで失敗します。 – Malartre

+0

powershellでエラーの詳細を確認できますか? – Malartre

+0

OKこれでさらに詳しい情報が得られました: $ error |フォーマットリスト-force – Malartre

関連する問題