C#
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
Join ServerC
C#
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
Join ServerCommunity questions
Channels
YYorimirus・ヨリミルス3/30/2023
Synchronise an object across two threads?
Hello. I have an object that I use to wait listen for a message from a TcpConnection. However, while it is waiting, the connection could get lost. So I have a field for that called _connectionLost and I have an event that sets this field to false.
The problem is that this event is fired from a different thread than the one that does the actual waiting. So when this field is changed, the other thread doesn't recognize that the value changed, so it will continue waiting for a message, even though it's pointless.
When I look at it using a debugger, it still says _connectionLost is false. I have verified that the event gets properly fired and the field actually gets set. It's just that the other thread doesn't see that this change happened.
What can I do to make sure the other thread sees the change?
I tried locks, tokens and the volatile keyword. None seem to do anything.
The problem is that this event is fired from a different thread than the one that does the actual waiting. So when this field is changed, the other thread doesn't recognize that the value changed, so it will continue waiting for a message, even though it's pointless.
When I look at it using a debugger, it still says _connectionLost is false. I have verified that the event gets properly fired and the field actually gets set. It's just that the other thread doesn't see that this change happened.
What can I do to make sure the other thread sees the change?
I tried locks, tokens and the volatile keyword. None seem to do anything.
DdaVinki3/30/2023
✅ ResolvePackageAssets is failing because it can't find the NuGet fallback folder
I installed something called Godot portably on a USB which ended up being more invasive than everybody says. Now, none of my projects across all .NET SDKs are failing because it can't find "GodotNuGetFallbackFolder" that Godot created when the USB isn't plugged in. This is happening on all computers I ran Godot on. It's not malware, but it sure sounds like it.
Is there some way to reset it back to what it was? I've reinstalled .NET, ran the repair tool, and I couldn't find much online. To nobody's surprise, deleting the obj and bin of a project and restoring NuGet doesn't fix it. Restoring the NuGet doesn't error when restoring though
Is there some way to reset it back to what it was? I've reinstalled .NET, ran the repair tool, and I couldn't find much online. To nobody's surprise, deleting the obj and bin of a project and restoring NuGet doesn't fix it. Restoring the NuGet doesn't error when restoring though
Microsoft.PackageDependencyResolution.targets(266, 5): [MSB4018] The "ResolvePackageAssets" task failed unexpectedly.
NuGet.Packaging.Core.PackagingException: Unable to find fallback package folder 'F:\Godot\Godot_v4.0.1-stable_mono_win64\editor_data\mono\GodotNuGetFallbackFolder'.
at NuGet.Packaging.FallbackPackagePathResolver..ctor(String userPackageFolder, IEnumerable`1 fallbackPackageFolders)
at Microsoft.NET.Build.Tasks.NuGetPackageResolver.CreateResolver(IEnumerable`1 packageFolders)
at Microsoft.NET.Build.Tasks.ResolvePackageAssets.CacheWriter..ctor(ResolvePackageAssets task)
at Microsoft.NET.Build.Tasks.ResolvePackageAssets.CacheReader.CreateReaderFromDisk(ResolvePackageAssets task, Byte[] settingsHash)
at Microsoft.NET.Build.Tasks.ResolvePackageAssets.CacheReader..ctor(ResolvePackageAssets task)
at Microsoft.NET.Build.Tasks.ResolvePackageAssets.ReadItemGroups()
at Microsoft.NET.Build.Tasks.ResolvePackageAssets.ExecuteCore()
at Microsoft.NET.Build.Tasks.TaskBase.Execute()
at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask)
Ccap5lut3/30/2023
✅ Make method implemented in interface accessible from implementing type
i have an interface
now
i tried implementing it in the adapter by simply casting
interface ICL
{
public IEnumerable<ICLPlatform> GetPlatforms()
{
// code
}
}
and an implementing structstruct CLAdapter : ICL
{
}
now
GetPlatforms()
isnt reachable via new CLAdapter().GetPlatforms()
, how can i make that accessible?i tried implementing it in the adapter by simply casting
this
to ICL
, but then i run into stack overflows /// <inheritdoc/>
public IEnumerable<ICLPlatform> GetPlatforms()
{
return ((ICL)this).GetPlatforms();
}
Oocc3/29/2023
Assert.Raises<> in xUnit
I'm trying to create tests for certain events. However it seems that xUnit assumes that I use EventHandler# for my events (see screenshot) which is not true for me.
I have my own delegate for events:
So I'm wondering if there's a way I could test it using my delegate (preferably while still using xUnit). Any help would be appreciated.
I have my own delegate for events:
public delegate ValueTask ValueTaskEvent<in Arg1>(Arg1 arg1);
So I'm wondering if there's a way I could test it using my delegate (preferably while still using xUnit). Any help would be appreciated.


Ccgxlm3/29/2023
Ambiguity between 2 things idk how to fix
Got an error message all of a sudden saying this when everything was working perfect before so i undid all the work i done and exited without saving but its still there


Zzezima113/29/2023
❔ Project structure
1. In my Solution there should be only 1 Project right? Unless its a big App
2. I started using folders in my Project 1 for all interfaces, 1 for all the Items lets say, 1 for all the character types(player,monster,npc) and so on. Is there a better way to structure your project?
3. I created a GitHub acc. Now I wanna structure the Projects that I wanna show off to companies but also keep other projects private (small projects or stuff I don´t wanna show to other people) Is it even a good idea to link my github to companies because I saw that they could see my commit history and every change made (some of my commits are dumb since I am also playing around getting to know git a bit more)...
4. Same as 3. but local project structure. So since I just started I have lots of different "small" projects. Kind of embarassing if I would put them all on my github repo. But they have little cool implementations that I would want to have access to lets say maybe even at work. How would you guys go about this?
Thanks in advance!
2. I started using folders in my Project 1 for all interfaces, 1 for all the Items lets say, 1 for all the character types(player,monster,npc) and so on. Is there a better way to structure your project?
3. I created a GitHub acc. Now I wanna structure the Projects that I wanna show off to companies but also keep other projects private (small projects or stuff I don´t wanna show to other people) Is it even a good idea to link my github to companies because I saw that they could see my commit history and every change made (some of my commits are dumb since I am also playing around getting to know git a bit more)...
4. Same as 3. but local project structure. So since I just started I have lots of different "small" projects. Kind of embarassing if I would put them all on my github repo. But they have little cool implementations that I would want to have access to lets say maybe even at work. How would you guys go about this?
Thanks in advance!
PPatrickG3/29/2023
❔ how to use EF6 in library with no dependancy injection and no startup.cs
I used EF core power tools to generate DB Context and reverse engineer the models.
now I get an error:
System.InvalidOperationException
HResult=0x80131509
Message=No database provider has been configured for this DbContext. A provider can be configured by overriding the 'DbContext.OnConfiguring' method or by using 'AddDbContext' on the application service provider. If 'AddDbContext' is used, then also ensure that your DbContext type accepts a DbContextOptions<TContext> object in its constructor and passes it to the base constructor for DbContext.
Source=Microsoft.EntityFrameworkCore
all the answers I can find are doing something in startup.cs which i dont have or using the dependancy injection framework which i dont use either
now I get an error:
System.InvalidOperationException
HResult=0x80131509
Message=No database provider has been configured for this DbContext. A provider can be configured by overriding the 'DbContext.OnConfiguring' method or by using 'AddDbContext' on the application service provider. If 'AddDbContext' is used, then also ensure that your DbContext type accepts a DbContextOptions<TContext> object in its constructor and passes it to the base constructor for DbContext.
Source=Microsoft.EntityFrameworkCore
all the answers I can find are doing something in startup.cs which i dont have or using the dependancy injection framework which i dont use either
Zzezima113/29/2023
❔ HeadFirst Design Pattern
So I started with this Book today. First problem starts with the Duck Project:
and when he tests he makes an instance of an abstract class ???? Is this a Java thing that works but not in C#?
and when he tests he makes an instance of an abstract class ???? Is this a Java thing that works but not in C#?




