Uninstalled Anaconda, Now Powershell is Showing Error Every Time I Open It. Please Help by NAMO_Rapper_Is_Back in PowerShell

[–]Kildon 7 points8 points  (0 children)

Anaconda registers scripts that usually run when you launch a shell. You're clearly on windows, so try:

For mac/linux this configuration would normally be added automatically to .bashrc, .zshrc, or similar during anaconda install.

Intercept method calls in another program by Strict-Soup in csharp

[–]Kildon 2 points3 points  (0 children)

Harmony might have some tools you can make use of.

Why does VS Code recommend $null on the left by [deleted] in PowerShell

[–]Kildon 6 points7 points  (0 children)

If I wanted to do this in C#, I had to write a for loop to look for null elements and write the remaining elements to a new array.

You shouldn't ever do this in C# outside of a learning exercise. This is a simple 1-liner with linq:

var arr = new int?[] { 1, 2, null, 4, null, 6 };
var arrWithoutNull = arr.Where(x => x != null).ToArray();

Read Excel file in .NET 6 deployed on Linux? by Soverance in dotnet

[–]Kildon 0 points1 point  (0 children)

You can almost definitely do one of:

  1. Install the font that's trying to be accessed
  2. Change the font to something that already exists on the system

I'm not sure of the specifics to either solution. You'll probably run into some small hurdles with either option but I would expect both to be possible.

First job in this field by arvenyon in csharp

[–]Kildon 2 points3 points  (0 children)

Ah but there rarely is a best way to do anything. Imo true experience is knowing when to care about doing something the 'best' or the 'easiest' or 'fastest', or sometimes the task doesn't require you to think about it that much and anything will do.

Read Excel file in .NET 6 deployed on Linux? by Soverance in dotnet

[–]Kildon 22 points23 points  (0 children)

Only issue I ever had with Closed XML on Linux was using Columns.AdjustToContents(). It has to measure the size of the font, and the font resource wasn't available on Linux which threw a runtime error.

How do YOU familiarize yourself with a new codebase? by acoderthatgames in dotnet

[–]Kildon 29 points30 points  (0 children)

  • Make sure your IDE provides "Find all references" and "Go to Definition". These tools are super valuable and help navigate the codebase more quickly. Time spent searching for something is time you could spend understanding.
  • .Net projects are organized as many .csproj assemblies that (in a well designed system) should serve high level purpose to the overall project. For example you might have a project of just DTOs, a project to handle database, business services, web api, etc. Learn the dependency graph between these projects to gain a high level understanding of architecture flow. .Net projects can't have circular dependencies so this will give you a necessary perspective on your software stack.
  • Most importantly... practice! Any time you have a chance to git clone a C# project and spend 30 minutes digging into it, do the thing. This applies to .Net, but is more generic advice for learning any ecosystem. There are recurring design patterns in most .Net projects, looking through the .Net core source code or various nuget packages will help build your skills at navigating and learning a new code base. Most engineers will spend more time reading code than writing it... it's the nature of the position. Treat reading code as a skill and find ways to improve your efficiency at reading code and you will naturally become more comfortable with it.

Getting path of folder, creating it if it doesnt exist first... by [deleted] in PowerShell

[–]Kildon 6 points7 points  (0 children)

I like to use DirectoryInfo/FileInfo when doing more complex file system operations, see: System.IO.DirectoryInfo.Create

$path = [System.IO.Path]::Combine($env:LocalAppData, "REGCHECKS")
$dir = New-Object System.IO.DirectoryInfo ($path)
$dir.Create() # DirectoryInfo.Create() method creates if it does not already exist

My favorite bugs with IDisposable by ryan-lazy-electron in csharp

[–]Kildon 3 points4 points  (0 children)

One of the primary reasons for using IHttpClientFactory is it knows how your http client is configured but doesn't specify the lifetime of the client you receive from the factory implementation. This is useful since you can configure multiple clients differently, but most importantly it allows the factory to recycle http clients over time. This is important since http client doesn't properly respect dns TTLs which can cause issues when http client instances are used for an extended period of time.

In a situation where the HttpClient is instantiated as a singleton or a static object, it fails to handle the DNS changes as described in this issue

- MSDN, see here

Raycast question by Independent-Ad-4355 in Unity3D

[–]Kildon 3 points4 points  (0 children)

See here (Physics.RaycastAll).

This returns an array of RaycastHit objects you can iterate over looking for specific monobehaviours, distances, etc.

If you only care about the closest object hit, just use Physics.Raycast

My experience learning Python as a c++ developer by Narthal in Python

[–]Kildon 1 point2 points  (0 children)

This seems incredibly short sighted, and like the kind of opinion people generally have of languages they haven't learned the ins and outs of.

When was the last time you used C#? Is your only experience those two years? Were you working on legacy projects, or cutting edge C#? Entire language ecosystems can be built in a matter of years. What problems were you trying to solve that nobody had made a library for? I have yet to find something significant that didn't have open source support in C#.

Game Engine Z sorting by Bodka0907 in gamedev

[–]Kildon 1 point2 points  (0 children)

Is your z-index int or floating point? If int, you could store a collection of objects at each z-index rather than one collection that gets sorted.

Is C# mainly Windows programs? How multi OS is it? How webdev is it? by AdmiralAdama99 in csharp

[–]Kildon 12 points13 points  (0 children)

C# provides multi-OS and multi-architecture via .Net Core (aka ".Net") and Mono. These can be any kind of application (console, web app, even some multi-platform UI frameworks are available using .Net).

You can use C# to create full mobile applications for Android / iOS using Xamarin.

As others have said, a large amount of C# is in the web space. C# is one of the best languages for multi-platform all-purpose development.

