简体   繁体   English

检查SignalR组件是否存在

[英]Check if SignalR assembly exists or not

How can I check if SignalR assembly exists or not to avoid this error: 我如何检查SignalR程序集是否存在以避免此错误:

Could not load file or assembly 'Microsoft.AspNet.SignalR.Core, Version=2.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' 无法加载文件或程序集'Microsoft.AspNet.SignalR.Core,Version = 2.2.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35'

I want to run a method when SignalR dll exists. 我想在SignalR dll存在时运行一种方法。 I have this code but it's always false . 我有此代码,但始终为false

var exists = AppDomain.CurrentDomain.GetAssemblies().Any(item => item.FullName.Contains("Microsoft.AspNet.SignalR.Core"));
if (exists)
    AddRowSignalR(faraLog);

what is the best solution? 最好的解决方案是什么?

GetAssemblies for the current domain will only list assemblies that are already loaded in that domain. 当前域的GetAssemblies将仅列出该域中已加载的程序集。 See the documentation: 请参阅文档:

https://msdn.microsoft.com/en-us/library/system.appdomain.getassemblies%28v=vs.110%29.aspx https://msdn.microsoft.com/en-us/library/system.appdomain.getassemblies%28v=vs.110%29.aspx

The assembly won't be auto-loaded until a type from that assembly is referenced in executed code. 除非在执行的代码中引用了该程序集的类型,否则该程序集将不会自动加载。 If you want to load an assembly without (first) referencing any types from that assembly in code directly, you need to use the Assembly.Load method. 如果要加载程序集而不(首先)直接在代码中引用该程序集的任何类型,则需要使用Assembly.Load方法。 See the documentation, especially the example at the bottom: 请参阅文档,尤其是底部的示例:

https://msdn.microsoft.com/en-us/library/25y1ya39%28v=vs.110%29.aspx https://msdn.microsoft.com/en-us/library/25y1ya39%28v=vs.110%29.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM