Arch Leaders
Arch Leaders
CC#
Created by Arch Leaders on 6/28/2024 in #help
Restrict register endpoint using ASP.NET Core Identity
I'm using ASP.NET Core Identity as my authentication flow in a simple Web API. However, because the register/login/etc endpoints are automatically created, I can't restrict any of the endpoints like I usually would. Is there a way to configure the default requirements (claims) for any one of the auto-generated endpoints? For example, I don't want /register to be public, I would like it to require an Admin claim. Is this possible?
14 replies
CC#
Created by Arch Leaders on 1/11/2024 in #help
Best way to uniquely hash an array of undefined length?
I need to recursively hash a tree of arrays/dicts, is there a preferred/best way to hash the values quickly? Essentially I need to cache equality, the idea being to hash every array in the tree once and lookup the object pointer, otherwise I'd have to generate the hash many times when comparing the arrays. If there's a better way to achieve that entirely, I'm open to that too.
7 replies
CC#
Created by Arch Leaders on 6/13/2023 in #help
Load DLL at runtime with shared dependency
Hello, I'm currently attempting to make an extension loader for my application, however I'm having issues loading the assembly at runtime because a dependency is already loaded in the running assembly. This is my current setup: - ExtensionManager.Core - this is a class library that contains the interfaces for the extension and service manager class. - ExtensionManager - this is a CLI project that loads the extension DLL and registers it to a common interface (from ExtensionManager.Core). - SampleExtension - this is a class library the implements the extension interfaces in ExtensionManager.Core and is loaded at runtime. Inside the ExtensionManager I attempt to load the SampleExtension.dll and get the type that implements IServiceExtension from ExtensionManager.Core, however doing so throws the following exception:
Unable to load one or more of the requested types.
Method 'RegisterExtension' in type 'SampleExtension.SampleExtension' from assembly 'SampleExtension, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' does not have an implementation.
Unable to load one or more of the requested types.
Method 'RegisterExtension' in type 'SampleExtension.SampleExtension' from assembly 'SampleExtension, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' does not have an implementation.
Is there a way to tell the SampleExtension DLL to use the loaded ExtensionManager.Core instead of loading a new one? I'm fairly new to this sort of thing, so any help is appreciated.
2 replies
CC#
Created by Arch Leaders on 1/10/2023 in #help
❔ ✅ AES - Padding is invalid and cannot be removed
I am attempting to quickly encrypt a set of files using AES, but I'm getting the above error when decrypting. I'm not sure if it's encryption or decryption that's wrong, but I've tried and googled everything I can think of, but nothing seems to works. Can anyone tell me what's wrong with this code: (also tried reading one-byte at a time, but with the same results)
28 replies
CC#
Created by Arch Leaders on 11/16/2022 in #help
❔ Embed and Self-Extract C++ DLL in a CSharp Library
Hello, I'm trying to embed a C++ DLL into my C# library to allow for single file publishing without distributing the C++ DLL along side the final application. (That is, any application using this library) I also don't want to require an initialize function to extract the C++ DLL, which could be forgotten and is a bit annoying for users. Is there a way either extract the DLLs when the parent application starts or else, a way to have them self-extract automatically at runtime?
2 replies
CC#
Created by Arch Leaders on 11/5/2022 in #help
Use static functions in runtime code (rosyln)
Hello, I'm trying to import a static class (using static namespace.class) into rosyln executing code (await CSharpScript.EvaluateAsync(code)). In this example, the function Query is a static function in the running assembly.
// Normal math functions
int value = 15 + 45 * 34;

// Reference an equation in the history panel
int reference = Query("001");

// Return the final solution
return value + reference;
// Normal math functions
int value = 15 + 45 * 34;

// Reference an equation in the history panel
int reference = Query("001");

// Return the final solution
return value + reference;
namespace MathNotationTool.Extensions
{
public static class CodeExt
{
public static decimal Query(string entry)
{
return ViewModel.Calculator.ViewModel.History.Where(x => x.Name == entry).FirstOrDefault()?.Value ?? 0;
}
}
}
namespace MathNotationTool.Extensions
{
public static class CodeExt
{
public static decimal Query(string entry)
{
return ViewModel.Calculator.ViewModel.History.Where(x => x.Name == entry).FirstOrDefault()?.Value ?? 0;
}
}
}
Currently I'm setting the default code options in the startup function:
ScriptOptions.Default.WithReferences(typeof(App).Assembly).WithImports("MathNotationTool.Extensions.CodeExt");
ScriptOptions.Default.WithReferences(typeof(App).Assembly).WithImports("MathNotationTool.Extensions.CodeExt");
But this doesn't seem to work. The function isn't recognized, and importing the namespace in the executing code fails in the same way (namespace/assembly not found). Is there a way to import a static class into the memory-runtime?
2 replies
CC#
Created by Arch Leaders on 10/21/2022 in #help
byte[] does not equal a matching byte[], but the hex values match.
I have two byte arrays, one is 4 bytes long containing a known sequence, the other is file data. I am attempting to locate the 4-byte sequence in the file data by checking every four bytes in the file data, and using indexing to get the four bytes. Here's the code:
byte[] data = File.ReadAllBytes(fileName);
byte[] header = new byte[] { 0x4B, 0x54, 0x53, 0x52 };
int pos = 0;
for (int i = 4; i < data.Length; i += 4) {
#if DEBUG
Debug.WriteLine(Convert.ToHexString(data[pos..i]));
bool isTrue = Convert.ToHexString(data[pos..i]) == Convert.ToHexString(header); // this is true
bool isFalse = data[pos..i] == header; // this is false
#endif
if (data[pos..i] == header) {
break;
}
pos += 4;
}
byte[] data = File.ReadAllBytes(fileName);
byte[] header = new byte[] { 0x4B, 0x54, 0x53, 0x52 };
int pos = 0;
for (int i = 4; i < data.Length; i += 4) {
#if DEBUG
Debug.WriteLine(Convert.ToHexString(data[pos..i]));
bool isTrue = Convert.ToHexString(data[pos..i]) == Convert.ToHexString(header); // this is true
bool isFalse = data[pos..i] == header; // this is false
#endif
if (data[pos..i] == header) {
break;
}
pos += 4;
}
Can anyone explain this behavior? And suggest how I can fix it? Thanks
21 replies
CC#
Created by Arch Leaders on 9/19/2022 in #help
Custom Class Serialization
Is it possible to use a custom JSON serializer on a class? For example, I have a class with a few properties (Member), and another class with the class "Member" as a child property. I want the JSON serializer (Microsoft's version, System.Texts.Json) to serialize the entire Member class as just a string. Anyone know how this is done/if it can be done? Thanks.
class Report
{
string Name { get; set; }
string Id { get; set; }
Member Member { get; set; }
}

class Member
{
string Name {get; set; }
string Id {get; set; }

void CustomSerializer()
{
return Id;
}
}
class Report
{
string Name { get; set; }
string Id { get; set; }
Member Member { get; set; }
}

class Member
{
string Name {get; set; }
string Id {get; set; }

void CustomSerializer()
{
return Id;
}
}
{
"Report": {
"Name": "Anything",
"Id": "9124",
"Member": "1832"
}
}
{
"Report": {
"Name": "Anything",
"Id": "9124",
"Member": "1832"
}
}
5 replies