我正在使用Visual Studio 2015专业版的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)
也尝试过:
signalr.exe ghp /assembly:"D:\WORKS\VISUALSTUDIO\ASPWEBSITE\ServerSignalR_ChatHub\ServerSignalR_ChatHub\bin\ServerSignalR_ChatHub.dll"
它生成空的server.js文件
我做错了什么或错过了什么?
答案 0 :(得分:1)
哦,伙计......经过大量的研究和尝试,我终于找到了答案。 在错误中:
它说,无法加载程序集Newtonsoft.Json,Version = 6.0.0.0 。但我有版本= 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 !!
答案 1 :(得分:0)
我想我将在Visual Studio中的项目属性“ Build Events”下添加使用“ pre-build event命令行”的解决方案。 我没有使用程序的已安装软件包(否则可以正常运行),而是将旧的NewtonSoft文件的副本放在“解决方案文件夹”级别的“ OldNewton”目录中。我注意到SignalR.Utils可执行文件的安装目录。然后,我编写了一些命令脚本,以切换到bin文件夹,复制到旧的NewtonSoft文件和Utils文件中,执行signalR ghp命令创建中心脚本,然后将文件复制到我想要的位置。我还添加了一些清理命令和一些命令来备份/还原任何现有的NewtonSoft文件。您可能需要将SignalR.Utils文件复制到OldNewton文件旁边的其自己的目录中,以防软件包被更新。我认为它看起来要复杂得多。您可以删除echo命令,甚至可能删除backup和cleanup命令以使其更短。有几种方法可以完成此操作,但这是我选择执行此操作的方式。
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