Ares
Ares
CC#
Created by Ares on 6/11/2024 in #help
[Reading files from sftp server] is what i am trying to do possible?
hello, in the following code:
public async Task GetInformation(string url)
{
//Start Connections
SshClient cSSH = new SshClient(sftpConfig.Host, sftpConfig.Port, sftpConfig.UserName, sftpConfig.Password);
SftpClient client = new SftpClient(sftpConfig.Host, sftpConfig.Port, sftpConfig.UserName, sftpConfig.Password);

...stuff

//Roslyn analysis
MSBuildLocator.RegisterDefaults();

var workspace = MSBuildWorkspace.Create();

var solution = await workspace.OpenSolutionAsync("Remote_Directory?"); --OpenSolutionAsync is for local use only.

foreach (var project in solution.Projects)
{
Console.WriteLine(project.AssemblyName);
}

//Close connections
client.Disconnect();
cSSH.Disconnect();
}
public async Task GetInformation(string url)
{
//Start Connections
SshClient cSSH = new SshClient(sftpConfig.Host, sftpConfig.Port, sftpConfig.UserName, sftpConfig.Password);
SftpClient client = new SftpClient(sftpConfig.Host, sftpConfig.Port, sftpConfig.UserName, sftpConfig.Password);

...stuff

//Roslyn analysis
MSBuildLocator.RegisterDefaults();

var workspace = MSBuildWorkspace.Create();

var solution = await workspace.OpenSolutionAsync("Remote_Directory?"); --OpenSolutionAsync is for local use only.

foreach (var project in solution.Projects)
{
Console.WriteLine(project.AssemblyName);
}

//Close connections
client.Disconnect();
cSSH.Disconnect();
}
Basically, I clone the repo to my stfp server and thats all good so the next step is to analyze the solution. However, since all of the files are remote and not local, I cant use workspace.OpenSolutionAsync, because that method takes a local path. I don't have any way to say hey look at my remote server and then create a new workspace and solution there like how I am doing above. I was trying to see if there was a way I could run the code via ssh command, but i dont think thats possible. Also, there is no point in trying to download any files because, if I am going to do that I might as well as just cloned it locally from the start and not use sftp. But I cant do local cause its a web app. Any advice?
46 replies
CC#
Created by Ares on 6/9/2024 in #help
Cant navigate to different directories in sftp server using SSH.NET
I am trying to make code that will navigate throughout my sftp server using SSH.NET library, and I'm having trouble with the navigation. They have a built in way of changing the current working directory with client.ChangeDirectory, and you can access the directory with client.WorkingDirectory. However, this doesn't seem to do anything at all when I use it. Even though I change the workign directory, and I see the string change, when I do "pwd" in ssh to access the current directory, it is always the root no matter what. The second method to navigate would be to just use cd in ssh, using cSSH.RunCommand("cd ..."). However, this has the same issue where it doesn't seem to change the directory at all. Not sure why, but none of these methods work. I've been trying for a long time now but cant seem to figure out why. Thanks.
20 replies
CC#
Created by Ares on 6/3/2024 in #help
how difficult would this be to do?
so basically just for pratcice, I want to make an app that takes a github url and then goes throught he repo and determines all of the constructor DI being used in the app and which controllers are using them. and then i can display the info with interactive ui. i will have to find some way to read the github repo, and then i will need Roslyn (which i dont know anything about) to analyze the code. but am i missing something majorly important that i didnt mention or advice?
14 replies
CC#
Created by Ares on 5/24/2024 in #help
✅ Dependency Injection Error?
I am injecting it in Program.cs:
builder.Services.AddIdentityCore<IdentityUser>()
.AddRoles<IdentityRole>()
.AddTokenProvider<DataProtectorTokenProvider<IdentityUser>>("RealTimePolls")
.AddEntityFrameworkStores<RealTimePollsAuthDbContext>()
.AddDefaultTokenProviders();
}
builder.Services.AddIdentityCore<IdentityUser>()
.AddRoles<IdentityRole>()
.AddTokenProvider<DataProtectorTokenProvider<IdentityUser>>("RealTimePolls")
.AddEntityFrameworkStores<RealTimePollsAuthDbContext>()
.AddDefaultTokenProviders();
}
so I dont understand why when I inject it into my repository:
{
public class SQLAuthRepository : IAuthRepository
{
private readonly RealTimePollsDbContext dbContext;
private readonly UserManager<IdentityUser> userManager;

public SQLAuthRepository(RealTimePollsDbContext dbContext
, UserManager<IdentityUser> userManager
)
{
this.dbContext = dbContext;
this.userManager = userManager;
}
{
public class SQLAuthRepository : IAuthRepository
{
private readonly RealTimePollsDbContext dbContext;
private readonly UserManager<IdentityUser> userManager;

public SQLAuthRepository(RealTimePollsDbContext dbContext
, UserManager<IdentityUser> userManager
)
{
this.dbContext = dbContext;
this.userManager = userManager;
}
it is giving me the error:
[15:20:20 ERR] 0f01858e-8fd6-442c-a045-21bee09ade58 : Unable to resolve service for type 'Microsoft.AspNetCore.Identity.UserManager`1[Microsoft.AspNetCore.Identity.IdentityUser]' while attempting to activate 'RealTimePolls.Controllers.AuthController'.
System.InvalidOperationException: Unable to resolve service for type 'Microsoft.AspNetCore.Identity.UserManager`1[Microsoft.AspNetCore.Identity.IdentityUser]' while attempting to activate 'RealTimePolls.Controllers.AuthController'.
at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.ThrowHelperUnableToResolveService(Type type, Type requiredBy)
at lambda_method206(Closure, IServiceProvider, Object[])
at Microsoft.AspNetCore.Mvc.Controllers.ControllerFactoryProvider.<>c__DisplayClass6_0.<CreateControllerFactory>g__CreateController|0(ControllerContext controllerContext)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
[15:20:20 ERR] 0f01858e-8fd6-442c-a045-21bee09ade58 : Unable to resolve service for type 'Microsoft.AspNetCore.Identity.UserManager`1[Microsoft.AspNetCore.Identity.IdentityUser]' while attempting to activate 'RealTimePolls.Controllers.AuthController'.
System.InvalidOperationException: Unable to resolve service for type 'Microsoft.AspNetCore.Identity.UserManager`1[Microsoft.AspNetCore.Identity.IdentityUser]' while attempting to activate 'RealTimePolls.Controllers.AuthController'.
at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.ThrowHelperUnableToResolveService(Type type, Type requiredBy)
at lambda_method206(Closure, IServiceProvider, Object[])
at Microsoft.AspNetCore.Mvc.Controllers.ControllerFactoryProvider.<>c__DisplayClass6_0.<CreateControllerFactory>g__CreateController|0(ControllerContext controllerContext)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
3 replies
CC#
Created by Ares on 5/23/2024 in #help
Help adding authorization
No description
1 replies
CC#
Created by Ares on 5/21/2024 in #help
✅ Help with depedency injection?
So I made an ILoginRepository and then SQLLoginRepository for login/logout routes, I am using Google provider. however, it seems liek the Dependency injection is failing, and I'm not sure why. I've spend about an hour trying to fix it but no luck. Anyone kno why im getting this error:
An unhandled exception occurred while processing the request.
InvalidOperationException: Unable to resolve service for type 'RealTimePolls.Repositories.SQLLoginRepository' while attempting to activate 'RealTimePolls.Controllers.LoginController'.
Microsoft.Extensions.DependencyInjection.ActivatorUtilities.ThrowHelperUnableToResolveService(Type type, Type requiredBy)
An unhandled exception occurred while processing the request.
InvalidOperationException: Unable to resolve service for type 'RealTimePolls.Repositories.SQLLoginRepository' while attempting to activate 'RealTimePolls.Controllers.LoginController'.
Microsoft.Extensions.DependencyInjection.ActivatorUtilities.ThrowHelperUnableToResolveService(Type type, Type requiredBy)
7 replies
CC#
Created by Ares on 5/20/2024 in #help
How do i solve this type error?
//Create
[HttpPost]
public async Task<IActionResult> Create(AddPollRequest addPollRequest)
{
var result = await HttpContext.AuthenticateAsync(
CookieAuthenticationDefaults.AuthenticationScheme
);


addPollRequest.UserId = await UserInformation.GetGoogleId(result); <-- this line

var domainPoll = mapper.Map<Poll>(addPollRequest);
await pollRepository.CreatePollAsync(domainPoll);
return RedirectToAction("Index", "Home");

}
//Create
[HttpPost]
public async Task<IActionResult> Create(AddPollRequest addPollRequest)
{
var result = await HttpContext.AuthenticateAsync(
CookieAuthenticationDefaults.AuthenticationScheme
);


addPollRequest.UserId = await UserInformation.GetGoogleId(result); <-- this line

var domainPoll = mapper.Map<Poll>(addPollRequest);
await pollRepository.CreatePollAsync(domainPoll);
return RedirectToAction("Index", "Home");

}
why do i get, CS1503 Argument 1: cannot convert from 'Microsoft.AspNetCore.Authentication.AuthenticateResult' to 'Microsoft.Identity.Client.AuthenticationResult
18 replies
CC#
Created by Ares on 3/14/2024 in #help
how would you prepare for a C# interview (no dotnet) thats a live coding session (but not leetcode)
anyone have any experience with this?
9 replies
CC#
Created by Ares on 3/1/2024 in #help
dotnet user secrets not working
No description
11 replies
CC#
Created by Ares on 2/29/2024 in #help
✅ Unable to configure HTTPS endpoint.
The container builds successfully but then at the end it says:
at Microsoft.Extensions.Hosting.Internal.Host.ForeachService[T](IEnumerable`1 services, CancellationToken token, Boolean concurrent, Boolean abortOnFirstException, List`1 exceptions, Func`3 operation)
Unhandled exception. System.InvalidOperationException: **Unable to configure HTTPS endpoint. No server certificate was specified, and the default developer certificate could not be found or is out of date.
To generate a developer certificate run 'dotnet dev-certs https'. To trust the certificate (Windows and macOS only) run 'dotnet dev-certs https --trust'.
For more information on configuring HTTPS see https://go.microsoft.com/fwlink/?linkid=848054.**
at Microsoft.Extensions.Hosting.Internal.Host.ForeachService[T](IEnumerable`1 services, CancellationToken token, Boolean concurrent, Boolean abortOnFirstException, List`1 exceptions, Func`3 operation)
Unhandled exception. System.InvalidOperationException: **Unable to configure HTTPS endpoint. No server certificate was specified, and the default developer certificate could not be found or is out of date.
To generate a developer certificate run 'dotnet dev-certs https'. To trust the certificate (Windows and macOS only) run 'dotnet dev-certs https --trust'.
For more information on configuring HTTPS see https://go.microsoft.com/fwlink/?linkid=848054.**
I tried running
dotnet dev-certs https --clean
sudo dotnet dev-certs https --clean
dotnet dev-certs https
dotnet dev-certs https --trust
dotnet dev-certs https --check --trust
dotnet dev-certs https --clean
sudo dotnet dev-certs https --clean
dotnet dev-certs https
dotnet dev-certs https --trust
dotnet dev-certs https --check --trust
it says that my certificate is valid but it still keeps giving me Unable to configure HTTPS endpoint. I also tried completely removing docker and then adding it back. but that didn twork either. I tried removing app.UseHttpsRedirection(); from Program.cs too. nothing seems to work at all.
31 replies
CC#
Created by Ares on 2/28/2024 in #help
✅ [ASP.NET CORE] Error when trying to run docker image i pushed to dockerhub
so i built, tagged, then uploaded my asp.net project to docker hub, and then i downloaded the compose.yaml, Dockerfile, and .dockerignore, and .csproj from my repo: . so i have all those 4 files in a empty folder called Docker. And then I pull my image from docker hub and then i use docker compose up to run the image using the yaml file. It starts building but then stops suddenly, complaining about a Main class in program.cs (but Im not even writing a console app?)
135 replies
CC#
Created by Ares on 2/28/2024 in #help
[ASP.NET] Docker build not working properly.
so basically i made and pushed a docker image to the hub repositoory. And everytime i push to github, there is a github action that also updates the docker image and then on render.com is updated too. so my docker image works fine for deploying to a cloud provider. but the problem is that if i want other people to pull my docker image from online and run it locally, they are unable to do that. when i pull and then run docker compose up, I get the following error:
42 replies
CC#
Created by Ares on 2/26/2024 in #help
google authentication question
No description
26 replies
CC#
Created by Ares on 2/25/2024 in #help
help deploying asp.net app docker image to render.com
No description
15 replies
CC#
Created by Ares on 2/24/2024 in #help
[ASP.NET CORE MVC] help with docker
No description
4 replies
CC#
Created by Ares on 2/23/2024 in #help
trying to deploy my app with docker with my problems
So i have my container running, and when I go to localhost:8080 where the docker is running, it takes me to the error view with the message being:
Error.
An error occurred while processing your request.
Request ID: An exception has been raised that is likely due to a transient failure.

Development Mode
Swapping to Development environment will display more detailed information about the error that occurred.

The Development environment shouldn't be enabled for deployed applications. It can result in displaying sensitive information from exceptions to end users. For local debugging, enable the Development environment by setting the ASPNETCORE_ENVIRONMENT environment variable to Development and restarting the app.
Error.
An error occurred while processing your request.
Request ID: An exception has been raised that is likely due to a transient failure.

Development Mode
Swapping to Development environment will display more detailed information about the error that occurred.

The Development environment shouldn't be enabled for deployed applications. It can result in displaying sensitive information from exceptions to end users. For local debugging, enable the Development environment by setting the ASPNETCORE_ENVIRONMENT environment variable to Development and restarting the app.
9 replies
CC#
Created by Ares on 2/19/2024 in #help
[ASP.NET CORE MVC] trying to add js dependency to my project, but its not being recognized.
Im trying to add a pagination library to my app, but the script is not working when i add the script tag to my view and try to use it. I know that the src for my script tag is correct because when i use postman to get the file or visit it in the browser, i see all of the paginationjs code. I also know that Jquery is working because I can select elements and do stuff with it with jquery when i tested it. But for some reason when i try to call paginationjs pagination function, it says "?page=1:364 Uncaught (in promise) TypeError: $(...).pagination is not a function at populateGrid (?page=1:364:41)" This is also the function I am trying to run:
<script src="~/js/pagination.js"></script>

<script>
$(document).ready(function () {
const populateGrid = async () => {
const { polls, pollCount } = await getData()
$('#pagination-container2').pagination({
dataSource: polls,
callback: function (data, pagination) {
// template method of yourself
var html = template(data);
$('#data-container').html(html);
}
})


}
populateGrid();
});
</script>
<script src="~/js/pagination.js"></script>

<script>
$(document).ready(function () {
const populateGrid = async () => {
const { polls, pollCount } = await getData()
$('#pagination-container2').pagination({
dataSource: polls,
callback: function (data, pagination) {
// template method of yourself
var html = template(data);
$('#data-container').html(html);
}
})


}
populateGrid();
});
</script>
I also tried right clicking on lib > add > client side library and installing paginationjs that way, and i saw it in my libman.json. I then added the script tag for that directory but i still had the same problem. I tried installing wiht npm too but no luck. how can i fix this? thanks. https://github.com/ForkEyeee/realtime-poll/blob/main/realTimePollsApp/Views/Home/Index.cshtml
1 replies
CC#
Created by Ares on 2/19/2024 in #help
[ASP.NET Core] Help using js library in my view?
No description
21 replies
CC#
Created by Ares on 2/17/2024 in #help
how do i reload my form with its values if any exceptions are thrown in the controller for it?
i know you can use return View() but the thing is that my form is not its own page, so i am kind of stuck on how to do this. the form is a hidden modal window that is accessible from any page, as it is in the header.
Controller
[HttpPost]
public ActionResult Create(
[FromForm] string title,
[FromForm] string firstOption,
[FromForm] string secondOption,
[FromForm] int genre
)
{
try
{
var googleId =
HttpContext != null ? HttpContext.User.Claims.ToList()[0].Value : string.Empty;

if (googleId == string.Empty)
throw new Exception("Could not find googleId");

int userId = _context.User.SingleOrDefault(u => u.GoogleId == googleId).Id;

var pollGenre = _context.Genre.SingleOrDefault(g => g.Id == genre);

Poll poll = new Poll
{
UserId = userId,
Title = title,
FirstOption = firstOption,
SecondOption = secondOption,
GenreId = pollGenre.Id,
};

_context.Polls.Add(poll);
_context.SaveChanges();

return RedirectToAction(
"Index",
new
{
polltitle = poll.Title,
pollid = poll.Id,
userid = poll.UserId,
genreName = pollGenre.Name,
}
);
}
catch (Exception e)
{
var errorViewModel = new ErrorViewModel { RequestId = e.Message };
return View("Error", errorViewModel);
}
}
Controller
[HttpPost]
public ActionResult Create(
[FromForm] string title,
[FromForm] string firstOption,
[FromForm] string secondOption,
[FromForm] int genre
)
{
try
{
var googleId =
HttpContext != null ? HttpContext.User.Claims.ToList()[0].Value : string.Empty;

if (googleId == string.Empty)
throw new Exception("Could not find googleId");

int userId = _context.User.SingleOrDefault(u => u.GoogleId == googleId).Id;

var pollGenre = _context.Genre.SingleOrDefault(g => g.Id == genre);

Poll poll = new Poll
{
UserId = userId,
Title = title,
FirstOption = firstOption,
SecondOption = secondOption,
GenreId = pollGenre.Id,
};

_context.Polls.Add(poll);
_context.SaveChanges();

return RedirectToAction(
"Index",
new
{
polltitle = poll.Title,
pollid = poll.Id,
userid = poll.UserId,
genreName = pollGenre.Name,
}
);
}
catch (Exception e)
{
var errorViewModel = new ErrorViewModel { RequestId = e.Message };
return View("Error", errorViewModel);
}
}
152 replies
CC#
Created by Ares on 2/12/2024 in #help
How do i get the users profile picture when using ASP.NET CORE Google Auth?
Im using this package: https://www.nuget.org/packages/Microsoft.AspNetCore.Authentication.Google/ In my login controller, I have some of the following code:
public async Task<IActionResult> GoogleResponse() //authentication
{
try
{
var result = await HttpContext.AuthenticateAsync(
CookieAuthenticationDefaults.AuthenticationScheme
);

if (result.Principal == null)
throw new Exception("Could not authenticate");

var claims = result
.Principal.Identities.FirstOrDefault()
?.Claims.Select(claim => new
{
claim.Issuer,
claim.OriginalIssuer,
claim.Type,
claim.Value
})
.ToList();
public async Task<IActionResult> GoogleResponse() //authentication
{
try
{
var result = await HttpContext.AuthenticateAsync(
CookieAuthenticationDefaults.AuthenticationScheme
);

if (result.Principal == null)
throw new Exception("Could not authenticate");

var claims = result
.Principal.Identities.FirstOrDefault()
?.Claims.Select(claim => new
{
claim.Issuer,
claim.OriginalIssuer,
claim.Type,
claim.Value
})
.ToList();
claims object contains 5 properties , that have the email, firstname, lastname, etc. but it doesnt have the link for the user profile picture. I'm trying to figure out how to get the users profile picture while logging in. Is there a way i can do that?
15 replies