LPeter1997
LPeter1997
CC#
Created by LPeter1997 on 9/24/2024 in #help
Could not load file or assembly '...' with a weaved DLL
I have a DLL I have weaved with Mono.Cecil, called Draco.Compiler. The weaver adds an assembly reference to Draco.Coverage, as the compiler DLL will call out to functions of this. When I execute with dotnet exec Draco.Compiler.dll, I get the usual exception indicating a failure to locate the assembly:
System.IO.FileNotFoundException: Could not load file or assembly 'Draco.Coverage, Version=0.2.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.
Now opening up the weaved DLL with ILSpy, all looks good and ILSpy actually manages to locate the dependency assembly as it's in the exact same folder as the weaved DLL. I'm not sure if ILSpy has a different/simpler assembly location strategy or something, but is there any way I could debug why this assembly loading fails when running with dotnet exec?
4 replies
CC#
Created by LPeter1997 on 9/16/2024 in #help
Mono.Cecil weaver messed up branch targets
No description
5 replies
CC#
Created by LPeter1997 on 8/30/2023 in #help
❔ Concurrent-exclusive scheduling with prioritizing exclusive execution
First off: I'm aware of ConcurrentExclusiveSchedulerPair from TPL, sadly it's not applicable for us, because it doesn't have the scheduling behavior we need. We have a bunch of messages coming in a sequential channel, that we are processing. Some messages are marked as EXCLUSIVE, some are not. EXCLUSIVE messages must be processed exclusively, as in no other message processing can be done in parallel. If there are only non-exclusive messages to process, the processing of those can happen in parallel. Whenever an exclusive message comes in, no further messages can be processed (except the ones that are already started), this means that if a non-exclusive message slips in after, the processing of that can not be started (this is the major behavior difference we need from ConcurrentExclusiveSchedulerPair). Anyone knows of such a scheduler/mechanism implementation somewhere? I'm not too well-versed with parallel/scheduling code so if I don't have to, I wouldn't spend ages trying to make an efficient and decent impl for it.
7 replies
CC#
Created by LPeter1997 on 7/17/2023 in #help
❔ Avoid infinite recursion in STJ converters
There are so-so many cases where I only want to customize reading up a type in System.Text.Json, but I'd want the default behavior for writing. Currently I'm doing this to avoid SO:
public override void Write(Utf8JsonWriter writer, TInterface value, JsonSerializerOptions options)
{
// TODO: Ugly hack, can we avoid recursion in a nicer way?
// Remove this converter
var newOptions = new JsonSerializerOptions(options);
for (var i = options.Converters.Count - 1; i >= 0; --i)
{
if (options.Converters[i].GetType() == this.GetType()
|| options.Converters[i].GetType() == typeof(ModelInterfaceConverter))
{
newOptions.Converters.RemoveAt(i);
}
}

// Default behavior
JsonSerializer.Serialize(writer, value, newOptions);
}
public override void Write(Utf8JsonWriter writer, TInterface value, JsonSerializerOptions options)
{
// TODO: Ugly hack, can we avoid recursion in a nicer way?
// Remove this converter
var newOptions = new JsonSerializerOptions(options);
for (var i = options.Converters.Count - 1; i >= 0; --i)
{
if (options.Converters[i].GetType() == this.GetType()
|| options.Converters[i].GetType() == typeof(ModelInterfaceConverter))
{
newOptions.Converters.RemoveAt(i);
}
}

// Default behavior
JsonSerializer.Serialize(writer, value, newOptions);
}
This is janky as hell IMO, is there a better/nicer way? I've found no obvious answer to it.
28 replies
CC#
Created by LPeter1997 on 5/24/2023 in #help
❔ Decent terminal UI library or solution
I'm writing a terminal-based application that requires a TUI. I've tried Terminal.Gui but I've found it quite bad, littered with all sorts of problems and missing simple things it doesn't do at all. I don't need a complex system, I'm writing a terminal-based debugger, so I'd need a few scrollable text views arranged in some grid and the ability to highlight portions of the source text when a breakpoint is hit or a statement is stepped. Any recommendations?
35 replies
CC#
Created by LPeter1997 on 3/27/2023 in #help
❔ OneOf deserializer for Newtonsoft JSON
I have a lot of data-contracts generated from code, which utilizes OneOf<...> (https://github.com/mcintyre321/OneOf) quite a lot because of the provided schema. There are cases where some of the alternatives are primitives, like OneOf<Int32, String> or OneOf<Boolean, FullCapabilities>, but there are also cases where everything is some object, like OneOf<NotebookDocumentSyncOptions, NotebookDocumentSyncRegistrationOptions>. Important, I can't change the schema, so I can't introduce custom type-information fields. This is a schema given by VS Code I must follow. Writing the serializer part is easy enough:
public override void WriteJson(JsonWriter writer, object? value, JsonSerializer serializer)
{
if (value is null)
{
serializer.Serialize(writer, null);
return;
}
var oneOf = (IOneOf)value;
serializer.Serialize(writer, oneOf.Value);
}
public override void WriteJson(JsonWriter writer, object? value, JsonSerializer serializer)
{
if (value is null)
{
serializer.Serialize(writer, null);
return;
}
var oneOf = (IOneOf)value;
serializer.Serialize(writer, oneOf.Value);
}
Now writing the deserializer should be technically possible. One could go through the generic args of the type to be deserialized and find what properties definitely discriminate for a given alternative. Has this been written before for OneOf or any of its alternatives? If possible, I'd like to avoid writing my own, possibly buggy and slow version of this.
2 replies
CC#
Created by LPeter1997 on 3/13/2023 in #help
✅ Profiling BDN benchmarks
I have a benchmarking project set up with BDN. It would be really nice if I could just jump in with the profiler on one of these benchmarks, see hotspots, etc. I haven't found any way BDN exposes this, and I fear it's not something they support.
15 replies
CC#
Created by LPeter1997 on 2/20/2023 in #help
❔ ✅ Singleton, thread-safe logger with absolutely 0 runtime performance penalty when turned off
I've got an application that lazily discovers its state-space, as it needs it. Carrying through a logger object these state objects seems way too extensive (hence some singleton would be ideal instead of DI), as I'd only like to look at a few isolated cases, I really don't need logging all the time. When I do want to look at a run, I don't mind the performance-penalty, but I can't allow even an empty vcall wasted when I turn it off (99.9% of the time). Are there existing solutions for weird cases like this?
21 replies
CC#
Created by LPeter1997 on 1/11/2023 in #help
❔ Package the binaries of another project
We have two projects in a solution, A and B. We'd like B to ship the binaries of A when packaged (not referencing it as a standard library dependency). There are existing libs we have seen that ship binaries (https://github.com/valentiniliescu/GraphVizNet/blob/master/GraphVizNet/GraphVizNet.csproj#L25) so, that's not exactly the problem. Where we are stuck is forcing A to build when packaging B, and then retrieving the output path for the binaries of A.
16 replies
CC#
Created by LPeter1997 on 11/4/2022 in #help
Making two dictionary writes atomic in multithreaded context
I have two writes to two ConcurrentDictionarys, one after the other:
dict1[k1] = o;
dict2[k2] = o;
dict1[k1] = o;
dict2[k2] = o;
Importantly, they write the same value in two different dictionaries with two different keys, which is important. Problem is that methods read from one dictionary or the other (they don't really utilize both at once) and the sequence of these writes is not atomic, meaning I could get a state where dict1 contains o but dict2 does not, which is undesirable. Is there any more efficient way to deal with this outside of needing to define a lock for the two of them?
7 replies
CC#
Created by LPeter1997 on 11/1/2022 in #help
Build ref return with System.Linq.Expressions
I'm building a delegate with System.Linq.Expressions that needs to return a ref. Is this possible? Taking a ref is no problem, but I found no method in the Expression class that constructs a ref operator.
1 replies
CC#
Created by LPeter1997 on 10/30/2022 in #help
Speed up reflection-based comparison
We have a type that we have no access to. Not now, never. And we can't replace it. We have a couple of private fields in it that we need to compare inside two instances to determine if they are equivalent for our purposes. Now the thing is, the place where the comparisons happen is super performance-critical. Is there a way to build up and "compile" a comparison function like this at runtime purely from reflection info to speed this up?
43 replies
CC#
Created by LPeter1997 on 10/8/2022 in #help
A generic and efficient way to feed in text for a lexer or scanner
In the past I was lazy and always just shoved a string into my lexical analyzer as input, but what's the "ideal" way to read source text? It should be relatively efficient as the lexer observes each character. It should also support peeking forward without consumption. The thing is, source code can come from many different places, like a file, a console REPL as lines, edit diffs from a language client, ... I'd like some way to read tokens from essentially any source without paying for virtual calls for each character read or something.
21 replies
CC#
Created by LPeter1997 on 9/10/2022 in #help
Choosing a license for a software specification
We are writing a specification for a programming language and we'd like to pick a license for the specs (not the compiler). There are two major goals we want to achieve: * The specs should stay free forever * It should be impossible for anyone to close off the sources to the specification This almost yells GPL, but since we are targeting a platform where there is a huge potential for languages to interop, we don't want such an invasive license. If another compiler team wants to do anything related to something they have to read our specs for, they are technically doing derivative work, which forces GPL on them, which we'd like to avoid. While it's desirable to enforce same license when forking the specs itself, this case is wildly different and we wouldn't like to enforce that. What would be the recommendations for our situation?
43 replies