Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8965283
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:46:28+00:00 2026-06-15T16:46:28+00:00

I have found following code to get all action from controller name. Type t

  • 0

I have found following code to get all action from controller name.

Type t = typeof(YourControllerType);
MethodInfo[] mi = t.GetMethods();
foreach (MethodInfo m in mi)
{
    if (m.IsPublic)
        if (typeof(ActionResult).IsAssignableFrom(m.ReturnParameter.ParameterType))
            methods = m.Name + Environment.NewLine + methods;
}

I want to make following code dynamic as function by passing controller name as follows:

 public string get_all_action(type ob)
        {
            string methods = "";
            Type t = typeof(ob);
            MethodInfo[] mi = t.GetMethods();

            foreach (MethodInfo m in mi)
            {
                if (m.IsPublic)
                    if (typeof(ActionResult).IsAssignableFrom(m.ReturnParameter.ParameterType))
                        methods = m.Name + Environment.NewLine + methods;
            }

            return methods;
        }

But I am confuse what type of parameter should passed to the function at definition and while calling the function.
I have following code to get all controller and pass controller name to get_all_action().

var asm = Assembly.GetExecutingAssembly();
            var controllerTypes = from d in asm.GetExportedTypes() where typeof(IController).IsAssignableFrom(d) select d;
            foreach(var val in controllerTypes)
            {                
               string actionname = get_all_action(val.Name);


            }

Here, val.Name is in string type therefore it throws exception:

Object reference not set to an instance of an object.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T16:46:29+00:00Added an answer on June 15, 2026 at 4:46 pm

    Your get_all_action method is expecting to receive a Type as the input parameter, whereas you’re attempting to call it with a String (i.e. the Type name) as the input parameter.

    The line here:

    string actionname = get_all_action(val.Name);
    

    should instead be:

    string actionname = get_all_action(val);
    

    And the first few lines of your get_all_action method should be changed to be:

    public string get_all_action(Type controllerType)
    {
        string methods = "";
        MethodInfo[] mi = controllerType.GetMethods();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

FINAL EDIT: After following the answer from Darin Dimitrov, I have found that the
I am stumped by the following code: <b><i>First name *</b></i> : <input type=text name='<?php
Hi all i've got the following code which will go off and get all
I have found the following piece of code which uses XmlHttpRequest to read JSON
On the MSDN, I have found following: public event EventHandler<MyEventArgs> SampleEvent; public void DemoEvent(string
I have found the following fragment in the Linux kernel (not the corresponding C
I have found the following command in AWK useful in Vim :'<,'>!awk '{ print
I have found the following expression which is intended to modify the id of
I have found the following resources on Balanced Matching for .net Regexes: http://weblogs.asp.net/whaggard/archive/2005/02/20/377025.aspx http://blogs.msdn.com/bclteam/archive/2005/03/15/396452.aspx
Reading a book I have found the following statement: (Object) Behaviors answer either of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.