Sekoree
Sekoree
CC#
Created by Sekoree on 6/21/2024 in #help
Every HttpClient request has a 5 second delay before execution
As the title says, it confuses me and the worst part, it works on my machine but not the one the Program has to run on. Its a simple Avalonia app, a customizable grid with buttons that when pressed send a HTTP request. Its a local network connection, plain HTTP Is there any HttpClient option I'm missing, some kind of Timeout?
29 replies
CC#
Created by Sekoree on 5/31/2024 in #help
✅ Trimming/NativeAOT preserve specific constructor(s) in ClassLibrary
Hi, I'm a bit stuck with a trimming issue. I basically have a shared project that has an abstract base class that other components can implement with a constructor that has some parameters. Additionally it has a management class that handles creation of these components implementing that base class. I use the Activator class to create instances of these components (which is the issue here I guess). Is there any way to tell it not to remove the constructor on those components (and I guess that base class)? Using and rd.xml worked once, now not anymore and idk why, but telling it to not trim those libraries entirely wouldn't be nice either. Is there any way to define this from the shared project to apply to other libraries that implement that base class too? (Also open to suggestions to not have to use this (static "Create" method in a base Interface maybe(?)) The implementations look like this: The method that creates the objects: https://github.com/vocawaves/Manager/blob/2fcde9b4f24a2eb551aa11671a808c99fc64de39/Manager.Shared/ComponentManager.cs#L20 One of the Components: https://github.com/vocawaves/Manager/blob/2fcde9b4f24a2eb551aa11671a808c99fc64de39/Manager.SimplePlayer/MediaPlayer.cs#L49 The base class: https://github.com/vocawaves/Manager/blob/2fcde9b4f24a2eb551aa11671a808c99fc64de39/Manager.Shared/Interfaces/General/ManagerComponent.cs#L51
13 replies
CC#
Created by Sekoree on 8/23/2023 in #help
✅ P/Invoke, changing values in a struct overwrites overwrites other values
Heyo! I'm working on a P/Invoke library for libMPV and it has a way to send it structured data instead of just strings as commands, but I'm kind of stuck at the struct layout. The root looks like this (it has a union so there is a bunch of values at offset 0)
[StructLayout(LayoutKind.Explicit, Size = 16)]
public struct MPVNode
{
[FieldOffset(0)]
public nint StringValue;
[FieldOffset(0)]
public int YesNoFlag;
[FieldOffset(0)]
public long IntegerValue;
[FieldOffset(0)]
public double DoubleValue;
[FieldOffset(0)]
public MPVNodeList NodeListValue;
[FieldOffset(0)]
public MPVByteArray ByteArrayValue;
[FieldOffset(8)]
public MPVFormat Format;
}
[StructLayout(LayoutKind.Explicit, Size = 16)]
public struct MPVNode
{
[FieldOffset(0)]
public nint StringValue;
[FieldOffset(0)]
public int YesNoFlag;
[FieldOffset(0)]
public long IntegerValue;
[FieldOffset(0)]
public double DoubleValue;
[FieldOffset(0)]
public MPVNodeList NodeListValue;
[FieldOffset(0)]
public MPVByteArray ByteArrayValue;
[FieldOffset(8)]
public MPVFormat Format;
}
To send commands I have to sent it a NodeList (in array or map/dictionary form, I'm using array here so the keys value is unused)
[StructLayout(LayoutKind.Explicit, Size = 24)]
public struct MPVNodeList
{
[FieldOffset(0)]
public int Num;
[FieldOffset(8)]
public IntPtr Nodes;
[FieldOffset(16)]
public IntPtr Keys;
}
[StructLayout(LayoutKind.Explicit, Size = 24)]
public struct MPVNodeList
{
[FieldOffset(0)]
public int Num;
[FieldOffset(8)]
public IntPtr Nodes;
[FieldOffset(16)]
public IntPtr Keys;
}
I'm calling it method via:
[LibraryImport("libmpv-2", EntryPoint = "mpv_command_node", StringMarshalling = StringMarshalling.Utf8)]
public static extern MPVError MPVCommandNode(MPVHandle ctx, ref MPVNode args, out MPVNode result);

public void Test()
{
var loadNode = new MPVNode()
{
Format = MPVFormat.String,
StringValue = Marshal.StringToCoTaskMemUTF8("loadfile\0")
};
var dataNode = new MPVNode()
{
Format = MPVFormat.String,
StringValue = Marshal.StringToCoTaskMemUTF8("<Path to a video file for now>\0")
};
var arr = new[] { loadNode, dataNode };
var ptr = Marshal.AllocCoTaskMem(Marshal.SizeOf<MPVNode>() * arr.Length);
for (int i = 0; i < arr.Length; i++)
Marshal.StructureToPtr(arr[i], ptr + i * Marshal.SizeOf<MPVNode>(), false);

var arrayNode = new MPVNode()
{
Format = MPVFormat.NodeArray,
NodeListValue = new MPVNodeList()
{
Num = 2,
Nodes = ptr
}
};
Interop.MPVCommandNode(_handle, ref arrayNode, out var result);
}
[LibraryImport("libmpv-2", EntryPoint = "mpv_command_node", StringMarshalling = StringMarshalling.Utf8)]
public static extern MPVError MPVCommandNode(MPVHandle ctx, ref MPVNode args, out MPVNode result);

public void Test()
{
var loadNode = new MPVNode()
{
Format = MPVFormat.String,
StringValue = Marshal.StringToCoTaskMemUTF8("loadfile\0")
};
var dataNode = new MPVNode()
{
Format = MPVFormat.String,
StringValue = Marshal.StringToCoTaskMemUTF8("<Path to a video file for now>\0")
};
var arr = new[] { loadNode, dataNode };
var ptr = Marshal.AllocCoTaskMem(Marshal.SizeOf<MPVNode>() * arr.Length);
for (int i = 0; i < arr.Length; i++)
Marshal.StructureToPtr(arr[i], ptr + i * Marshal.SizeOf<MPVNode>(), false);

var arrayNode = new MPVNode()
{
Format = MPVFormat.NodeArray,
NodeListValue = new MPVNodeList()
{
Num = 2,
Nodes = ptr
}
};
Interop.MPVCommandNode(_handle, ref arrayNode, out var result);
}
The struct in the header file looks like this: https://github.com/mpv-player/mpv/blob/ce7997649816e4d6c05071fbd4ecac0557120720/libmpv/client.h#L750 And the method is here: https://github.com/mpv-player/mpv/blob/ce7997649816e4d6c05071fbd4ecac0557120720/libmpv/client.h#L930 I noticed that the Format value in arrayNode changes when NodeListValue is set, so I believe some value has the wrong size and data in the struct gets overwritten? And thats probably what breaks it, I'd assume something is wrong with my struct, but I just cant seem to find what, I looked at other (C#) libraries but they either implement it the same as me afaik or just skip over that method Should NodeListValue just be an IntPtr or something like that? My results vary between getting Invalid Parameter as error from the lib or outright corrupt memory exceptions
18 replies