signalr 在创建 server.js 文件时生成错误
signalr generating error while creating server.js file
我在 Visual Studio 2015 Pro 下使用 Xamarin 创建 Android 的聊天应用程序。
我想为 SignalR 生成的代理创建一个物理文件,在此处描述:SignalR Hubs API Guide
因此,如前所述,我安装了 Microsoft.AspNet.SignalR.Utils NuGet 包。
我试过了:
signalr.exe ghp /path:"D:\WORKS\VISUALSTUDIO\ASPWEBSITE\ServerSignalR_ChatHub\ServerSignalR_ChatHub\bin"
但它总是给出以下错误:
SignalR Utility Version: 2.2.1.0
Creating temp directory C:\Users\vivek\AppData\Local\Temp\aeb9348c-3f99-4537-bed7-7313b3c4bcbe
Warning: Could not load file or assembly 'Microsoft.DiaSymReader.Native.amd64.dll' or one of its dependencies. The module was expected to contain an assembly manifest.
Warning: Could not load file or assembly 'Microsoft.DiaSymReader.Native.x86.dll' or one of its dependencies. The module was expected to contain an assembly manifest.
Warning: Could not load file or assembly 'Microsoft.DiaSymReader.Native.amd64.dll' or one of its dependencies. The module was expected to contain an assembly manifest.
Warning: Could not load file or assembly 'Microsoft.DiaSymReader.Native.x86.dll' or one of its dependencies. The module was expected to contain an assembly manifest.
Error: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.IO.FileLoadException: Could not load file or assembly 'Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
at Microsoft.AspNet.SignalR.DefaultDependencyResolver.RegisterDefaultServices()
at Microsoft.AspNet.SignalR.DefaultDependencyResolver..ctor()
--- End of inner exception stack trace ---
Server stack trace:
at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
at System.Activator.CreateInstance(Type type, Boolean nonPublic)
at System.Activator.CreateInstance(Type type)
at Microsoft.AspNet.SignalR.Utils.GenerateHubProxyCommand.JavaScriptGenerator.GenerateProxy(String path, String url, Action`1 warning)
at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Object[]& outArgs)
at System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage msg)
Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at Microsoft.AspNet.SignalR.Utils.GenerateHubProxyCommand.JavaScriptGenerator.GenerateProxy(String path, String url, Action`1 warning)
at Microsoft.AspNet.SignalR.Utils.GenerateHubProxyCommand.OutputHubs(String path, String url, String outputPath)
at Microsoft.AspNet.SignalR.Utils.GenerateHubProxyCommand.Execute(String[] args)
at Microsoft.AspNet.SignalR.Utils.Program.Main(String[] args)
Also tried:
signalr.exe ghp /assembly:"D:\WORKS\VISUALSTUDIO\ASPWEBSITE\ServerSignalR_ChatHub\ServerSignalR_ChatHub\bin\ServerSignalR_ChatHub.dll"
It generate empty server.js file
我做错了什么或遗漏了什么?
哦,伙计....经过大量研究和尝试,我终于找到了答案。
在错误中:
它说,无法加载程序集Newtonsoft.Json,版本=6.0.0.0。但是我有 Version=9.0.0.0
所以我只是强制卸载它并使用最小依赖版本安装它=6.0.0.0(在我的例子中它依赖于SignalR.Core.dll(v2.2.1))。
uninstall-package newtonsoft.json -force
install-package newtonsoft.json -version "6.0.4"
然后 运行:
signalr.exe ghp /path:"D:\WORKS\<path>\ServerSignalR_ChatHub\bin"
并成功生成server.js!!
我想我会在 Visual Studio 的项目属性“构建事件”下添加使用“预构建事件命令行”的解决方案。
我没有使用我的程序的已安装包(否则效果很好),而是将旧 NewtonSoft 文件的副本放在解决方案文件夹级别的“OldNewton”目录中。我记下了 SignalR.Utils 可执行文件的安装目录。然后我编写了一些命令来更改到 bin 文件夹,复制旧的 NewtonSoft 文件和 Utils 文件,执行 signalR ghp 命令来创建集线器脚本,然后将文件复制到我想要的位置。我还向 backup/restore 任何现有的 NewtonSoft 文件添加了一些清理命令和一些命令。您可能希望将 SignalR.Utils 文件复制到 OldNewton 文件旁边的它们自己的目录中,以防包更新。我认为它看起来比实际要复杂得多。您可以删除 echo 命令,甚至可能删除备份和清理命令以使其更短。有几种方法可以做到这一点,但这是我选择的方法。
cd $(TargetDir)
@echo Creating backup
if not exist backup\nul mkdir backup
if exist backup del backup\*.* /q /f
if exist Newton*.* move Newton*.* backup\*.* /q /f
@Echo Copying in the Signal R files
copy "$(SolutionDir)packages\Microsoft.AspNet.SignalR.Utils.2.4.1\tools\net40" .
@Echo Copying in the old NewtonSoft files
copy $(SolutionDir)OldNewton\*.* .
@Echo Creating the hub script: signalr ghp /path:$(TargetDir)
signalr ghp /path:$(TargetDir)
@Echo moving hub file to where I want it: move /Y server.js "$(ProjectDir)scripts\app\srFreedomHub.js"
move /Y server.js "$(ProjectDir)scripts\app\srFreedomHub.js"
@echo remove the signalR util files and old Newton Files
del signalr.* /q /f
del Newton*.* /q /f
@echo Restore the backup folder files
if exist backup\Newton*.* move backup\*.* .
@echo Remove the backup folder
if exist backup\nul rmdir backup /S /Q
我在 Visual Studio 2015 Pro 下使用 Xamarin 创建 Android 的聊天应用程序。 我想为 SignalR 生成的代理创建一个物理文件,在此处描述:SignalR Hubs API Guide 因此,如前所述,我安装了 Microsoft.AspNet.SignalR.Utils NuGet 包。 我试过了:
signalr.exe ghp /path:"D:\WORKS\VISUALSTUDIO\ASPWEBSITE\ServerSignalR_ChatHub\ServerSignalR_ChatHub\bin"
但它总是给出以下错误:
SignalR Utility Version: 2.2.1.0
Creating temp directory C:\Users\vivek\AppData\Local\Temp\aeb9348c-3f99-4537-bed7-7313b3c4bcbe
Warning: Could not load file or assembly 'Microsoft.DiaSymReader.Native.amd64.dll' or one of its dependencies. The module was expected to contain an assembly manifest.
Warning: Could not load file or assembly 'Microsoft.DiaSymReader.Native.x86.dll' or one of its dependencies. The module was expected to contain an assembly manifest.
Warning: Could not load file or assembly 'Microsoft.DiaSymReader.Native.amd64.dll' or one of its dependencies. The module was expected to contain an assembly manifest.
Warning: Could not load file or assembly 'Microsoft.DiaSymReader.Native.x86.dll' or one of its dependencies. The module was expected to contain an assembly manifest.
Error: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.IO.FileLoadException: Could not load file or assembly 'Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
at Microsoft.AspNet.SignalR.DefaultDependencyResolver.RegisterDefaultServices()
at Microsoft.AspNet.SignalR.DefaultDependencyResolver..ctor()
--- End of inner exception stack trace ---
Server stack trace:
at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
at System.Activator.CreateInstance(Type type, Boolean nonPublic)
at System.Activator.CreateInstance(Type type)
at Microsoft.AspNet.SignalR.Utils.GenerateHubProxyCommand.JavaScriptGenerator.GenerateProxy(String path, String url, Action`1 warning)
at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Object[]& outArgs)
at System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage msg)
Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at Microsoft.AspNet.SignalR.Utils.GenerateHubProxyCommand.JavaScriptGenerator.GenerateProxy(String path, String url, Action`1 warning)
at Microsoft.AspNet.SignalR.Utils.GenerateHubProxyCommand.OutputHubs(String path, String url, String outputPath)
at Microsoft.AspNet.SignalR.Utils.GenerateHubProxyCommand.Execute(String[] args)
at Microsoft.AspNet.SignalR.Utils.Program.Main(String[] args)
Also tried:
signalr.exe ghp /assembly:"D:\WORKS\VISUALSTUDIO\ASPWEBSITE\ServerSignalR_ChatHub\ServerSignalR_ChatHub\bin\ServerSignalR_ChatHub.dll"
It generate empty server.js file
我做错了什么或遗漏了什么?
哦,伙计....经过大量研究和尝试,我终于找到了答案。 在错误中:
它说,无法加载程序集Newtonsoft.Json,版本=6.0.0.0。但是我有 Version=9.0.0.0 所以我只是强制卸载它并使用最小依赖版本安装它=6.0.0.0(在我的例子中它依赖于SignalR.Core.dll(v2.2.1))。
uninstall-package newtonsoft.json -force
install-package newtonsoft.json -version "6.0.4"
然后 运行:
signalr.exe ghp /path:"D:\WORKS\<path>\ServerSignalR_ChatHub\bin"
并成功生成server.js!!
我想我会在 Visual Studio 的项目属性“构建事件”下添加使用“预构建事件命令行”的解决方案。 我没有使用我的程序的已安装包(否则效果很好),而是将旧 NewtonSoft 文件的副本放在解决方案文件夹级别的“OldNewton”目录中。我记下了 SignalR.Utils 可执行文件的安装目录。然后我编写了一些命令来更改到 bin 文件夹,复制旧的 NewtonSoft 文件和 Utils 文件,执行 signalR ghp 命令来创建集线器脚本,然后将文件复制到我想要的位置。我还向 backup/restore 任何现有的 NewtonSoft 文件添加了一些清理命令和一些命令。您可能希望将 SignalR.Utils 文件复制到 OldNewton 文件旁边的它们自己的目录中,以防包更新。我认为它看起来比实际要复杂得多。您可以删除 echo 命令,甚至可能删除备份和清理命令以使其更短。有几种方法可以做到这一点,但这是我选择的方法。
cd $(TargetDir)
@echo Creating backup
if not exist backup\nul mkdir backup
if exist backup del backup\*.* /q /f
if exist Newton*.* move Newton*.* backup\*.* /q /f
@Echo Copying in the Signal R files
copy "$(SolutionDir)packages\Microsoft.AspNet.SignalR.Utils.2.4.1\tools\net40" .
@Echo Copying in the old NewtonSoft files
copy $(SolutionDir)OldNewton\*.* .
@Echo Creating the hub script: signalr ghp /path:$(TargetDir)
signalr ghp /path:$(TargetDir)
@Echo moving hub file to where I want it: move /Y server.js "$(ProjectDir)scripts\app\srFreedomHub.js"
move /Y server.js "$(ProjectDir)scripts\app\srFreedomHub.js"
@echo remove the signalR util files and old Newton Files
del signalr.* /q /f
del Newton*.* /q /f
@echo Restore the backup folder files
if exist backup\Newton*.* move backup\*.* .
@echo Remove the backup folder
if exist backup\nul rmdir backup /S /Q