【发布时间】:2017-11-18 06:20:35
【问题描述】:
我正在尝试使用 powershell 脚本连接到 SignalR 集线器。我对powershell很陌生,所以请原谅任何菜鸟的错误。
我已经设置了一个最小的 not 我在这里尝试过的工作示例: Gist
相关代码:
加载 dll
$dllFolder = -join((Get-Item -Path ".\" -Verbose).FullName, "\bin\Debug\")
[string[]] $dllPathsToLoad = @("\Newtonsoft.Json.dll", "\Microsoft.AspNet.SignalR.Client.dll")
$token = "insertyourtokenhere"
function LoadDllPaths($dlls)
{
foreach ($dll in $dlls)
{
$dllpath = $dllFolder + $dll
[System.Reflection.Assembly]::LoadFrom($dllpath)
}
}
[...]
LoadDllPaths($dllPathsToLoad)
创建 HubConnection:
$server = "https://localhost/rest/"
[...]
$hub = New-Object Microsoft.AspNet.SignalR.Client.HubConnection($server)
步骤:
- 创建一个新的 Visual Studio 项目
- 添加 Newtonsoft.Json v10.0.2 Nuget 包(最新)
- 添加 Microsoft.AspNet.SignalR.Client v2.2.2 Nuget 包(最新)
- 将 powershell 脚本添加到项目的根目录
- 使用 powershell(以管理员身份运行),键入
.\HubConnectionTestsScript.ps1
结果:
Error : System.Management.Automation.MethodInvocationException: Exception calling ".ctor" with "1" argument(s): "Could not load file or assembly 'Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The system cannot find the file specified." ---> System.IO.FileNotFoundException: Could not load file or assembly 'Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The system cannot find the file specified.
at Microsoft.AspNet.SignalR.Client.Connection..ctor(String url, String queryString)
at Microsoft.AspNet.SignalR.Client.HubConnection..ctor(String url, Boolean useDefaultUrl)
--- End of inner exception stack trace ---
at System.Management.Automation.DotNetAdapter.AuxiliaryConstructorInvoke(MethodInformation methodInformation, Object[] arguments, Object[] originalArguments)
at System.Management.Automation.DotNetAdapter.ConstructorInvokeDotNet(Type type, ConstructorInfo[] constructors, Object[] arguments)
at Microsoft.PowerShell.Commands.NewObjectCommand.CallConstructor(Type type, ConstructorInfo[] constructors, Object[] args)
This signalR source code object 似乎是问题所在,我只是看不出它的哪一部分会引发此错误。
问题:
当signalR dependencies 说>=6.0.4,而我有10.0.2 时,为什么错误会提到Newtonsoft.Json v6.0.0?
我是否在我的 Powershell 脚本中做错了可能导致此问题的任何事情?
非常感谢!任何帮助在这一点上表示赞赏
【问题讨论】:
标签: c# asp.net powershell nuget signalr