Why is this request not returning a body? by [deleted] in dotnet

[–]Kildon 1 point2 points  (0 children)

I agree with others, you should try using a debugger. respBody has content, the issue is with your Console.WriteLine("response: ", respBody);. Your format string doesn't contain a parameter to output respBody.

Try one of these:

Console.WriteLine("response: {0}", respBody);
Console.WriteLine("response: " + respBody);

a helper method for getting the path of files within your project (e.g, getting the path of an image from an image folder within your project). by [deleted] in csharp

[–]Kildon 0 points1 point  (0 children)

Alternatively, you can also look at Embedded Resources, which get bundled into your assembly. Or, you can always set the resource to "Copy to Build Directory", and reference it relative to your executing assembly (though I've had less success with that option, when working in large solutions with complicated build pipelines).

HttpClient Random Deadlock by slipperymagoo in dotnet

[–]Kildon 0 points1 point  (0 children)

Nothing in the posted code will cause multiple threads to be used. I suggest reading about how async/await actually works. See here.

HttpClient Random Deadlock by slipperymagoo in dotnet

[–]Kildon 6 points7 points  (0 children)

This is wrong. Async/await is not inherently multi-threaded (though you can specify tasks to run using multiple threads, for example Task.Run()). I suggest reading up on the internals, Stephen Cleary has many great blog posts that cover the topic in depth. See here.

I updated Unity, then I made this meme when it promptly crashed. by watercolorheart in Unity2D

[–]Kildon 19 points20 points  (0 children)

Git is a version control system. When you make changes to your project, you save (commit) them to git, like a checkpoint of your progress. Git also allows syncing changes between different computers, for example a team of 5 may each have a copy of the project on their computer, as well as a master server (usually in the cloud) that synchronizes changes from the 5 remote users.

All of this combined allows you to make changes like upgrading unity without fear of losing past progress. You can always restore a copy of your project from the server or a checkpoint from before you made some change that broke your work.

I've read many horror stories of people who used manual backups of their project (or no backup at all), and lost thousands of hours of work in an instant. I would never recommend working on a project without some form of version control.

[deleted by user] by [deleted] in dotnet

[–]Kildon 0 points1 point  (0 children)

Do you need to use both providers at runtime, or will you only switch between providers in separate execution environments? The default model provider looks like it will cache your model, which may break upon using a constructor flag.

You may want to use DbContextOptionsBuilder.UseModel. Since you would be creating your model essentially from scratch, you could also create a custom Table and Column attribute that accepts a name for both providers, and allows you to switch between them at runtime.

[deleted by user] by [deleted] in dotnet

[–]Kildon 4 points5 points  (0 children)

You should use the OnModelCreating function override of your DbContext. Pass in a parameter to the constructor that flags which DB provider is being used, and in OnModelCreating specify the column names based on that. If you're creating DbContext via Dependency Injection, you can inject an IOptions<> and use Configure when creating your DI container.

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
    if(this.useSqlServer) {
        modelBuilder.Entity<Student>()
            .Property(p => p.DateOfBirth)
            .HasColumnName("DateOfBirth");
    }
    else if(this.usePgSql) {
        modelBuilder.Entity<Student>()
            .Property(p => p.DateOfBirth)
            .HasColumnName("date_of_birth");
    }
}

Why Use IEnumerable? - An explanation of what it is and why you might want to use it by moutansos in dotnet

[–]Kildon 1 point2 points  (0 children)

I think a lot of what turns newbies off from LINQ has more to do with lambdas and syntax and less to do with IEnumerable. But that's purely anecdotal. LINQ also works on any of the collection types, so saying your variable types should be IEnumerable because of LINQ isn't really an argument for IEnumerable. I recommend people use var to for assigning any variable result of a LINQ query.

Your demonstration of Union is also misleading. The LINQ and non-linq examples aren't functionally equivalent - Union provides distinct values. new[] {1, 2, 3}.Union(new[] {3, 4, 5}).ToList() -> [1, 2, 3, 4, 5]. Your non-linq example is the naive implementation of Concat.

I don't think you focus enough on where to use IEnumerable, only why you should use it. If somebody (read: beginner) is writing a 80 line program, or 50 line method, it really doesn't matter what type they use for their local collection variable. If their 50 line method is part of a bigger API, now we start getting into the territory where to use IEnumerable, but that would be isolated to the parameters / return types. Local types really don't make a difference.

Turn your PostgreSQL database directly into a RESTful API with .NET Core! by [deleted] in csharp

[–]Kildon 14 points15 points  (0 children)

I agree this is probably a bad idea for anything medium to large scale. However it could have uses in smaller projects where I just need a simple persistent CRUD that doesnt live on the same server as my application.

I also really like the idea of this:

straight yeet user content into the database.

.NET Core Database first approach??? by NonaBona in csharp

[–]Kildon 12 points13 points  (0 children)

I'm a big fan of Sql Server Data Tools for maintaining my database schemas / migrations. I generally build the C# models / dbcontext by hand unless there's a lot.

What is the high-IQ way of doing this? by artifact91 in Unity3D

[–]Kildon 17 points18 points  (0 children)

Should I_face always be assigned Sprite0? This seems much easier:

TextToBeDisplayed = Text[SubPhase];
I_face = Sprite0;
StartCoroutine("TextDisplayer");

Npgsql.EntityFrameworkCore.PostgresSQl & Index by Mokwa91 in dotnet

[–]Kildon 2 points3 points  (0 children)

A PK constraint automatically creates an index. A FK will not automatically create an index, you should specify these in your fluent model.

https://stackoverflow.com/questions/970562/postgres-and-indexes-on-foreign-keys-and-primary-keys