Quantcast
Channel: User Kyle McClellan - Stack Overflow
Browsing latest articles
Browse All 43 View Live

Comment by Kyle McClellan on Call async method in AddTransient in Startup -...

This is okay, but you still need to await. I think OP is trying to avoid asynchronous code in the parts of the app that consume IFoo.

View Article



Comment by Kyle McClellan on The operation was canceled .net

You could add _httpClient.Timeout = TimeSpan.FromMinutes(5); before you make the request. It's probably better to do it as part of the initialization of your client, which is not included in your code.

View Article

Comment by Kyle McClellan on Redis list with expiring entries?

If elements are added in timestamp order, a regular list of serialized timestamp/values with RPUSH would work. Use LINDEX 0 to check the oldest entry and LPOP to expire it. This is more efficient since...

View Article

Comment by Kyle McClellan on Transactions failing when all conditions are met...

"transactions only fail if their conditions aren't met" - not true. Conditions are evaluated prior to issuing the multi/exec. Any changes to watched keys during the remainder of the transaction will...

View Article

Comment by Kyle McClellan on How to compile code using...

As I mentioned, hoping to do this without changing the source code (since this would be an extensive project)! If the answer is "that's not possible," this is still a different question than the above.

View Article


Comment by Kyle McClellan on How to compile code using...

I've got this working using -D'__declspec(dllexport)=__attribute((visibility("default"))‌​)'! Note that you need to wrap the option in single quotes if it contains special characters. I'm also using...

View Article

Comment by Kyle McClellan on .NET Concurrent Dictionary Exchange Value

"wouldn't the lambda be executed again" - not if the value was deleted. It would hit this line. To avoid looping, you'd need to specify an addValueFactory that sets the default as well.

View Article

Comment by Kyle McClellan on .NET Concurrent Dictionary Exchange Value

As discussed in Theodor's answer, I think you need _ = dict.AddOrUpdate(key, key => { oldValue = default; return newValue; }, (key, old) => { oldValue = old; return newValue; });

View Article


Comment by Kyle McClellan on Conform IAsyncEnumerable to Dataflow ISourceBlock

I disagree with the distinction. Both async enumerables and source blocks model an interaction with data that may or may not exist yet. Dataflow blocks are more feature rich but are consequently more...

View Article


Comment by Kyle McClellan on Associate a CancellationToken with an async...

What is the rationale behind TaskContinuationOptions.ExecuteSynchronously?

View Article

Comment by Kyle McClellan on How to use an object's identity as key for...

@MikeNakis Because of the contravariance of IEqualityComparer<in T>, ReferenceEqualityComparer.Instance works for any type derived from object.

View Article

Answer by Kyle McClellan for Overwrite Branch in Git

You are close. Because there is no "theirs" strategy, you have to do some branch hopping. To get Stage to look exactly like UAT, you have to first merge Stage into UAT.git checkout UATgit merge -s ours...

View Article

Answer by Kyle McClellan for "WARNING: Can't mass-assign protected attributes"

If you want to disable mass assignment protection for an individual call (but not globally), the :without_protection => true option can be used. I find this useful for migrations and other places...

View Article


Answer by Kyle McClellan for Ruby - Ignore protected attributes

Personally, I like to keep things in the model by overriding assign_attributes.def assign_attributes(new_attributes, options = {}) if options[:safe_assign] authorizer =...

View Article

No authentication handler is configured to authenticate for the scheme: Windows

I haven't seen any questions addressing this error specific to the "Windows" authentication scheme. I have an ASP.NET Core 2.0 app hosted in IIS, and I tried to follow these instructions to set up...

View Article


Answer by Kyle McClellan for EF Core Update-Database command creates schema...

Calling modelBuilder.HasDefaultSchema("dbo") in the db context solved this problem for me (EF 3.1.7), but it needs to be there when you generate the migration (not when it gets applied). This makes EF...

View Article

Answer by Kyle McClellan for Escape dot (.) from I18n translation look up

I had the same problem loading translations from a non-YAML source where period syntax was more convenient than a tree relationship. You can use the below code to convert the keys as part of I18n...

View Article


Answer by Kyle McClellan for ECDsa Signing in .Net Core on Linux

