Chik3r
Chik3r
CC#
Created by Chik3r on 4/18/2024 in #help
Waiting until struct is modified from another thread
No description
13 replies
CC#
Created by Chik3r on 9/7/2023 in #help
✅ Output TaskParameter is unrecognized
I'm trying to use CreateItem to add metadata to an item using batching, but it says that
error MSB4066: The attribute "TaskParameter" in element <Output> is unrecognized.
error MSB4066: The attribute "TaskParameter" in element <Output> is unrecognized.
Code that throws:
<CreateItem Include="@(_ResolvedProjectReferencePaths)" AdditionalMetadata="ProjectPath=%(OriginalItemSpec)" Condition="'@(_ResolvedProjectReferencePaths)'!=''">
<Output TaskParameter="Include" ItemName="TmpResolvedProjects" />
</CreateItem>
<CreateItem Include="@(_ResolvedProjectReferencePaths)" AdditionalMetadata="ProjectPath=%(OriginalItemSpec)" Condition="'@(_ResolvedProjectReferencePaths)'!=''">
<Output TaskParameter="Include" ItemName="TmpResolvedProjects" />
</CreateItem>
10 replies
CC#
Created by Chik3r on 8/21/2023 in #help
Custom MSBuild task fails to load `System.Runtime`
Hi, I'm making a custom MSBuild task that needs to load images and I was using ImageSharp for that. Before, I was targetting net6.0 and it worked when using dotnet build or Rider, but I now had to change to netstandard2.0 as I need to support VS and forgot that VS only likes netstandard. After I changed to netstandard2.0, a method using ImageSharp started to throw the following exception while running the task, but only from VS (it still works when using dotnet build):
Could not load file or assembly 'System.Runtime, Version=4.2.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
at tModLoader.BuildTools.ModFile.ContentConverters.ToRaw(Stream src, Stream dst)
at tModLoader.BuildTools.ModFile.ContentConverters.Convert(String& resourceName, FileStream src, MemoryStream dst) in C:\Users\ikerv\Documents\Programming\tModLoader\tModLoader\BuildTools\ModFile\ContentConverters.cs:line 15
at tModLoader.BuildTools.Tasks.PackageModFile.AddResource(TmodFile tmodFile, String resourcePath) in C:\Users\ikerv\Documents\Programming\tModLoader\tModLoader\BuildTools\Tasks\PackageModFile.cs:line 253
at tModLoader.BuildTools.Tasks.PackageModFile.<>c__DisplayClass42_0.<Run>b__1(String resource) in C:\Users\ikerv\Documents\Programming\tModLoader\tModLoader\BuildTools\Tasks\PackageModFile.cs:line 109
at System.Threading.Tasks.Parallel.<>c__DisplayClass17_0`1.<ForWorker>b__1()
at System.Threading.Tasks.Task.InnerInvokeWithArg(Task childTask)
at System.Threading.Tasks.Task.<>c__DisplayClass176_0.<ExecuteSelfReplicating>b__0(Object <p0>)
Could not load file or assembly 'System.Runtime, Version=4.2.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
at tModLoader.BuildTools.ModFile.ContentConverters.ToRaw(Stream src, Stream dst)
at tModLoader.BuildTools.ModFile.ContentConverters.Convert(String& resourceName, FileStream src, MemoryStream dst) in C:\Users\ikerv\Documents\Programming\tModLoader\tModLoader\BuildTools\ModFile\ContentConverters.cs:line 15
at tModLoader.BuildTools.Tasks.PackageModFile.AddResource(TmodFile tmodFile, String resourcePath) in C:\Users\ikerv\Documents\Programming\tModLoader\tModLoader\BuildTools\Tasks\PackageModFile.cs:line 253
at tModLoader.BuildTools.Tasks.PackageModFile.<>c__DisplayClass42_0.<Run>b__1(String resource) in C:\Users\ikerv\Documents\Programming\tModLoader\tModLoader\BuildTools\Tasks\PackageModFile.cs:line 109
at System.Threading.Tasks.Parallel.<>c__DisplayClass17_0`1.<ForWorker>b__1()
at System.Threading.Tasks.Task.InnerInvokeWithArg(Task childTask)
at System.Threading.Tasks.Task.<>c__DisplayClass176_0.<ExecuteSelfReplicating>b__0(Object <p0>)
10 replies
CC#
Created by Chik3r on 8/5/2023 in #help
❔ How to serialize certain null values with System.Text.Json
In System.Text.Json, if I have something like
record Item(string Text, int? Number);

List<Item> items = new();
JsonSerializerOptions options = new() {
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingDefault,
};
string json = JsonSerializer.Serialize(items, options);
record Item(string Text, int? Number);

List<Item> items = new();
JsonSerializerOptions options = new() {
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingDefault,
};
string json = JsonSerializer.Serialize(items, options);
I can serialize a list of items but ignore null values when writing, but what should I do if I want to serialize a single null value and ignore all others, something like this:
[
{
"Text": "Test"
},
{
"Text": "test 2",
"Number": 1
},
{
"Text": "test 3",
"Number": null, // Tell the serializer to only serialize this null value
}
]
[
{
"Text": "Test"
},
{
"Text": "test 2",
"Number": 1
},
{
"Text": "test 3",
"Number": null, // Tell the serializer to only serialize this null value
}
]
5 replies
CC#
Created by Chik3r on 7/5/2023 in #help
✅ Serializing XML with diacritics/accents
Hi, I'm trying to serialize a class to xml that contains some strings, some of which may contain an accent (example: genérica) or other latin characters (example: diseño). Currently I'm serializing it using the following code:
private static byte[] SerializeXml<T>(T data) {
using MemoryStream mem = new();
using StreamWriter writer = new(mem);
// XmlWriterSettings settings = new() {Encoding = Encoding.Default};

XmlSerializer serializer = new(typeof(T));
// using StringWriter writer = new Utf8StringWriter();
using XmlWriter xmlWriter = XmlWriter.Create(writer);
serializer.Serialize(xmlWriter, data);
return mem.ToArray();
}
private static byte[] SerializeXml<T>(T data) {
using MemoryStream mem = new();
using StreamWriter writer = new(mem);
// XmlWriterSettings settings = new() {Encoding = Encoding.Default};

XmlSerializer serializer = new(typeof(T));
// using StringWriter writer = new Utf8StringWriter();
using XmlWriter xmlWriter = XmlWriter.Create(writer);
serializer.Serialize(xmlWriter, data);
return mem.ToArray();
}
(I was previously trying to use a StringWriter but it also doesn't work) It ends up replacing the characters with ?? instead of writing the actual characters. The final XML needs to be formatted to UTF8 (and include encoding="utf-8" at the top of the xml), so I'm not able to use iso-8859-1 (but even when I tried to use it as an encoding it replaced characters with "??")
21 replies