Skip to content

Building main with Castle.Core 5.2.1 gives build errors (Possible null reference) #871

New issue

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

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

Already on GitHub? # to your account

Open
304NotModified opened this issue Mar 9, 2025 · 3 comments

Comments

@304NotModified
Copy link
Contributor

304NotModified commented Mar 9, 2025

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. castleproject/Core#684 (comment)

@304NotModified 304NotModified changed the title Building with Castle.Core 5.2.1 gives build errors Building main with Castle.Core 5.2.1 gives build errors Mar 9, 2025
@304NotModified
Copy link
Contributor Author

304NotModified commented Mar 9, 2025

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

@304NotModified 304NotModified changed the title Building main with Castle.Core 5.2.1 gives build errors Building main with Castle.Core 5.2.1 gives build errors (Possible null reference) Mar 9, 2025
@304NotModified
Copy link
Contributor Author

304NotModified commented Mar 10, 2025

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 castleproject/Core#684

@stakx
Copy link

stakx commented Mar 10, 2025

Hi @304NotModified, like I already mentioned over in the Castle.Core issue, these build errors are probably a direct result of castleproject/Core#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. :-)

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

No branches or pull requests

2 participants