【发布时间】:2014-05-10 22:21:47
【问题描述】:
我正在尝试为我的基于 EF6 的网站创建 powershell 管理脚本,但我正在努力创建一个 DbContext 来访问我的实体。
在PowerShell App.Config 之后,我正在执行以下操作来加载我的 dll,为当前应用程序域设置配置文件并实例化我的 DbContext。
Add-Type -AssemblyName System.Configuration
[appdomain]::CurrentDomain.SetData("APP_CONFIG_FILE", "path.to.web.config")
[Reflection.Assembly]::LoadFrom("MyProject.Dll")
$ctx = New-Object MyProject.MyDbContext
$ctx
我能够加载 dll,并且可以检查它是否找到了 MyProject.MyDbContext 类,并且它似乎也能够创建对象,但是在执行最后一条语句时,我得到了 TargetInvocationException
format-default : Exception has been thrown by the target of an invocation.
+ CategoryInfo : NotSpecified: (:) [format-default], TargetInvocationException
+ FullyQualifiedErrorId : System.Reflection.TargetInvocationException,Microsoft.PowerShell.Commands.FormatDefaultCommand
我尝试捕获 TargetInvocationException,但它似乎以某种方式逃脱了我的 try-catch。
有什么想法吗?
【问题讨论】:
标签: entity-framework powershell