Я следую вместе с учебником построить чат-клиент и сервер, прямо сейчас я получаю следующее сообщение об ошибке:C# ConcurrentDictionary использование несовместимой доступности?
Inconsistent accessibility: field type 'System.Collections.Concurrent.ConcurrentDictionary<string,ChattingServer.ConnectedClient>' is less accessible than field 'ChattingServer.ChattingService._connectedClients' c:\Users\KOEMXE\Documents\Visual Studio 2012\Projects\ChatApplication\ChattingServer\ChattingService.cs 17 62 ChattingServer
Вот файл класс, где соответствующий вопрос лежит (ChattingService.cs):
using ChattingInterfaces;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
namespace ChattingServer
{
[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple, InstanceContextMode = InstanceContextMode.Single)]
public class ChattingService : IChattingService
{
//private ConnectedClient _connectedClients;
public ConcurrentDictionary<string, ConnectedClient> _connectedClients = new ConcurrentDictionary<string, ConnectedClient>();
public int Login(string userName)
{
//is anyone else logged in with my name?
foreach (var client in _connectedClients)
{
if(client.Key.ToLower() == userName.ToLower())
{
//if yes
return 1;
}
}
var establishedUserConnection = OperationContext.Current.GetCallbackChannel<IClient>();
ConnectedClient newClient = new ConnectedClient();
newClient.connection = establishedUserConnection;
newClient.UserName = userName;
_connectedClients.TryAdd(userName, newClient);
return 0;
}
public void SendMessageToALL(string message, string userName)
{
foreach (var client in _connectedClients)
{
if (client.Key.ToLower() != userName.ToLower())
{
client.Value.connection.GetMessage(message, userName);
}
}
}
}
}
Нужно ли объявлять тип в объекте ConcurrentDictionary в другом месте? В чем проблема? Благодаря!
Я бы предположил, что ChattingServer.ConnectedClient не является общедоступным. – DaveShaw