Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Complex nullable reference types cannot be used on the interface-based message types #5752

Closed
bording opened this issue Sep 10, 2020 · 5 comments · Fixed by #5997
Closed
Labels
Milestone

Comments

@bording
Copy link
Member

bording commented Sep 10, 2020

While #5488 fixed problems related to using nullable references with interface messages, it's been reported that we still have a problem.

Whenever the interface has a property that is a nullable array, it fails.

public interface MyMessage : IMessage
{
    object[]? Broken { get; set; }
}

On startup, the following exception is thrown:

System.InvalidCastException
  HResult=0x80004002
  Message=Unable to cast object of type 'System.Collections.ObjectModel.ReadOnlyCollection`1[System.Reflection.CustomAttributeTypedArgument]' to type 'System.Array'.
  Source=System.Private.CoreLib
  StackTrace:
   at System.Reflection.Emit.CustomAttributeBuilder.EmitValue(BinaryWriter writer, Type type, Object value) in /_/src/System.Private.CoreLib/src/System/Reflection/Emit/CustomAttributeBuilder.cs:line 456
   at System.Reflection.Emit.CustomAttributeBuilder.InitCustomAttributeBuilder(ConstructorInfo con, Object[] constructorArgs, PropertyInfo[] namedProperties, Object[] propertyValues, FieldInfo[] namedFields, Object[] fieldValues) in /_/src/System.Private.CoreLib/src/System/Reflection/Emit/CustomAttributeBuilder.cs:line 170
   at System.Reflection.Emit.CustomAttributeBuilder..ctor(ConstructorInfo con, Object[] constructorArgs, PropertyInfo[] namedProperties, Object[] propertyValues) in /_/src/System.Private.CoreLib/src/System/Reflection/Emit/CustomAttributeBuilder.cs:line 41
   at NServiceBus.ConcreteProxyCreator.AddCustomAttributeToProperty(CustomAttributeData attributeData, PropertyBuilder propBuilder) in /_/src/NServiceBus.Core/MessageInterfaces/MessageMapper/Reflection/ConcreteProxyCreator.cs:line 112
   at NServiceBus.ConcreteProxyCreator.CreateTypeFrom(Type type) in /_/src/NServiceBus.Core/MessageInterfaces/MessageMapper/Reflection/ConcreteProxyCreator.cs:line 45
   at NServiceBus.MessageInterfaces.MessageMapper.Reflection.MessageMapper.GenerateImplementationFor(Type interfaceType) in /_/src/NServiceBus.Core/MessageInterfaces/MessageMapper/Reflection/MessageMapper.cs:line 230
   at NServiceBus.MessageInterfaces.MessageMapper.Reflection.MessageMapper.InnerInitialize(Type t) in /_/src/NServiceBus.Core/MessageInterfaces/MessageMapper/Reflection/MessageMapper.cs:line 200
   at NServiceBus.MessageInterfaces.MessageMapper.Reflection.MessageMapper.InitType(Type t) in /_/src/NServiceBus.Core/MessageInterfaces/MessageMapper/Reflection/MessageMapper.cs:line 146
   at NServiceBus.MessageInterfaces.MessageMapper.Reflection.MessageMapper.Initialize(IEnumerable`1 types) in /_/src/NServiceBus.Core/MessageInterfaces/MessageMapper/Reflection/MessageMapper.cs:line 34
   at NServiceBus.SerializationFeature.Setup(FeatureConfigurationContext context) in /_/src/NServiceBus.Core/Serialization/SerializationFeature.cs:line 26
   at NServiceBus.Features.FeatureActivator.FeatureInfo.InitializeFrom(FeatureConfigurationContext featureConfigurationContext) in /_/src/NServiceBus.Core/Features/FeatureActivator.cs:line 237
   at NServiceBus.Features.FeatureActivator.ActivateFeature(FeatureInfo featureInfo, List`1 featuresToActivate, FeatureConfigurationContext featureConfigurationContext) in /_/src/NServiceBus.Core/Features/FeatureActivator.cs:line 194
   at NServiceBus.Features.FeatureActivator.SetupFeatures(FeatureConfigurationContext featureConfigurationContext) in /_/src/NServiceBus.Core/Features/FeatureActivator.cs:line 57
   at NServiceBus.FeatureComponent.Initalize(FeatureConfigurationContext featureConfigurationContext) in /_/src/NServiceBus.Core/Features/FeatureComponent.cs:line 29
   at NServiceBus.EndpointCreator.Initialize() in /_/src/NServiceBus.Core/EndpointCreator.cs:line 61
   at NServiceBus.EndpointCreator.Create(SettingsHolder settings, Configuration hostingConfiguration) in /_/src/NServiceBus.Core/EndpointCreator.cs:line 27
   at NServiceBus.HostCreator.<CreateWithInternallyManagedContainer>d__1.MoveNext() in /_/src/NServiceBus.Core/Hosting/HostCreator.cs:line 86
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() in /_/src/System.Private.CoreLib/shared/System/Runtime/ExceptionServices/ExceptionDispatchInfo.cs:line 63
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) in /_/src/System.Private.CoreLib/shared/System/Runtime/CompilerServices/TaskAwaiter.cs:line 180
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) in /_/src/System.Private.CoreLib/shared/System/Runtime/CompilerServices/TaskAwaiter.cs:line 151
   at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult() in /_/src/System.Private.CoreLib/shared/System/Runtime/CompilerServices/TaskAwaiter.cs:line 563
   at NServiceBus.Endpoint.<Start>d__1.MoveNext() in /_/src/NServiceBus.Core/Endpoint.cs:line 29
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() in /_/src/System.Private.CoreLib/shared/System/Runtime/ExceptionServices/ExceptionDispatchInfo.cs:line 63
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) in /_/src/System.Private.CoreLib/shared/System/Runtime/CompilerServices/TaskAwaiter.cs:line 180
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) in /_/src/System.Private.CoreLib/shared/System/Runtime/CompilerServices/TaskAwaiter.cs:line 151
   at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult() in /_/src/System.Private.CoreLib/shared/System/Runtime/CompilerServices/TaskAwaiter.cs:line 563
   at Program.<Main>d__0.MoveNext() in C:\Code\docs.particular.net\samples\rabbitmq\simple\Rabbit_5\Sample\Program.cs:line 19
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() in /_/src/System.Private.CoreLib/shared/System/Runtime/ExceptionServices/ExceptionDispatchInfo.cs:line 63
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) in /_/src/System.Private.CoreLib/shared/System/Runtime/CompilerServices/TaskAwaiter.cs:line 180
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) in /_/src/System.Private.CoreLib/shared/System/Runtime/CompilerServices/TaskAwaiter.cs:line 151
   at System.Runtime.CompilerServices.TaskAwaiter.GetResult() in /_/src/System.Private.CoreLib/shared/System/Runtime/CompilerServices/TaskAwaiter.cs:line 107
   at Program.<Main>()

  This exception was originally thrown at this call stack:
    System.Reflection.Emit.CustomAttributeBuilder.EmitValue(System.IO.BinaryWriter, System.Type, object) in CustomAttributeBuilder.cs
    System.Reflection.Emit.CustomAttributeBuilder.InitCustomAttributeBuilder(System.Reflection.ConstructorInfo, object[], System.Reflection.PropertyInfo[], object[], System.Reflection.FieldInfo[], object[]) in CustomAttributeBuilder.cs
    System.Reflection.Emit.CustomAttributeBuilder.CustomAttributeBuilder(System.Reflection.ConstructorInfo, object[], System.Reflection.PropertyInfo[], object[]) in CustomAttributeBuilder.cs
    NServiceBus.ConcreteProxyCreator.AddCustomAttributeToProperty(System.Reflection.CustomAttributeData, System.Reflection.Emit.PropertyBuilder) in ConcreteProxyCreator.cs
    NServiceBus.ConcreteProxyCreator.CreateTypeFrom(System.Type) in ConcreteProxyCreator.cs
    NServiceBus.MessageInterfaces.MessageMapper.Reflection.MessageMapper.GenerateImplementationFor(System.Type) in MessageMapper.cs
    NServiceBus.MessageInterfaces.MessageMapper.Reflection.MessageMapper.InnerInitialize(System.Type) in MessageMapper.cs
    NServiceBus.MessageInterfaces.MessageMapper.Reflection.MessageMapper.InitType(System.Type) in MessageMapper.cs
    NServiceBus.MessageInterfaces.MessageMapper.Reflection.MessageMapper.Initialize(System.Collections.Generic.IEnumerable<System.Type>) in MessageMapper.cs
    NServiceBus.SerializationFeature.Setup(NServiceBus.Features.FeatureConfigurationContext) in SerializationFeature.cs
    ...
    [Call Stack Truncated]
@robbaman
Copy link

robbaman commented Mar 9, 2021

To add to this, the error also seems to occur when the property is a list type:

List<ReserveerMagazijnVoorraadArtikelMessageData>? Artikelen { get; set; }

image

@dbelcham
Copy link
Contributor

dbelcham commented Mar 9, 2021

Thanks for the additional input @robbaman

@robbaman
Copy link

Ha! Yeah, it's one of those things that keeps messing with you. It turns out I had "thumbed up" this issue some months back and had forgotten. So now I spent yet another hour trying to figure out what was going on and preparing a new issue, only to find this existing issue once again... well at least I got to make a screenshot this time :)

@bording bording added the Bug label Mar 10, 2021
@SzymonPobiega SzymonPobiega changed the title Enabling C# 8 nullable references can still throw exception on interface messages Complex nullable reference types cannot be used on the interface-based message types Mar 29, 2021
@SzymonPobiega SzymonPobiega added this to the 7.4.5 milestone Mar 29, 2021
@SzymonPobiega
Copy link
Member

@robbaman this has been released in 7.4.6

@robbaman
Copy link

@SzymonPobiega Thanks a lot for looking into this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants