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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T13:37:08+00:00 2026-05-11T13:37:08+00:00

Previously, I ran into a problem trying to share a type definition between my

  • 0

Previously, I ran into a problem trying to share a type definition between my ASMX webservice and my .aspx page (webclient)

Confused on C# Array of objects and implicit type conversion

As I understand the advice, the ‘problem’ this creates can be solved by copying the array of objects created in the client to a new array of objects as defined by the ASMX proxy class.

Being a rookie in C# I am still struggling with this simple task. Here are more parts of my code (the other fragments in the previous post remain unchanged):

… here is where I populate the ‘test data’ I want to pass to the web service:

// create an array of MetaData objects MetaData[] nvPairs = new MetaData[20];   // arbitrary length of 20 pairs  // create arbitrary MetaData objects in the array nvPairs[0] = new MetaData('Grant Number', '2577-9912'); nvPairs[1] = new MetaData('OPEAnalyst', 'Simpson'); 

… here I attempt a function to ‘copy’ from ‘real’ type defined in my TRIMBrokerUtil namespace (which I can’t use completely because of the proxy) to the proxy version of that type:

protected TRIMBrokerASMXProxy.ASMXProxy.MetaData[] CopyMetaData(     MetaData utilArray) {     TRIMBrokerASMXProxy.ASMXProxy.MetaData[] outArray =          new TRIMBrokerASMXProxy.ASMXProxy.MetaData[utilArray.Name.Length];     int i;     for (i = 0; i < utilArray.Name.Length; i++)     {         outArray[i].Name = utilArray.Name;         outArray[i].Value = utilArray.Value;     }     return outArray; } 

… and then here is where I try to call that function (compiler flags 2 errors on this line:

TRIMBrokerASMXProxy.ASMXProxy.MetaData[] kvData =      CopyMetaData(metaDataArray);  

Both of the compile errors below point to the same line:

Error 1 The best overloaded method match for ‘_Default.CopyMetaData(TRIMBrokerUtil.MetaData)’ has some invalid arguments

Error 2 Argument ‘1’: cannot convert from ‘TRIMBrokerUtil.MetaData[]’ to ‘TRIMBrokerUtil.MetaData’

Am I close ?

  • 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. 2026-05-11T13:37:09+00:00Added an answer on May 11, 2026 at 1:37 pm

    You’ve declared your parameter to be MetaData rather than MetaData[] – in other words it’s not an array. You’re then using utilArray.Name rather a lot, but it’s not clear why.

    I suspect you actually want:

    protected TRIMBrokerASMXProxy.ASMXProxy.MetaData[]     CopyMetaData(MetaData[] utilArray) {     TRIMBrokerASMXProxy.ASMXProxy.MetaData[] outArray =          new TRIMBrokerASMXProxy.ASMXProxy.MetaData[utilArray.Length];     for (int i = 0; i < utilArray.Length; i++)     {         outArray[i] = new TRIMBrokerASMXProxy.ASMXProxy.MetaData();         outArray[i].Name = utilArray[i].Name;         outArray[i].Value = utilArray[i].Value;     }     return outArray; } 

    By the way, you might want to consider a using directive to make this easier to read:

    using ProxyMetaData = TRIMBrokerASMXProxy.ASMXProxy.MetaData;  ...  protected ProxyMetaData[] CopyMetaData(MetaData[] utilArray) {     ProxyMetaData[] outArray = new ProxyMetaData[utilArray.Length];     for (int i = 0; i < utilArray.Length; i++)     {         outArray[i] = new ProxyMetaData();         outArray[i].Name = utilArray[i].Name;         outArray[i].Value = utilArray[i].Value;     }     return outArray; } 

    Another alternative is Array.ConvertAll:

    ProxyMetaData[] output = Array.ConvertAll(input,     metaData => new ProxyMetaData(metaData.Name, metaData.Value)); 

    If you’re not using C# 3 you can use an anonymous method for that. If ProxyMetaData doesn’t have an appropriate constructor and you are using C# 3, you can use an object initializer:

    ProxyMetaData[] output = Array.ConvertAll(input,     metaData => new ProxyMetaData { metaData.Name, metaData.Value }); 

    If you’re stuck with C# 2 and no appropriate constructor, then:

    ProxyMetaData[] output = Array.ConvertAll(input, delegate(MetaData metaData) {     ProxyMetaData proxy = new ProxyMetaData();     proxy.Name = metaData.Name;     proxy.Value = metaData.Value; }); 

    I think that’s covered all the bases 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 182k
  • Answers 182k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Developers do not have to work around the issue of… May 12, 2026 at 4:27 pm
  • Editorial Team
    Editorial Team added an answer How do you guys feel about this? Grab the original… May 12, 2026 at 4:27 pm
  • Editorial Team
    Editorial Team added an answer You could try: var myObserver = { observe: function(aSubject, aTopic,… May 12, 2026 at 4:27 pm

Related Questions

I have an application written in VB.NET that interacts with Excel via interop. I
While trying out an experimental UINavigationController-based iPhone application, I ran into a problem when
I ran into this problem at my old job, and now again at my
I'm writing a C parser using PLY, and recently ran into a problem. This

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.