Update: As of .NET Core 3.0, cross-platform PKCS is now built into the framework.private static ECDsa GetEllipticCurveAlgorithm(string privateKey){ var result = ECDsa.Create();...

View Article

Answer by Kyle McClellan for Elasticsearch, how to return unique values of...

SQL's SELECT DISTINCT [cat], [sub] can be imitated with a Composite Aggregation.{"size": 0, "aggs": {"cat_sub": {"composite": {"sources": [ { "cat": { "terms": { "field": "cat" } } }, { "sub": {...

View Article

Answer by Kyle McClellan for How to deal with nullable reference types with...

Another option, for those who want to handle missing properties with meaningful exceptions:using System;public class Car{ private string? name; private int? year; public string Name { get =>...

View Article

Deterministic Surrogate Key

I have a table with an integer identity column as a surrogate key for two other columns (int and datetime). To keep the value of this key in sync across test and production environments, I had the idea...

View Article


Answer by Kyle McClellan for Exception thrown from task is swallowed, if...

You don't have to use BackgroundService. As the name implies, it's useful for work that isn't the primary responsibility of the process and whose errors shouldn't cause it to exit.You can roll your own...

View Article


Answer by Kyle McClellan for How to abort unit test from another thread?

A solution leveraging TimeoutAttribute and/or TestContext.CancellationTokenSource:[TestClass]public class SomeTestClass{ private Task abortTask; // Test runner will set this automatically. public...

View Article

Answer by Kyle McClellan for Does the new `System.Text.Json` have a required...

As of 5.0, you can achieve this using constructors. Any exceptions will bubble up during deserialization.public class Videogame{ public Videogame(string name, int? year) { this.Name = name ?? throw new...

View Article

Answer by Kyle McClellan for EditorConfig section inheritance

Your section header contains a typo and should be [*.cs] to match files with the .cs extension.To answer the question, however, you do not need to specify rules "again" for each section. It's expected...

View Article


Answer by Kyle McClellan for Log without Exception stack trace in Serilog

Regardless of what log properties exist, "formatters" are how Serilog transforms standard log information (including exceptions) into text.To get rid of the redundancy, you'll need to use a something...

View Article

Answer by Kyle McClellan for Security implications of refresh token grace period

The description of the security benefit of token rotation in OAuth 2.0 Security Best Current Practice:If a refresh token is compromised and subsequently used by both the attacker and the legitimate...

View Article

OAuth: Should an unexpired access token be revoked when it is refreshed?

Typically an access token is refreshed (using a refresh token) when it is expired. However, it's possible to refresh an unexpired token. I understand the requirements for revoking the refresh token as...

View Article

Answer by Kyle McClellan for using system.linq for each new project created?

If you're using C# 10+ (default with .NET 6+), you can enable ImplicitUsings in your project file. There are a handful of common namespaces (including the two you mention) that are then automatically...

View Article



Answer by Kyle McClellan for ARel select rows by string length

AREL's value is not just for DB cross-compatibility. I had a similar use case where I had to create AREL nodes for custom algebra.I believe this is what you were looking for:class User <...

View Article

Answer by Kyle McClellan for What is default location for apache kafka...

kafka-run-class.sh has the following code:base_dir=$(dirname $0)/..# Log directory to useif [ "x$LOG_DIR" = "x" ]; then LOG_DIR="$base_dir/logs"fiKAFKA_LOG4J_OPTS="-Dkafka.logs.dir=$LOG_DIR...

View Article

Answer by Kyle McClellan for Call async method in AddTransient in Startup -...

What I usually do in this case is implement a IHostedService do to the asynchronous work I need at startup and store it in some singleton state. As long as any services that use IFoo are registered...

View Article

Answer by Kyle McClellan for "AddOptions.Configure()" doesn't work when...

This is almost definitely because of named options. AddOptions() without a name parameter applies the delegate to the default name (string.Empty). Your implementation of IConfigureNamedOptions runs for...

View Article


Answer by Kyle McClellan for Pop multiple values atomically from a Redis FIFO...

As of 6.2.0, LPOP and RPOP now support a count argument.

View Article

Answer by Kyle McClellan for Start IHostedService after Configure()

The source code of the newer WebApplicationBuilder recommends leveraging ConfigureContainer to achieve this behavior, though I personally don't find that to be the cleanest solution and seems likely it...

View Article

.NET Concurrent Dictionary Exchange Value

Is there a data structure similar to ConcurrentDictionary<TKey,TValue> and Interlocked.Exchange<T>(...) that would allow you atomically to set a new value and retrieve the old value...

View Article


How does cancellation acknowledgment work for async continuations?

The documentation for Task.IsCanceled specifies that OperationCanceledException.CancellationToken has to match the cancellation token used to start the task in order to properly acknowledge. I'm...

View Article


Comment by Kyle McClellan on query for one field doesn't equal another field...

Note that this is an "expensive" query since it can't do an indexed lookup. ES doesn't really offer feature parity with relational databases here.

View Article

Comment by Kyle McClellan on Start a task with clean AsyncLocal state

Why the need for Task.Run(...)? Shouldn't SuppressFlow() by itself do the trick?

View Article

Answer by Kyle McClellan for ASP.NET Core - System.Text.Json: how to reject...

This is now supported as of .NET 8 and/or System.Text.Json v8.0.0: https://learn.microsoft.com/en-us/dotnet/standard/serialization/system-text-json/missing-members

View Article
Browsing latest articles
Browse All 43 View Live




Latest Images