340,756 questions
2374
votes
41
answers
1.2m
views
How do I get a consistent byte representation of strings in C# without manually specifying an encoding?
How do I convert a string to a byte[] in .NET (C#) without manually specifying a specific encoding?
I'm going to encrypt the string. I can encrypt it without converting, but I'd still like to know ...
1
vote
1
answer
84
views
Callback methods with ProtoBeforeSerialization/ProtoAfterDeserialization donot work in protobuf-net 3.2.26, even when assigned explicitly to MetaType
I'm upgrading from protobuf-net 2.2.1.0 to 3.2.26, and I've noticed that callback methods decorated with [ProtoBeforeSerialization] and [ProtoAfterDeserialization] are no longer invoked during ...
1
vote
0
answers
134
views
Send array of objects to .NET controller action
I am trying to pass a javascript array of objects to a .NET controller action List<> parameter. Below is my C#
public bool ImportACE([FromBody] List<Element> elements)
{
foreach(...
3
votes
1
answer
167
views
how would I skew a Windows Forms texture/image so that one side is smaller/bigger than the other side to have a "pinched" look to it
(I am aware using windows forms for this kind of project is stupid and inefficient but it is a requirement for the college course I'm doing so I'm stuck using this)
in windows forms you can draw an ...
1
vote
1
answer
92
views
How to upload files from a C# console app to Sharepoint?
I'm pretty new to this (4 months into my first dev job) and I'm stuck on something.
The company asked me to write a C# program that uploads files from my computer to SharePoint Online. I googled ...
Best practices
0
votes
0
replies
40
views
How to run tests with CDK pipelines
We are building and deploying a few system using the AWS CDK Pipeline, mostly with dotnet
Most cases we are building the deployed apps using dockerfile assets referenced in the CDK
Should we run the ...
1866
votes
26
answers
2.5m
views
What is a NullReferenceException, and how do I fix it?
I have some code and when it executes, it throws a NullReferenceException, saying:
Object reference not set to an instance of an object.
What does this mean, and what can I do to fix this error?
1
vote
1
answer
50
views
Why does MSBuild apparently ignore CopyToOutputDirectory when specified in Directory.Build.props?
When you add an appsettings.json file to a project, the following is inserted in its .csproj file:
<ItemGroup>
<None Update="appsettings.json">
<CopyToOutputDirectory>...
1
vote
0
answers
68
views
System.Net.WebSockets is missing messages/notifications
I am creating a lib to listen to server notifications (more than 100,000 requests per hour), when using WebSocketSharp it is receiving all 100,000 notifications but there is memory leak (server goes ...
1
vote
1
answer
115
views
Hierarchical Directory.Packages.props with GlobalPackageReference doesn't resolve for tests
I have the following project structure (the full repo can be found at https://github.com/asarkar/functional-csharp-buonanno)
root
├── Directory.Packages.props
├── src
│ └── Proj1
│ └── Proj1....
1341
votes
39
answers
1.3m
views
How can I generate random alphanumeric strings?
How can I generate a random 8 character alphanumeric string in C#?
2
votes
1
answer
156
views
C# Project using Spinnaker SDK (for win-x64 and linux-arm64)
I am currently trying to utilize the Spinnaker SDK in a C# .NET8.0 application.
My goal is to make a cross-platform application that runs on both Windows-x64 and NVIDIA Jetson Orin (Linux ARM64)
I ...
1
vote
1
answer
69
views
EPSON LQ-350 - Control Continuous Printing via C# code to print line by line and prevent form feed
Use case: to dequeue plain string messages and print them line by line on to tractor feed paper without a form feed happening after each message is printed. Current solution (in code below) prints one ...
0
votes
0
answers
36
views
IAuthenticateResultFeature disappears when specifying schemes with AuthorizeFilter
I have been successfully reading the logged in OIDC authentication scheme from IAuthenticateResultFeature when using OIDC. I need to know this scheme to perform sign out. This is for a .NET 8 ASP....
2
votes
2
answers
279
views
C#, PowerShell hosting: how to process return variable
I want to use PowerShell in C#. Example:
using System.Management.Automation;
namespace PSTest;
class Program
{
static void Main()
{
using (var powerShell = PowerShell.Create())
...
0
votes
1
answer
29
views
.NET 9 on macOS ARM64: HttpClient fails with CSSM_ModuleLoad() / SSL connection error during unit tests
I'm running .NET 9.0.306 on macOS ARM64 and encountering an issue when running unit tests that call an external HTTPS API via HttpClient.
Note - Cookies disabled because problem first appeared as a ...
1
vote
2
answers
237
views
Why let with where clause can't translate to SQL?
I have a code snippet that uses let with a where clause.
private List<string> Example2()
{
var query1 =
from c in _context.Customers
let custPurchases = _context.Purchases....
0
votes
0
answers
228
views
C# Dev Kit on an Air Gapped Network
I am on an air gapped network trying to run a C++ project that uses solution files from Visual Studio, because that is what the rest of my team uses.
I have:
C# Dev Kit 1.61.22
C# 2.93.21
.NET ...
336
votes
59
answers
849k
views
Nuget connection attempt failed "Unable to load the service index for source"
While trying to connect to Nuget, I'm getting the error below, and then I am unable to connect:
[nuget.org] Unable to load the service index for source
https://api.nuget.org/v3/index.json.
An error ...
1
vote
0
answers
120
views
In case of large number of items Context Menu is slowing down WPF application view rendering
I have following context menu defined as a part of the DataTemplate in xaml:
<DataTemplate DataType="{x:Type viewModel:OverviewAnnotationItemViewModel}">
<views:...
1693
votes
25
answers
308k
views
What is the best algorithm for overriding GetHashCode?
In .NET, the GetHashCode method is used in a lot of places throughout the .NET base class libraries. Implementing it properly is especially important to find items quickly in a collection or when ...
1
vote
0
answers
207
views
C# array[i] where i is IBinaryInteger<T>?
A BinaryInteger<T> is an integer of some bit-length. I'd like to use it to index an array.
Casting to an int isn't possible - I have to use int.CreateTruncating(i) (or similar) at run-time to ...
1915
votes
20
answers
457k
views
Proper use of the IDisposable interface
I know from reading Microsoft documentation that the "primary" use of the IDisposable interface is to clean up unmanaged resources.
To me, "unmanaged" means things like database ...
628
votes
72
answers
379k
views
"The breakpoint will not currently be hit. The source code is different from the original version." What does this mean?
When debugging in Visual Studio, sometimes I add a breakpoint but it's hollow and VS says "The breakpoint will not currently be hit. The source code is different from the original version." Obviously ...
0
votes
0
answers
58
views
Handlebars.net Pre-Compilation
We are a little confused about pre-compiling a template.
for example:
Is it possible to store the template variable in say a database and then just retrieve it and call
string source =
@"<div ...