dotnet / dotnet/wcf

Auto-generated client code may use incorrect type

Open
#5,412 6 comments 2 reactions 0 assignees View on GitHub
triaged
Dominant language
C#
Stars
1.8k
Forks
576
Avg merge
6d 9h
Merged PRs (30d)
2

Description

**Describe the bug**
When generating client implementation from https://www.onvif.org/ver10/advancedsecurity/wsdl/advancedsecurity.wsdl, the generator generates incorrect code. If you look at the following line:
https://github.com/jflevesque-genetec/wcf/blob/2d051c83b3f141ab6dddf51aeb4ce3477981e228/ClassLibrary1/Connected%20Services/ServiceReference1/Reference.cs#L8277
the type specified in the attribute is incorrect. It should have been `typeof(DNAttributeTypeAndValue[])`

**To Reproduce**
Sample: https://github.com/jflevesque-genetec/wcf

```
Callstacks:
System.ServiceModel.CommunicationException: There was an error in serializing body of message GetAllCertPathValidationPoliciesRequest: 'CodeGenError(IsNotAssignableFrom): Cannot convert source type [ServiceReference1.DNAttributeTypeAndValue[]] to target type [ServiceReference1.DNAttributeTypeAndValue].'. Please see InnerException for more details.
---> System.InvalidOperationException: CodeGenError(IsNotAssignableFrom): Cannot convert source type [ServiceReference1.DNAttributeTypeAndValue[]] to target type [ServiceReference1.DNAttributeTypeAndValue].
---> System.Xml.Serialization.CodeGeneratorConversionException: CodeGenError(IsNotAssignableFrom): Cannot convert source type [ServiceReference1.DNAttributeTypeAndValue[]] to target type [ServiceReference1.DNAttributeTypeAndValue].
at System.Xml.Serialization.CodeGenerator.InternalConvert(Type source, Type target, Boolean isAddress)
at System.Xml.Serialization.SourceInfo.InternalLoad(Type elementType, Boolean asAddress)
at System.Xml.Serialization.XmlSerializationWriterILGen.WriteElement(SourceInfo source, ElementAccessor element, String arrayName, Boolean writeAccessor)
at System.Xml.Serialization.XmlSerializationWriterILGen.WriteElements(SourceInfo source, String enumSource, ElementAccessor[] elements, TextAccessor text, ChoiceIdentifierAccessor choice, String arrayName, Boolean writeAccessors, Boolean isNullable)
at System.Xml.Serialization.XmlSerializationWriterILGen.WriteArrayItems(ElementAccessor[] elements, TextAccessor text, ChoiceIdentifierAccessor choice, TypeDesc arrayTypeDesc, String arrayName, String choiceName)
at System.Xml.Serialization.XmlSerializationWriterILGen.WriteElement(SourceInfo source, ElementAccessor element, String arrayName, Boolean writeAccessor)
at System.Xml.Serialization.XmlSerializationWriterILGen.WriteElements(SourceInfo source, String enumSource, ElementAccessor[] elements, TextAccessor text, ChoiceIdentifierAccessor choice, String arrayName, Boolean writeAccessors, Boolean isNullable)
at System.Xml.Serialization.XmlSerializationWriterILGen.WriteMember(SourceInfo source, String choiceSource, ElementAccessor[] elements, TextAccessor text, ChoiceIdentifierAccessor choice, TypeDesc memberTypeDesc, Boolean writeAccessors)
at System.Xml.Serialization.XmlSerializationWriterILGen.WriteStructMethod(StructMapping mapping)
at System.Xml.Serialization.XmlSerializationILGen.GenerateReferencedMethods()
at System.Xml.Serialization.XmlSerializationWriterILGen.GenerateEnd()
at System.Xml.Serialization.TempAssembly.GenerateRefEmitAssembly(XmlMapping[] xmlMappings, Type[] types)
at System.Xml.Serialization.TempAssembly..ctor(XmlMapping[] xmlMappings, Type[] types, String defaultNamespace, String location)
--- End of inner exception stack trace ---
at System.Xml.Serialization.TempAssembly..ctor(XmlMapping[] xmlMappings, Type[] types, String defaultNamespace, String location)
at System.Xml.Serialization.XmlSerializer.GetSerializersFromCache(XmlMapping[] mappings, Type type)
at System.Xml.Serialization.XmlSerializer.FromMappings(XmlMapping[] mappings, Type type)
at System.ServiceModel.Description.XmlSerializerHelper.FromMappingsViaReflection(XmlMapping[] mappings, Type type)
at System.ServiceModel.Description.XmlSerializerHelper.FromMappings(XmlMapping[] mappings, Type type)
at System.ServiceModel.Description.XmlSerializerOperationBehavior.Reflector.SerializerGenerationContext.CreateSerializersFromMappings(XmlMapping[] mappings, Type type)
at System.ServiceModel.Description.XmlSerializerOperationBehavior.Reflector.SerializerGenerationContext.GenerateSerializers()
at System.ServiceModel.Description.XmlSerializerOperationBehavior.Reflector.SerializerGenerationContext.GetSerializer(Int32 handle)
at System.ServiceModel.Description.XmlSerializerOperationBehavior.Reflector.SerializerStub.GetSerializer()
at System.ServiceModel.Description.XmlSerializerOperationBehavior.Reflector.MessageInfo.get_BodySerializer()
at System.ServiceModel.Dispatcher.XmlSerializerOperationFormatter.SerializeBody(XmlDictionaryWriter writer, MessageVersion version, String action, MessageDescription messageDescription, Object returnValue, Object[] parameters, Boolean isRequest)
--- End of inner exception stack trace ---
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.b__0(IAsyncResult asyncResult)
--- End of stack trace from previous location ---
at ClassLibrary1.Class1.<>c__DisplayClass0_0.<b__0>d.MoveNext() in C:\Genetec\github\wcf\ClassLibrary1\Class1.cs:line 37
--- End of stack trace from previous location ---
at FluentAssertions.Specialized.AsyncFunctionAssertions`2.NotThrowAsync(String because, Object[] becauseArgs).
at FluentAssertions.Execution.XUnit2TestFramework.Throw(String message)
at FluentAssertions.Execution.TestFrameworkProvider.Throw(String message)
at FluentAssertions.Execution.DefaultAssertionStrategy.HandleFailure(String message)
at FluentAssertions.Execution.AssertionScope.FailWith(Func`1 failReasonFunc)
at FluentAssertions.Execution.AssertionScope.FailWith(Func`1 failReasonFunc)
at FluentAssertions.Execution.AssertionScope.FailWith(String message, Object[] args)
at FluentAssertions.Specialized.DelegateAssertionsBase`2.NotThrowInternal(Exception exception, String because, Object[] becauseArgs)
at FluentAssertions.Specialized.AsyncFunctionAssertions`2.NotThrowAsync(String because, Object[] becauseArgs)
at ClassLibrary1.Class1.Test() in C:\Genetec\github\wcf\ClassLibrary1\Class1.cs:line 39
at Xunit.Sdk.TestInvoker`1.<>c__DisplayClass48_0.<b__1>d.MoveNext() in /_/src/xunit.execution/Sdk/Frameworks/Runners/TestInvoker.cs:line 285
--- End of stack trace from previous location ---
at Xunit.Sdk.ExecutionTimer.AggregateAsync(Func`1 asyncAction) in /_/src/xunit.execution/Sdk/Frameworks/ExecutionTimer.cs:line 48
at Xunit.Sdk.ExceptionAggregator.RunAsync(Func`1 code) in /_/src/xunit.core/Sdk/ExceptionAggregator.cs:line 90
```

WSDL: https://www.onvif.org/ver10/advancedsecurity/wsdl/advancedsecurity.wsdl

**Expected behavior**
Auto-generated code to work out of the box.

**Additional context**
To reproduce, simply run the Test method in Class1.cs

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.