C
C#•2w ago
RdZoid

Console.Writeline throwing error CS0234 in one class but the program.cs in the same project doesn't.

Hello, I have a console app project where there is the default program.cs class where console.writeline works, but then I have a separate class within that same project where it doesn't work. It says WriteLine doesn't exist in the namespace.. are you missing a reference? Idk if I've ever had this happen especially when it works in another class within that project! Adding in "using system;" just has it greyed out as if it's already using it.
28 Replies
333fred
333fred•2w ago
Show your code
RdZoid
RdZoidOP•2w ago
using Microsoft.AspNetCore.SignalR.Client;

namespace AJS.DVDCentral.UI.Console
{
public class SignalRConnection
{
private string hubAddress;
HubConnection _connection;

public string User { get; set; }
public string Message { get; set; }
string owner;

public SignalRConnection(string hubAddress)
{
this.hubAddress = hubAddress;
}
public SignalRConnection(string hubAddress, string owner)
{
this.hubAddress = hubAddress;
this.owner = owner;
}

public HubConnection HubConnection
{
get { return _connection; }
}

public void Start()
{
_connection = new HubConnectionBuilder()
.WithUrl(hubAddress)
.Build();

_connection.On<string, string>("ReceiveMessage", (s1, s2) => OnSend(s1, s2));


_connection.StartAsync();
}

private void OnSend(string user, string message)
{
Console.WriteLine($"{user}: {message}");
User = user;
Message = message;
}

public void Stop()
{

_connection.StopAsync();
}

public void ConnectToChannel(string user)
{
Start();
string message = user + " connected...";

try
{
_connection.InvokeAsync("SendMessage", "System", message);

}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}

public void SendMessageToChannel(string user, string message)
{
try
{
//Start();
//Console.WriteLine($"{user} {message}");
_connection.InvokeAsync("SendMessage", user, message);
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}

}

}
}
using Microsoft.AspNetCore.SignalR.Client;

namespace AJS.DVDCentral.UI.Console
{
public class SignalRConnection
{
private string hubAddress;
HubConnection _connection;

public string User { get; set; }
public string Message { get; set; }
string owner;

public SignalRConnection(string hubAddress)
{
this.hubAddress = hubAddress;
}
public SignalRConnection(string hubAddress, string owner)
{
this.hubAddress = hubAddress;
this.owner = owner;
}

public HubConnection HubConnection
{
get { return _connection; }
}

public void Start()
{
_connection = new HubConnectionBuilder()
.WithUrl(hubAddress)
.Build();

_connection.On<string, string>("ReceiveMessage", (s1, s2) => OnSend(s1, s2));


_connection.StartAsync();
}

private void OnSend(string user, string message)
{
Console.WriteLine($"{user}: {message}");
User = user;
Message = message;
}

public void Stop()
{

_connection.StopAsync();
}

public void ConnectToChannel(string user)
{
Start();
string message = user + " connected...";

try
{
_connection.InvokeAsync("SendMessage", "System", message);

}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}

public void SendMessageToChannel(string user, string message)
{
try
{
//Start();
//Console.WriteLine($"{user} {message}");
_connection.InvokeAsync("SendMessage", user, message);
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}

}

}
}
333fred
333fred•2w ago
And where is the error?
RdZoid
RdZoidOP•2w ago
On every Console.WriteLine
RdZoid
RdZoidOP•2w ago
No description
333fred
333fred•2w ago
What happens if you fully qualify the call Ie, System.Console.WriteLine
ARDA64
ARDA64•2w ago
using system;
RdZoid
RdZoidOP•2w ago
well that works... if I do that it's just greyed out and doesn't fix it
333fred
333fred•2w ago
Reread the op where that was already tried 🙂
RdZoid
RdZoidOP•2w ago
but why would it even need that? lol doens't make sense
333fred
333fred•2w ago
Oh, I'm an idiot, look at your namespace
RdZoid
RdZoidOP•2w ago
does the .Console break it?
333fred
333fred•2w ago
Yep
RdZoid
RdZoidOP•2w ago
ok I thought that could've been it, my instructor said dot console when creating it though so probably just a flub, thanks though!
333fred
333fred•2w ago
No problem. Make sure to mark it as $closed if that's all $close
MODiX
MODiX•2w ago
If you have no further questions, please use /close to mark the forum thread as answered
RdZoid
RdZoidOP•2w ago
$close
MODiX
MODiX•2w ago
If you have no further questions, please use /close to mark the forum thread as answered
333fred
333fred•2w ago
$ is just a tag, / invokes commands
RdZoid
RdZoidOP•2w ago
$close
MODiX
MODiX•2w ago
If you have no further questions, please use /close to mark the forum thread as answered
333fred
333fred•2w ago
Use the command, not the tag
RdZoid
RdZoidOP•2w ago
I tried it says the application did not respond or the other says I dont have permission
333fred
333fred•2w ago
Well, that's annoying I'd ping @Patrick, but I feel like he might be unable to kick accord right now Oh, oops, silly me, I pinged @Patrick anyways
Patrick
Patrick•2w ago
Hello
RdZoid
RdZoidOP•2w ago
I cant close this
Patrick
Patrick•2w ago
Ok just ignore it
RdZoid
RdZoidOP•2w ago
ok

Did you find this page helpful?