question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Incorrect generated client, two-dimensional array generated in place of list (WCF Connected Services)

See original GitHub issue

Hacked WSDL: https://gist.github.com/Ravenheart/dc92c2023d3536798aca3e721f5a85ae

In relation to https://github.com/dotnet/wcf/issues/1269 I’ve had some help from the company that made the service and they created a special version that doesn’t have endless recursion possible. Now this new version is added successfully to a sample project BUT the actual generated code throws a runtime exception.

System.AggregateException: One or more errors occurred. (System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e is not assignable from System.String[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e.) ---> System.InvalidOperationException: System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e is not assignable from System.String[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e.
   at System.Runtime.AsyncResult.End[TAsyncResult](IAsyncResult result)
   at System.ServiceModel.Channels.ServiceChannel.SendAsyncResult.End(SendAsyncResult result)
   at System.ServiceModel.Channels.ServiceChannel.EndCall(String action, Object[] outs, IAsyncResult result)
   at System.ServiceModel.Channels.ServiceChannelProxy.TaskCreator.<>c__DisplayClass1_0.<CreateGenericTask>b__0(IAsyncResult asyncResult)
   --- End of inner exception stack trace ---
   at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
   at TestConsoleNETCore.Program.Main(String[] args) in D:\DEV\TestConsoleNETCore\src\TestConsoleNETCore\Program.cs:line 17
---> (Inner Exception #0) System.InvalidOperationException: System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e is not assignable from System.String[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e.
   at System.Runtime.AsyncResult.End[TAsyncResult](IAsyncResult result)
   at System.ServiceModel.Channels.ServiceChannel.SendAsyncResult.End(SendAsyncResult result)
   at System.ServiceModel.Channels.ServiceChannel.EndCall(String action, Object[] outs, IAsyncResult result)
   at System.ServiceModel.Channels.ServiceChannelProxy.TaskCreator.<>c__DisplayClass1_0.<CreateGenericTask>b__0(IAsyncResult asyncResult)<---

The error in question is related to complex types that may end up with properties like “public string[][] SomeProperty” and according to some googling around this is also a bug with .NET’s tooling (tested it with wsdl.exe, svcutil.exe and the new connected services util).

Generated client: https://gist.github.com/Ravenheart/b33e79eba6519088731804b11d8bb6bd

Usage:

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;

namespace TestConsoleNETCore
{
    public class Program
    {
        public static void Main(string[] args)
        {
            try
            {
                PISServiceWS.PISWebServiceClient client = new PISServiceWS.PISWebServiceClient();

                //exception here
                var res = client.vldContractAsync(new PISServiceWS.vldContractIn()
                {
                    Item = "8610166253",
                    ItemElementName = PISServiceWS.ItemChoiceType9.egn,

                    issueDate = new DateTime(2016, 6, 6),
                    issueDateSpecified = true,

                    practiceNo = "2211131508",
                    specCode = "01",
                    uin = "0500000012",
                }).Result;

                Console.WriteLine(res.vldContractOut.vld);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
    }
}

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:29 (9 by maintainers)

github_iconTop GitHub Comments

4reactions
huanwucommented, Jun 23, 2016

@Ravenheart The generated code for the two dimensional array tr is not correct. In XmlArrayItemAttribute, we need either use typeof(string[]) or add NestingLevel=1. We’ll look at the root cause.

To work around this issue now, you can edit the generated code and make the change yourself as below. [System.Xml.Serialization.XmlArrayAttribute(Order=1)] [System.Xml.Serialization.XmlArrayItemAttribute(“td”, typeof(string), IsNullable=false)] public string[][] tr {}

Either use [System.Xml.Serialization.XmlArrayItemAttribute(“td”, typeof(string[]), IsNullable=false)] Or [System.Xml.Serialization.XmlArrayItemAttribute(“td”, typeof(string), IsNullable=false, NestingLevel=1)]

3reactions
Ravenheartcommented, Jun 26, 2020

@eng-marani its been there since the early 2000s 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why does WCF return myObject[] instead of List<T> like I ...
I am returning a List from my WCF method. In my client code, it's return type shows as MyObject[]. I have to either...
Read more >
Service Connection List<T> vs Array bug
This method avoids VS from converting list to Array. We don't need to use VS to generate proxy classes to call WCF services....
Read more >
WCF the Manual Way… the Right Way
When I right-click on my project and choose "Add Service Reference" I can browse to the service address (Figure 1) or simply drop-down...
Read more >
Using WCF With .NET Core - The Seeley Coder
Recently I was going through the motions upgrading an ASP.NET Core 2.0 website to 2.2. Overall the process was fairly straightforward, ...
Read more >
ServiceModel Metadata Utility Tool (Svcutil.exe) - WCF
The ServiceModel Metadata Utility tool is used to generate service model code from metadata documents, and metadata documents from service ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found