Jelle
Jelle
Explore posts from servers
CC#
Created by Jelle on 10/26/2023 in #help
❔ Distributing a CLI app (with .NET 8 Native AOT)
Hi guys, I built a CLI app that I'd like to distribute to the major platforms (windows, mac, linux). I'm trying to deal with building and distributing the app now that I have a version that I'm happy with, though I'm running into some issues.. I thought that with .NET 8's improved Native AOT, it'd be perfect to write my app targeting that. The app's use is that it makes it easy to create files and directories etc. so I honestly don't think a self-contained app is suitable for this use-case because how can I ask people to install 100MB+ for such a simple app (though maybe I can)? I'm using CommandLineParser for dealing with the argument parsing, and using DotNetYaml in also a relatively critical part of the app, both are throwing Native AOT warnings and Trim warnings. The app crashes when creating the Options object from CommandLineParser.Parser.ParseArguments .. (this doesn't happen when running it locally with the debugger attached, only when running the executable that was built with Native AOT with dotnet publish) The exception I'm currently hitting reads as follows:
InvalidOperationException: Type ****.CommandLine.Verbs.Create.CreateVerbOptions appears to be immutable, but no constructor found to accept values.
at CommandLine.Infrastructure.ReflectionHelper.CreateDefaultImmutableInstance(Type, Type[]) + 0x11c
at CommandLine.Core.InstanceBuilder.<>c__1`1.<Build>b__1_0(Func`1 f) + 0xf
at CommandLine.Core.InstanceBuilder.Build[T](Maybe`1, Func`3, IEnumerable`1, StringComparer, Boolean, CultureInfo, Boolean, Boolean, Boolean, IEnumerable`1) + 0x111
at CommandLine.Core.InstanceChooser.MatchVerb(Func`3, IEnumerable`1, Tuple`2, IEnumerable`1, StringComparer, Boolean, CultureInfo, Boolean, Boolean, Boolean, IEnumerable`1) + 0x19f
at CommandLine.Core.InstanceChooser.<Choose>g__choose|1_1(InstanceChooser.<>c__DisplayClass1_0&) + 0x114
at CommandLine.Core.InstanceChooser.Choose(Func`3, IEnumerable`1, IEnumerable`1, StringComparer, Boolean, CultureInfo, Boolean, Boolean, Boolean, IEnumerable`1) + 0x22b
at CommandLine.Parser.ParseArguments(IEnumerable`1, Type[]) + 0xcf
InvalidOperationException: Type ****.CommandLine.Verbs.Create.CreateVerbOptions appears to be immutable, but no constructor found to accept values.
at CommandLine.Infrastructure.ReflectionHelper.CreateDefaultImmutableInstance(Type, Type[]) + 0x11c
at CommandLine.Core.InstanceBuilder.<>c__1`1.<Build>b__1_0(Func`1 f) + 0xf
at CommandLine.Core.InstanceBuilder.Build[T](Maybe`1, Func`3, IEnumerable`1, StringComparer, Boolean, CultureInfo, Boolean, Boolean, Boolean, IEnumerable`1) + 0x111
at CommandLine.Core.InstanceChooser.MatchVerb(Func`3, IEnumerable`1, Tuple`2, IEnumerable`1, StringComparer, Boolean, CultureInfo, Boolean, Boolean, Boolean, IEnumerable`1) + 0x19f
at CommandLine.Core.InstanceChooser.<Choose>g__choose|1_1(InstanceChooser.<>c__DisplayClass1_0&) + 0x114
at CommandLine.Core.InstanceChooser.Choose(Func`3, IEnumerable`1, IEnumerable`1, StringComparer, Boolean, CultureInfo, Boolean, Boolean, Boolean, IEnumerable`1) + 0x22b
at CommandLine.Parser.ParseArguments(IEnumerable`1, Type[]) + 0xcf
It honestly seems quite a lot like it's coming from the Trim and/or AOT warnings when building the project. There's a few questions I'd like to ask: 1. Any advice on how I can deal with the exception? 2. Is it even worth it for me to dig into this issue? There may be plenty more even if I solve the one I'm currently encountering 3. Am I overreacting regarding size? I guess I could just release a self-contained app but like I mentioned above, I feel like the size is too big to justify the use-case 4. Any tips or examples on proper open-source CLI apps built on .net? I'm honestly quite lost especially regarding distributing them but I'm also starting to think building it on dotnet wasnt a great choice
4 replies
CC#
Created by Jelle on 10/16/2023 in #help
❔ HMAC encrypt a string
Hey guys I'm trying to HMAC encrypt a string but the resulting hash is being rejected by the server I want to use it on. It's returning 400 Bad Request: "Please provide a valid HMAC hash" I'm trying to achieve this: https://docs.novu.co/notification-center/client/react/get-started#enabling-hmac-encryption
import { createHmac } from "crypto";

const hmacHash = createHmac("sha256", process.env.NOVU_API_KEY)
.update(subscriberId)
.digest("hex");
import { createHmac } from "crypto";

const hmacHash = createHmac("sha256", process.env.NOVU_API_KEY)
.update(subscriberId)
.digest("hex");
With my code looking like this:
using var hmac = new HMACSHA256(Encoding.UTF8.GetBytes(apiKey));
var hash = hmac.ComputeHash(Encoding.UTF8.GetBytes(userId));
result.NotificationCenterHash = Convert.ToHexString(hash);
using var hmac = new HMACSHA256(Encoding.UTF8.GetBytes(apiKey));
var hash = hmac.ComputeHash(Encoding.UTF8.GetBytes(userId));
result.NotificationCenterHash = Convert.ToHexString(hash);
I'm wondering if I'm just doing it wrong or if there's something else perhaps.. I triple checked the values I'm using and they should be correct The hash that I output is 18A22B366AF133C8ADD62E471BB3F91984D12E495CD4EC33999DEE8B48722E39
16 replies
CC#
Created by Jelle on 9/28/2023 in #help
❔ Getting cross-platform directories for storing data
Hey guys, I'm writing a CLI app with .NET 8 and I'm looking into storing config and caches on the filesystem. I was wondering if there's some utility similar to this https://github.com/sindresorhus/env-paths#api that automatically picks the right path based on the OS and what the file is for?
6 replies