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

Ref struct in scanned assembly results in app crash at startup, if sagas are present #7179

Closed
SimonCropp opened this issue Oct 17, 2024 · 6 comments · Fixed by #7187
Closed
Milestone

Comments

@SimonCropp
Copy link
Contributor

SimonCropp commented Oct 17, 2024

Describe the bug

since MakeGenericType is used without checking if the type constraints are met

image

Steps to reproduce

have a Ref struct in message scanning

NSB 9.2.2.0
.net: 8

Backported to

  • 9.1.2
  • 9.0.4
  • 8.2.4
  • 7.8.6
@SimonCropp SimonCropp added the Bug label Oct 17, 2024
@SimonCropp
Copy link
Contributor Author

it is a side effect of

transport.RouteToEndpoint(Assembly)

it doesn't seem to respect the message convention. so if u have any type in that assembly that conflicts with a type constraint it will blow up.

repo: https://github.com/SimonCropp/NSBGreedyRoutTo

@SimonCropp
Copy link
Contributor Author

stack:

System.Exception: Failed to evaluate Message convention. See inner exception for details.
 ---> System.ArgumentException: GenericArguments[0], 'My.Messages.RefStruct', on 'NServiceBus.IHandleTimeouts`1[T]' violates the constraint of type 'T'.
 ---> System.TypeLoadException: GenericArguments[0], 'My.Messages.RefStruct', on 'NServiceBus.IHandleTimeouts`1[T]' violates the constraint of type parameter 'T'.
   at System.RuntimeTypeHandle.Instantiate(RuntimeType inst)
   at System.RuntimeType.MakeGenericType(Type[] instantiation)
   --- End of inner exception stack trace ---
   at System.RuntimeType.ValidateGenericArguments(MemberInfo definition, RuntimeType[] genericArguments, Exception e)
   at System.RuntimeType.MakeGenericType(Type[] instantiation)
   at NServiceBus.Features.Sagas.IsTypeATimeoutHandledByAnySaga(Type type, IEnumerable`1 sagas) in /_/src/NServiceBus.Core/Sagas/Sagas.cs:line 107
   at NServiceBus.Features.Sagas.<>c__DisplayClass0_0.<.ctor>b__4(Type t) in /_/src/NServiceBus.Core/Sagas/Sagas.cs:line 25
   at NServiceBus.Conventions.<>c__DisplayClass2_0.<IsInSystemConventionList>b__0(Func`2 isSystemMessageAction) in /_/src/NServiceBus.Core/Conventions/Conventions.cs:line 90
   at System.Linq.Enumerable.Any[TSource](IEnumerable`1 source, Func`2 predicate)
   at NServiceBus.Conventions.IsInSystemConventionList(Type t) in /_/src/NServiceBus.Core/Conventions/Conventions.cs:line 90
   at NServiceBus.Conventions.<IsMessageType>b__1_0(RuntimeTypeHandle typeHandle) in /_/src/NServiceBus.Core/Conventions/Conventions.cs:line 37
   at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
   at NServiceBus.Conventions.ConventionCache.ApplyConvention(Type type, Func`2 action) in /_/src/NServiceBus.Core/Conventions/Conventions.cs:line 266
   at NServiceBus.Conventions.IsMessageType(Type t) in /_/src/NServiceBus.Core/Conventions/Conventions.cs:line 32
   --- End of inner exception stack trace ---
   at NServiceBus.Conventions.IsMessageType(Type t) in /_/src/NServiceBus.Core/Conventions/Conventions.cs:line 80
   at NServiceBus.AssemblyRouteSource.<>c__DisplayClass3_0.<GenerateRoutes>b__0(Type t) in /_/src/NServiceBus.Core/Routing/AssemblyRouteSource.cs:line 23
   at System.Linq.Enumerable.WhereSelectArrayIterator`2.ToArray()
   at NServiceBus.AssemblyRouteSource.GenerateRoutes(Conventions conventions) in /_/src/NServiceBus.Core/Routing/AssemblyRouteSource.cs:line 22
   at NServiceBus.Features.ConfiguredUnicastRoutes.Apply(UnicastRoutingTable unicastRoutingTable, Conventions conventions) in /_/src/NServiceBus.Core/Routing/ConfiguredUnicastRoutes.cs:line 23
   at NServiceBus.RoutingComponent.Initialize(Configuration configuration, Configuration receiveConfiguration, Conventions conventions, PipelineSettings pipelineSettings, Configuration hostingConfiguration, TransportSeam transportSeam) in /_/src/NServiceBus.Core/Routing/RoutingComponent.cs:line 36
   at NServiceBus.EndpointCreator.Configure() in /_/src/NServiceBus.Core/EndpointCreator.cs:line 86
   at NServiceBus.EndpointCreator.Create(EndpointConfiguration endpointConfiguration, IServiceCollection serviceCollection) in /_/src/NServiceBus.Core/EndpointCreator.cs:line 34
   at NServiceBus.Endpoint.Create(EndpointConfiguration configuration, CancellationToken cancellationToken) in /_/src/NServiceBus.Core/Endpoint.cs:line 24

@SimonCropp
Copy link
Contributor Author

@boblangley what was the outcome of the Triage?

@boblangley
Copy link
Member

We ranked it as a priority bug, but not critical. This means we have queued it for work with the other priority bugs and a team will take this on when one becomes available to work on it. I don't have an ETA, the team should say something on this issue when they start working on it.

@andreasohlund
Copy link
Member

Thanks @SimonCropp we are working on a fix for this #7187

@andreasohlund andreasohlund added this to the 9.2.3 milestone Oct 24, 2024
@SimonCropp
Copy link
Contributor Author

@andreasohlund thanks

@poornimanayar poornimanayar changed the title Ref struct in message scanning results in app crash at startup Ref struct in scanned assembly results in app crash at startup, if sagas are present Oct 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants