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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T15:01:02+00:00 2026-06-03T15:01:02+00:00

I’ve recently had quite a problem with a certain web method I’m using: void

  • 0

I’ve recently had quite a problem with a certain web method I’m using:

void CheckGfiHelpdesks(string ticket, GfiCheck[] newHelpdeskChecks, GfiCheck[] otherChecks)

I’ve been calling that method with this code:

List<GfiCheck> newFailedChecks = new List<GfiCheck>();

List<GfiCheck> otherFailedChecks = new List<GfiCheck>();

//do some work, create new GfiCheck items, fill the lists

Webclient.CheckGfiHelpdesks(Ticket, newFailedChecks.ToArray(), otherFailedChecks.ToArray());

newFailedChecks and otherFailedChecks are List. This has been working fine when the method was running on IIS as a SOAP service.

However, after I copied the exact same method into a WCF service, the call produced a “400 bad request” exception.

Eventually I figured out that .ToArray() was indeed the problem. This:

Webclient.CheckGfiHelpdesks(Ticket, newFailedChecks.ToArray<GfiCheck>(), otherFailedChecks.ToArray<GfiCheck>());

i.e. using the System.Linq.Enumerable.ToArray<T>() instead of System.Collections.Generic.List<T>.ToArray() finally solved the problem and the exception went away.

What is the explanation for this difference? An Array is an Array, but apparently not?

The exact Exception is:

System.ServiceModel.ProtocolException

The remote server returned an unexpected response: (400) Bad Request.

StackTrace:

Server stack trace:

at System.ServiceModel.Channels.HttpChannelUtilities.ValidateRequestReplyResponse(HttpWebRequest request, HttpWebResponse response, HttpChannelFactory factory, WebException responseException, ChannelBinding channelBinding)

at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)

at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)

at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout)

at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)

at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)

at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

>

Exception rethrown at [0]:

at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)

at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)

at MonitoringService.BL.CentronService.ICentronService.CheckGfiHelpdesks(String ticket, GfiCheck[] newHelpdeskChecks, GfiCheck[] otherChecks)

at MonitoringService.BL.CentronService.CentronServiceClient.CheckGfiHelpdesks(String ticket, GfiCheck[] newHelpdeskChecks, GfiCheck[] otherChecks) in C:\Users\sohrm\documents\visual studio 2010\Projects\MonitoringService\MonitoringService.BL\Service References\CentronService\Reference.cs:Zeile 5368.

at MonitoringService.BL.ConnectorBL.CheckHelpdesks(List`1 clients) in C:\Users\sohrm\documents\visual studio 2010\Projects\MonitoringService\MonitoringService.BL\ConnectorBL.cs:Zeile 120.

at MonitoringService.WinForm.MainForm.LoadChecks() in C:\Users\sohrm\documents\visual studio 2010\Projects\MonitoringService\MonitoringService.Client\MainForm.cs:Zeile 124.

at MonitoringService.WinForm.MainForm.btnLoad_Click(Object sender, EventArgs e) in C:\Users\sohrm\documents\visual studio 2010\Projects\MonitoringService\MonitoringService.Client\MainForm.cs:Zeile 114.

at System.Windows.Forms.Control.OnClick(EventArgs e)

at DevExpress.XtraEditors.BaseButton.OnClick(EventArgs e)

at DevExpress.XtraEditors.BaseButton.OnMouseUp(MouseEventArgs e)

at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)

at System.Windows.Forms.Control.WndProc(Message& m)

at DevExpress.Utils.Controls.ControlBase.WndProc(Message& m)

at DevExpress.XtraEditors.BaseControl.WndProc(Message& msg)

at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)

at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)

at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)

at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)

at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)

at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)

at System.Windows.Forms.Application.Run(Form mainForm)

at MonitoringService.WinForm.Program.Main() in C:\Users\sohrm\documents\visual studio 2010\Projects\MonitoringService\MonitoringService.Client\Program.cs:Zeile 22.

at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)

at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)

at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()

at System.Threading.ThreadHelper.ThreadStart_Context(Object state)

at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)

at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)

at System.Threading.ThreadHelper.ThreadStart()

  • 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-03T15:01:03+00:00Added an answer on June 3, 2026 at 3:01 pm

    There should not be difference between System.Collections.Generic.List<T>.ToArray() and System.Linq.Enumerable.ToArray<T>(). Lets see what happens inside:

    System.Collections.Generic.List<T> just creates new array and copies internal items array to it:

    public T[] ToArray()
    {
        T[] destinationArray = new T[this._size];
        Array.Copy(this._items, 0, destinationArray, 0, this._size);
        return destinationArray;
    }
    

    System.Linq.Enumerable cannot access internal items array of list, so it creates array via buffer:

    public static TSource[] ToArray<TSource>(this IEnumerable<TSource> source)
    {
        if (source == null)    
            throw Error.ArgumentNull("source");
    
        Buffer<TSource> buffer = new Buffer<TSource>(source);
        return buffer.ToArray();
    }
    

    What happens inside buffer? List<T> is a ICollection<T> thus it just calls CopyTo implementation of List<T>:

    internal Buffer(IEnumerable<TElement> source)
    {
       TElement[] array = null;
       ICollection<TElement> is2 = source as ICollection<TElement>;
       length = is2.Count;
       if (length > 0)
       {
           array = new TElement[length];
           // implemented as Array.Copy(this._items, 0, array, 0, this._size);
           is2.CopyTo(array, 0);
       }
    
       this.items = array;
       this.count = length;
    }
    

    As you can see, items are copied to new array via list’s method CopyTo, which do exactly same thing as inside ToArray method. But with System.Linq.Enumerable you have small drawback – after list items was copied to buffer, another array is created, and items from buffer copied to that array:

    internal TElement[] ToArray()
    {
       if (this.count == 0)        
           return new TElement[0];
    
       if (this.items.Length == this.count)        
           return this.items;
    
       TElement[] destinationArray = new TElement[this.count];
       Array.Copy(this.items, 0, destinationArray, 0, this.count);
       return destinationArray;
    }
    

    So, in both cases items from list copied to new array via same method Array.Copy. But in case of Enumerable this happens twice. I’d rather go with list’s ToArray implementation if I deal with List.

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

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
Specifically, suppose I start with the string string =hello \'i am \' me And
I am reading a book about Javascript and jQuery and using one of the
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

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.