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

  • Home
  • SEARCH
  • 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 562787
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T12:35:30+00:00 2026-05-13T12:35:30+00:00

I am getting an error when trying to use a Type parameter when specifying

  • 0

I am getting an error when trying to use a Type parameter when specifying the Type for a generic method.

Error: ‘JsonFilter.JsonDataType’ is a ‘property’ but is used like a ‘type’

public class JsonFilter : ActionFilterAttribute
{
    public Type JsonDataType { get; set; }
    public override void OnActionExecuting(ActionExecutingContext filterContext)
    {
        ...
        JavaScriptSerializer jss = new JavaScriptSerializer();
        var result = jss.Deserialize<JsonDataType>(inputContent);//Error here
        ...

New Code

...
JavaScriptSerializer jss = new JavaScriptSerializer();
MethodInfo method = jss.GetType()
               .GetMethod("Deserialize")
               .MakeGenericMethod(new Type[] { JsonDataType });
var result = method.Invoke(jss, new object[] { inputContent });
filterContext.ActionParameters[Param] = result;
...

Reflection saves the day. Thanks @Jason for the explanation that when type is specified as part of generic method ( <Typename> ), then it gets compiled into bytes. Whereas when as property, it can be any type, only determinable at runtime.

UPDATE

For this specific problem, the following code is more concise.

var o = new DataContractJsonSerializer(JsonDataType).ReadObject(
    filterContext.HttpContext.Request.InputStream);
filterContext.ActionParameters[Param] = o;
  • 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-05-13T12:35:30+00:00Added an answer on May 13, 2026 at 12:35 pm

    The error

    Error: ‘JsonFilter.JsonDataType‘ is a ‘property’ but is used like a ‘type’

    is telling you exactly the problem.

    var result = jss.Deserialize<JsonDataType>(inputContent);
    

    Here, you are trying to pass JsonDataType as a type parameter to the generic method JavaScriptSerializer.Deserialize<T>

    but here

    public Type JsonDataType { get; set; }
    

    you declared JsonDataType as a property of type Type, but not as a type. To use a generic method you need to pass a type parameter (or, in some cases, let the compiler infer one). For example

    var result = jss.Deserialize<string>(inputContent);
    

    would be correct usage as string is a type.

    Now, if you absolutely want to use the type that is represented by JsonDataType you can use reflection.

    MethodInfo generic = typeof(JavaScriptSerializer).GetMethod("Deserialize")
                                                     .GetGenericMethodDefinition();
    MethodInfo closed = generic.MakeGenericMethod(new [] { JsonDataType });
    closed.Invoke(jss, new object[] { inputContent });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use slime from CVS (2009-01-05) but keep getting this error: LOAD:
I am trying to use heroku and appear to be getting a Postgres error
I am getting this error when trying to run internet information services on a
I'm getting this error after trying to appendChild to an element that was just
All of a sudden I start getting this error while trying to open 2
I've updated my TortoiseSVN client and now I'm getting the error when trying to
I'm getting the following error when trying to run a JSP. I'm using Tomcat
I'm getting a 404 error when trying to run another web service on an
I'm getting the following error when trying to build my app using Team Foundation
I am getting the following error when trying to install Visual Studio 2005 on

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.