© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
1 reply
florent

❔ 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.
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?
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

❔ ASP.NET to .net Core
C#CC# / help
3y ago
asp.net 7 core mvc Roles not working.
C#CC# / help
2y ago
ASP.NET CORE MVC VS ASP.NET CORE WEB API
C#CC# / help
17mo ago