Building main with Castle.Core 5.2.1 gives build errors (Possible null reference)
See #870
Error: /home/runner/work/NSubstitute/NSubstitute/src/NSubstitute/Proxies/CastleDynamicProxy/ProxyIdInterceptor.cs(28,29): error CS8602: Dereference of a possibly null reference. [/home/runner/work/NSubstitute/NSubstitute/src/NSubstitute/NSubstitute.csproj::TargetFramework=net8.0]
Error: /home/runner/work/NSubstitute/NSubstitute/src/NSubstitute/Proxies/CastleDynamicProxy/CastleInvocationMapper.cs(12,13): error CS8602: Dereference of a possibly null reference. [/home/runner/work/NSubstitute/NSubstitute/src/NSubstitute/NSubstitute.csproj::TargetFramework=net8.0]
Error: /home/runner/work/NSubstitute/NSubstitute/src/NSubstitute/Proxies/CastleDynamicProxy/CastleInvocationMapper.cs(27,72): error CS8603: Possible null reference return. [/home/runner/work/NSubstitute/NSubstitute/src/NSubstitute/NSubstitute.csproj::TargetFramework=net8.0]
Error: /home/runner/work/NSubstitute/NSubstitute/src/NSubstitute/Proxies/CastleDynamicProxy/CastleDynamicProxyFactory.cs(128,26): error CS8604: Possible null reference argument for parameter 'target' in 'object ProxyGenerator.CreateInterfaceProxyWithTarget(Type interfaceToProxy, Type[]? additionalInterfacesToProxy, object target, ProxyGenerationOptions options, params IInterceptor[] interceptors)'. [/home/runner/work/NSubstitute/NSubstitute/src/NSubstitute/NSubstitute.csproj::TargetFramework=net8.0]
See logs: https://github.com/nsubstitute/NSubstitute/actions/runs/13752672225/job/38455602274?pr=870
PS: There is a comment about Castle.Core 5.2 and NSubstitute, but that seems about something else. https://github.com/castleproject/Core/issues/684#issue-2498212992
I haven't tested NSubstitute locally with Castle.Core 5.2.1 yet. Maybe it isn't a runtime error with NSubstitute 5.3.0
I ran locally some tests (~600) without issues with Castle.Core 5.2.1 and NSubstitute 5.3.0. But be aware of the new bug: default interface implementations won't work anymore - see https://github.com/castleproject/Core/issues/684
Hi @304NotModified, like I already mentioned over in the Castle.Core issue, these build errors are probably a direct result of https://github.com/castleproject/Core/pull/668.
I've added the nullable reference type annotations based on a reasonably careful (IIRC) study of DynamicProxy's source code. However, they can still be misleading due to the fact that DynamicProxy e. g. has only one interface type to represent proxy invocations, yet there are 5 or so different proxy types... some of those may produce null references in invocation properties while others don't, so depending on the proxy type(s) you're using, you may never actually encounter null references but the interface still has to declare them as a possibility.
So I could imagine that in some cases you may safely ignore the nullability errors using the ! operator... but don't just take my word for it, do check your code carefully. :-)
@stakx could we have a fix or prerelease package of Castle.Core for this?
@304NotModified, I cannot look at your build errors right now. If you think that the DynamicProxy nullable reference type hints are incorrect, could you perhaps open an issue describing the suspected defect? Thanks.