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.
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?