EElio3/29/2023
✅ EqualityComparer
Hello, anyone know of this code work ?
-->
cause i'm wondering if this will trigger the equals override inside myclass to compare each element or if it will do an equal on the collection to look if they have the same hashcode or something like that
-->
EqualityComparer<ICollection<myclass>> .Default.Equals(myclassS, x.myclassS)
cause i'm wondering if this will trigger the equals override inside myclass to compare each element or if it will do an equal on the collection to look if they have the same hashcode or something like that
PPH3/29/2023
❔ error attaching script (unity)
this error appears when trying to attach the script, does anyone know how to solve it?


FFyren3/29/2023
yield???
public IEnumerable<int> A()
{
for (int i = 0; i <= 10; i += 2)
yield return i;
}
public IEnumerable<int> B()
{
var ints = new List<int>();
for (int i = 0; i <= 10; i += 2)
ints.Add(i);
return ints;
}
What is the difference here?
GGuns3/29/2023
C# Data Table issue
https://pastebin.com/DSHwSh0M
based on this program, I need to set the values of the
Rn this is how it is being done, but for unknown reasons, even after updating the file the values for that column (
e.g; on the fist run i.e when the file is not yet synced the data grid view should look like this;
v1;
then after updating the file and re opening the updated file, the data grid view should look like this;
v2;
but instead the datagrid view is still looking like the first version...
based on this program, I need to set the values of the
Old PS A11Y State
in the mergedDataTable
to the values from the initial target file/worksheet and technically the targetDataTable
. what do i need to changed?Rn this is how it is being done, but for unknown reasons, even after updating the file the values for that column (
Old PS A11Y State
) are not being updated;foreach (DataRow targetRow in targetRows)
{
targetRow.SetField("Status", updatedStatus);
DataRow updatedRow = syncedDataTable.NewRow();
updatedRow["Finding ID"] = findingId;
updatedRow["Status"] = updatedStatus;
syncedDataTable.Rows.Add(updatedRow);
DataRow mergedRow = mergedDataTable.NewRow();
mergedRow["Finding ID"] = findingId;
mergedRow["eA State"] = sourceDataTable.Rows[i].Field<string>("Status");
// assuming the issue is here;
mergedRow["old PS A11Y State"] = targetDataTable.Rows[i].Field<string>("Status");
mergedRow["new PS A11Y State"] = updatedStatus;
mergedDataTable.Rows.Add(mergedRow);
}
e.g; on the fist run i.e when the file is not yet synced the data grid view should look like this;
v1;
finding id, ea state,old, new
1a, closed, open, closed
then after updating the file and re opening the updated file, the data grid view should look like this;
v2;
finding id, ea state,old, new
1a, closed, **closed**, closed
but instead the datagrid view is still looking like the first version...
Ccoolyukii3/29/2023
❔ Microsoft Graph SDK - Serializing objects
Hello,
I am currently working with Microsoft Graph API to work with the Planner. My goal is to backup tasks, buckets and such (all info necessary basically) so that it could be later imported in case things got deleted.
I figured that I'd backup the information in JSON format, so that it can be easily uploaded back in without much hassle.
However, I'm running into an issue;
I've noticed that
The general idea is to serialize all of the tasks into JSON and then store it in a file.
I am currently working with Microsoft Graph API to work with the Planner. My goal is to backup tasks, buckets and such (all info necessary basically) so that it could be later imported in case things got deleted.
I figured that I'd backup the information in JSON format, so that it can be easily uploaded back in without much hassle.
However, I'm running into an issue;
var tasks = await graphClient.Groups["id"].Planner.Plans["id"].Tasks.GetAsync();
I've noticed that
tasks
has a .Serialize()
method, however, I cannot figure out how to supply it with a Microsoft.Kiota.Abstractions.SerializationWriter
param. Any ideas?The general idea is to serialize all of the tasks into JSON and then store it in a file.
Ccarrotther3/29/2023
❔ XML deserialise different types into a single list
I'm using the build in XML serialisation library (unless it's with .NET framework?), and I current have it deserialise a collection of elements into a list of that element type. This is my class:
But I also want to add a Mousestroke too (LMB, RMB, etc), but I want to maintain the order that they are placed in the XML document, meaning I need them to go into 1 list right? Is it possible to do that for 2 different types or is that a limitation in the serialiser?
public class Shortcut {
[XmlElement("Keystroke")] public List<Keystroke> KeyStrokes { get; set; }
}
public class Keystroke {
[XmlAttribute("Keycode")] public string KeyCode { get; set; }
[XmlAttribute("Mods")] public string Mods { get; set; }
}
But I also want to add a Mousestroke too (LMB, RMB, etc), but I want to maintain the order that they are placed in the XML document, meaning I need them to go into 1 list right? Is it possible to do that for 2 different types or is that a limitation in the serialiser?
FVFlorian Voß3/29/2023
❔ Access things from different scene in Unity
I have a Class Selector scene that has a Class Selector Script component (MonoBehaviour) attached to one of it's GameObjects, see first screenshot.
I have a Stat Selector scene that has a Stat Selector Script component (MonoBehaviour) attached to one of it's GameObjects.
The Stat selector holds a field of type ClassSelector and I want to assign to it the ClassSelector from my ClassSelector Scene, how can I do that?
I have a Stat Selector scene that has a Stat Selector Script component (MonoBehaviour) attached to one of it's GameObjects.
The Stat selector holds a field of type ClassSelector and I want to assign to it the ClassSelector from my ClassSelector Scene, how can I do that?


