2010-11-30 4 views
1

PowerShell v2로이 간단한 .NET 4 함수를 호출하려고합니다. 정의는 다음과 같습니다.PowerShell은 ASP.NET DLL에서 간단한 함수를 호출하지 못합니다.

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

해당 기능을 포함하는 DLL 파일에 경로를 추가합시다. 웹 응용 프로그램 DLL 파일 ASP.NET MVC입니다.

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

의 그것을 시도하자 (FAIL를!) :

PS >
[NM4.SiteAdmin.Logic.Subscription]

IsPublic IsSerial Name
BaseType

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

이의이

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

왜 PowerShell을

에서 기능을 관찰하자

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을에서 클래스를 관찰하자 왜 오? 그것은 나에게 의사처럼 보인다.

답변

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 파일은 일반적으로 일반적인 웹 컨텍스트가 아닙니다. . 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 | 형식 목록 - 강제 – Malartre

관련 문제