C
C#15mo ago
nobody

❔ Runtime reflection on Asp .net core 7.0 missing

Hi, I am writing a generator which is used to generated api endpoints in a highly unified way. For that I need to be able to add data annotations to specific parameters. The Generator works fine, but when I add e.g the [FromBody] data annotation, it crashes with the following error: Could not load file or assembly 'Microsoft.AspNetCore.Mvc.Core, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified. And this is the code:
private static (string parameterWithTypes, string parametersWithoutTypes) GetMethodParameters(MethodInfo method)
{
var parametersWithTypes = method.GetParameters()
.Select(param =>
{
// Get all attributes for the parameter
var attributes = param.GetCustomAttributes(false)
.Select(attr => $"[{attr.GetType().FullName}]")
.Aggregate(string.Empty, (current, attrName) => current + attrName + " ");

return $"{attributes}{TypeHelper.GetFriendlyName(param.ParameterType)} {param.Name}";
});

var parametersWithoutTypes = method.GetParameters()
.Select(param => $"{param.Name}");

return (string.Join(", ", parametersWithTypes), string.Join(", ", parametersWithoutTypes));
}
private static (string parameterWithTypes, string parametersWithoutTypes) GetMethodParameters(MethodInfo method)
{
var parametersWithTypes = method.GetParameters()
.Select(param =>
{
// Get all attributes for the parameter
var attributes = param.GetCustomAttributes(false)
.Select(attr => $"[{attr.GetType().FullName}]")
.Aggregate(string.Empty, (current, attrName) => current + attrName + " ");

return $"{attributes}{TypeHelper.GetFriendlyName(param.ParameterType)} {param.Name}";
});

var parametersWithoutTypes = method.GetParameters()
.Select(param => $"{param.Name}");

return (string.Join(", ", parametersWithTypes), string.Join(", ", parametersWithoutTypes));
}
` This occurs when I retrieve the type of a AspNetCore data annotation. There is no nuget packaged which I could include in order to make the types known in my generator project. Any suggestions?
1 Reply
Accord
Accord15mo ago
Looks like nothing has happened here. I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server