KKamyab3/29/2023
❔ C# how do I write an If-statement to handle a button?
Hi, I wanted some assistance with writing a If-statement that filters out the zones section in my app when the switch shown in the first pic is pressed off.








DDultus3/29/2023
❔ Magnetic Links for application?
Hey, does someone have an article/tutorial/explanation how I can develop magnetic links for my application?
E.g. I click on a link or open a website and my application gets called.
E.g. I click on a link or open a website and my application gets called.
NNobody3/29/2023
❔ Show values from a list in a datagridview getting source from bindingsource
Hello! I have the following problem: I am currently developing a winforms app with a datagridview that takes its information from a bindingsource. In this bindingsource i have multiple objects based on my materials class. Every material have two variables, one for its name and a list for other objects that each material should have. Every material have the same number of objects in this list and they all have the same name. I cant seem to figure out how to do this however.
OOdin3/29/2023
❔ GetAxis wont work
public class Driver : MonoBehaviour
{
// Start is called before the first frame update
const float MoveUnitsPerSecond = 5;
float horizontalInput = Input.GetAxis("Horizontal");
float verticalInput = Input.GetAxis("Vertical");
// Update is called once per frame
void Update()
{
//move game object as needed
Vector3 position = transform.position;
if (horizontalInput != 0)
{
position.x += horizontalInput * MoveUnitsPerSecond *
Time.deltaTime;
}
if (verticalInput != 0)
{
position.x += verticalInput * MoveUnitsPerSecond *
Time.deltaTime;
}
transform.position = position;
}
} Why wont GetAxis work, the course i am going off of has this exact code but unity is saying that I cannot call GetAxis("Horizontal") from a monobehavior constructor
{
// Start is called before the first frame update
const float MoveUnitsPerSecond = 5;
float horizontalInput = Input.GetAxis("Horizontal");
float verticalInput = Input.GetAxis("Vertical");
// Update is called once per frame
void Update()
{
//move game object as needed
Vector3 position = transform.position;
if (horizontalInput != 0)
{
position.x += horizontalInput * MoveUnitsPerSecond *
Time.deltaTime;
}
if (verticalInput != 0)
{
position.x += verticalInput * MoveUnitsPerSecond *
Time.deltaTime;
}
transform.position = position;
}
} Why wont GetAxis work, the course i am going off of has this exact code but unity is saying that I cannot call GetAxis("Horizontal") from a monobehavior constructor
OONW-Uno3/29/2023
✅ (SOLVED)Help a Beginner
i am following CodeMonkeys 11Hr youtube video on coding a game in unity. I have ran into a issue where unity wont even open the project besides in safe mode even though the errors it is telling me needs fixed are from scripts that i haven't touched in a while. im asking for help with how to solve whatever weird issue im having and i just hope my project didnt corrupt over the time i was at work. Thanks in advance.

