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 8481783
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T19:39:13+00:00 2026-06-10T19:39:13+00:00

I have an external function which has following syntax: public void Set<FieldType>( Field field,

  • 0

I have an external function which has following syntax:

public void Set<FieldType>(
    Field field,
FieldType value
) 

Field type can be some of primitive types like int, double, bool etc. and also can be generic list of these types, e.g. IList< int >

The problem is that I must pass exactly an IList< T > interface. If I pass any type which implements IList< T > interface the function throws InvalidOperationException Unsupported type: System.Collections.Generic.List`1[[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]

For example:

IList<int> list1 = new List<int>();
List<int> list2 = new List<int>();

Entity entity = new Entity();

//this works fine
entity.Set(field, list1);

//Here exception is throw
entity.Set(field, list2);

//works fine as well
entity.Set(field, list2 as IList<int>);

The issue that I get the list dynamically via reflection

var property = entityType.GetProperty(field.FieldName);
dynamic propertyValue = property.GetValue(myObject, null);

So, the propertyValue is List< T >, not a IList< T >, and when I pass this value to the external functions I see an exception.

Obviously, it is a bug of external function.

The only idea I have is to cast the propertyValue to IList< T >. But I don’t know T at the compile time.

So, I need to cast dynamically. I’ve got a generic list interface type like variable

var genericIListType = typeof (IList<>)
    .MakeGenericType(field.ValueType);

But I cannot find the way how to cast propertyValue to this type. I can find only examples how to cast object to other objects (e.g. using Activator.CreateInstance), but I need to cast to an interface.

Please give me advice how to achieve the goal.

  • 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-10T19:39:14+00:00Added an answer on June 10, 2026 at 7:39 pm

    You could wrap the external function:

    public void SetWrapper<T>(Field field, List<T> list) {
        entity.Set(field, (IList<T>)list);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a little dropdown menu similar <select> , which contolled from external js-function.
I have the following error: LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup
I have an external setting file which has some nodes holiding attribute values of
Is it possible to have a C++ template function which can access different fields
I have the following code in an external JS file (ie: test.js); which creates
I have the following script, which is in an external file called at the
I have the working code pasted below which has a function called FormatStatus() as
I have a really simple external css stylesheet that has the following : div.hideBox
I have the following code: typedef void VOID; int f(void); int g(VOID); which compiles
I am new to web development. I have an external JavaScript file which has

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.