Skip to main content
 首页 » 编程设计

c#之.Net 完整配置文件配置的 Microsoft.ServiceBus.dll 问题

2024年02月05日9JustinYoung

我最近在我的整个 Visual Studio 2015 解决方案上运行了 nuget auto package restore。当然,这是一个非常糟糕的主意,我花了几天时间修复丢失的 dll 并手动解决解决方案中我的 7 个项目的包问题。

然而,我仍然面临这些问题:

The type or namespace name 'Notifications' does not exist in the namespace 'Microsoft.ServiceBus' (are you missing an assembly reference?)

和

The name 'NotificationHubClient' does not exist in the current context

出现在这段代码中:

using System; 
using System.Collections.Generic; 
using System.Configuration; 
using Microsoft.ServiceBus.Notifications; 
 
namespace B8AK.Service 
{ 
    /// <summary> 
    /// Summary description for PushNotification 
    /// </summary> 
    public class PushNotification 
    { 
        /// <summary> 
        /// Send push notification 
        /// </summary> 
        /// <param name="msg">Message</param> 
        /// <param name="key">SPID or Customer mobile</param> 
        /// <returns></returns> 
        public static bool Send(string msg, string key) 
        { 
            try 
            { 
                var notificationHubClint = NotificationHubClient.CreateClientFromConnectionString(ConfigurationManager.AppSettings["ServiceBusPushNotificationConnectionString"], ConfigurationManager.AppSettings["ServiceBusPushNotificationName"]); 
                Dictionary<string, string> param = new Dictionary<string, string>(); 
                param.Add("message", msg); 
                param.Add("alert", msg); 
                var template = new TemplateNotification(param); 
                List<string> tagList = new List<string>(); 
                tagList.Add(key); 
                notificationHubClint.SendNotificationAsync(template, tagList); 
                return true; 
            } 
            catch (Exception exception) 
            { 
                Console.WriteLine(exception.Message); 
                return false; 
            } 
        } 
    } 
} 

尽管在我的项目中引用了“Microsoft.ServiceBus.dll”。

在 Stackoverflowing 这个问题之后,我遇到了一个 solution建议将目标框架从 .Net 客户端配置文件更改为项目属性中的完整配置文件,但就我而言,我已经在运行完整的 .net 配置文件。

请您参考如下方法:

已修复!

安装这个 nuget 包解决了我的问题:

=> Microsoft.Azure.NotificationHubs