n8ta
n8ta
CC#
Created by n8ta on 2/21/2024 in #help
How to run a target when any of a set of input files has changed?
I'm trying to build a large project that msbuild does not understand via a <Target> with the inputs parameter as a list of all source files in that project and outputs as the single file the build produces. However, even when I change a file in the Inputs of the <Target> the target is not re-run. There is not a 1-1 mapping between inputs and outputs.
<Target Name="CustomJsBuildLocal" Inputs="@(JsInputFiles)" Outputs="@(JSOutputFiles)">
<Message Importance="High" Text="Building" />
<Exec ConsoleToMsBuild="true" Command="some kinda slow command based on input fules" WorkingDirectory="$(BuildFolder)">
<Output TaskParameter="ConsoleOutput" PropertyName="OutputOfExec" />
</Exec>
</Target>
<Target Name="CustomJsBuildLocal" Inputs="@(JsInputFiles)" Outputs="@(JSOutputFiles)">
<Message Importance="High" Text="Building" />
<Exec ConsoleToMsBuild="true" Command="some kinda slow command based on input fules" WorkingDirectory="$(BuildFolder)">
<Output TaskParameter="ConsoleOutput" PropertyName="OutputOfExec" />
</Exec>
</Target>
19 replies
CC#
Created by n8ta on 12/14/2023 in #help
✅ How does this code call System.Text.StringBuilder.ToString?
public bool PersistSettings()
{
bool succeeded = false;

try
{
lock (thisLock)
{
if (!hasChanges)
{
return true;
}

BackupSettingsFile();

using (StreamWriter writer = new StreamWriter(settingsFile))
{
writer.Write(JsonConvert.SerializeObject(settings));
}

hasChanges = false;
succeeded = true;
}
}
catch (Exception e)
{
RestoreSettingsFile();
}

return succeeded;
}
public bool PersistSettings()
{
bool succeeded = false;

try
{
lock (thisLock)
{
if (!hasChanges)
{
return true;
}

BackupSettingsFile();

using (StreamWriter writer = new StreamWriter(settingsFile))
{
writer.Write(JsonConvert.SerializeObject(settings));
}

hasChanges = false;
succeeded = true;
}
}
catch (Exception e)
{
RestoreSettingsFile();
}

return succeeded;
}
I've grabbed stacks of my program at runtime and I can see it in the PersistSettings method and then above that on the stack is System.Text.StringBuilder.ToString. Can anyone tell where that method could be inserted by the compiler?
7 replies
CC#
Created by n8ta on 10/18/2023 in #help
❔ ENV var dump collection not working on some machines
I'm using these env vars to collect dumps from my .net core macOS app (docs: https://learn.microsoft.com/en-us/dotnet/core/diagnostics/collect-dumps-crash) DOTNET_CreateDumpVerboseDiagnostics=1 DOTNET_CreateDumpLogToFile=/var/tmp/dotnet.log COMPlus_DbgEnableMiniDump=1 COMPlus_CreateDumpDiagnostics=1 COMPlus_EnableCrashReport=1 COMPlus_EnableDumpOnSigTerm=1 This works locally on an arm device and an intel device. I see /var/tmp/dotnet.log show up with coredump diagnostics and I see coredumps in TMPDIR. However when I run it in an azure devops pipeline no coredumps are created and the coredump log only contains 0003bf7f TickFrequency: 1000000 ticks per ms 0003bf7f PAGE_SIZE 4096 I'm not sure how to debug this further since I cannot ssh into my ADO pipeline agent. Anyone have any suggestions on next steps?
2 replies
CC#
Created by n8ta on 8/13/2023 in #help
❔ No atomic appends to file in .NET core?
I've used this snippet before to do atomic appends to a file https://stackoverflow.com/questions/1862309/how-can-i-do-an-atomic-write-append-in-c-or-how-do-i-get-files-opened-with-the but it seems that this no longer works in .NET core. I found this attempt to fix https://github.com/dotnet/runtime/pull/55465 which was not merged and this proposal https://github.com/dotnet/runtime/issues/53432#issuecomment-902478772. Is there any other way to accomplish atomic appends? I only really need macos support but it seems like cross plat isn't too much to ask (:
5 replies
CC#
Created by n8ta on 7/12/2023 in #help
Specifying framework version of dependency manually in SDK style project
I am updating an old project to the SDK style and I have a reference that looked like
<Reference Include="Package, Version=1.2.3.4, Culture=neutral>
<HintPath>$(EnlistmentRoot)\packages\Package\lib\net45\Package.dll</HintPath>
</Reference>
<Reference Include="Package, Version=1.2.3.4, Culture=neutral>
<HintPath>$(EnlistmentRoot)\packages\Package\lib\net45\Package.dll</HintPath>
</Reference>
After moving to SDK style I had
<PackageReference Include="Package" Version="1.2.3.4" />
<PackageReference Include="Package" Version="1.2.3.4" />
Which caused the build system to select the net46 version of the package not the net45 which turns out to be important. How can I override that behavior? Going back to the <Reference seems to work but it'd be nice to use PackageReference if possible.
11 replies
CC#
Created by n8ta on 5/25/2023 in #help
❔ System.TypeLoadException
Having an issue where my native bindings project (using objective-sharpie) expects a class to exist in the Xamarin.Mac assembly but when it runs in some of my projects it hits: System.TypeLoadException : Could not resolve type with token 01000012 from typeref (expected class 'ObjCRuntime.ThrowHelper' in assembly 'Xamarin.Mac, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065') I built the my package on Xamarin 9.0.1.2 and the application is being built into an application w/ 9.0.1.5. Is this mismatch the problem? What else might be the issue?
7 replies
CC#
Created by n8ta on 5/17/2023 in #help
VS Mac bindgen error
I've used objective sharpie to generate a c# wrapper around an obj-c library following https://learn.microsoft.com/en-us/xamarin/cross-platform/macios/binding/objective-sharpie/ When I go to build my project with vs mac I receive this: error BI1042: bgen: Missing '[Field (LibraryName=value)]' for {0} (e.g."__Internal") as part of the _GenerateBindings target. What does this mean? There's no associated line number and I'm not clear on what this task does.
2 replies
CC#
Created by n8ta on 5/9/2023 in #help
❔ How to take a native crash [{0x7f803bba7228} + 0x3bd] + PDB/DLL and get a line number?
I have a native crash from a .net application on macOS that contains some managed code in the stack. 10 MyDll.MyClass.Myfunction (string,string) [{0x7f803bba7228} + 0x3bd] [/xyz/MyDll/MyClass.cs :: 378u] (0x14b362550 0x14b362c88) [0x7f8032105240 - MyApp.exe] [0x14b36290d] I have the DLL and PDB and I'd like to turn this into a line number. How can I do that?
20 replies
CC#
Created by n8ta on 1/20/2023 in #help
❔ Convert decimal without trailing 0s
My goal is to print decimal numbers with all available precision and without a trailing .0
decimal a = 123.0m;
decimal b = 123m;
Console.WriteLine(a.ToString()); // 123.0
Console.WriteLine(b.ToString()); // 123
Console.WriteLine(a.ToString() == b.ToString()); // false
decimal a = 123.0m;
decimal b = 123m;
Console.WriteLine(a.ToString()); // 123.0
Console.WriteLine(b.ToString()); // 123
Console.WriteLine(a.ToString() == b.ToString()); // false
I'd like 123.0 to convert to 123 not 123.0. How can I do this for the decimal type? I was somewhat surprised that 123.0 and 123 are converted into different values.
24 replies
CC#
Created by n8ta on 12/16/2022 in #help
❔ Binding redirects not being loaded despite config file being set
I have net48 package with a binding redirect from newtonsoft 0->13 to 13.0.0.0
<?xml version="1.0" encoding="utf-8"?>
<configuration>
...
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-13.0.0.0" newVersion="13.0.0.0" />
</dependentAssembly>
</assemblyBinding>
<!-- Use StarDefinitionsCanExceedAvailableSpace=true to avoid UI hangs on high-resolution monitors -->
<AppContextSwitchOverrides value="Switch.System.Windows.Controls.Grid.StarDefinitionsCanExceedAvailableSpace=true"/>
</runtime>
<userSettings>
</userSettings>
</configuration>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
...
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-13.0.0.0" newVersion="13.0.0.0" />
</dependentAssembly>
</assemblyBinding>
<!-- Use StarDefinitionsCanExceedAvailableSpace=true to avoid UI hangs on high-resolution monitors -->
<AppContextSwitchOverrides value="Switch.System.Windows.Controls.Grid.StarDefinitionsCanExceedAvailableSpace=true"/>
</runtime>
<userSettings>
</userSettings>
</configuration>
This redirect is not being used at runtime and I can confirm that with fusion++ https://pastebin.com/NVw4wxsc However if I debug and inspect what my config file path is var configFile = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile; It is correct and when I open it I see my redirect. How can I debug why my config file's binding redirect is not being parsed? This only happens when run as a test not when we run the normal app.
2 replies
CC#
Created by n8ta on 9/14/2022 in #help
Combine two Expression Func [Answered]
I have two Expression<Func<A,A>>. I want to combine them into a single Expression<Func<A,A>> that runs the output of the first through the second. How can I do that?
30 replies
CC#
Created by n8ta on 8/16/2022 in #help
[resolved] Cs equivalent of (0..10).map [Answered]
In rust I'd write smoething like (0..10).map( to iterate over a range of numbers. Obviously I can do it with a for loop but I'd prefer an IEnumerable that I can select on.
18 replies