-
Notifications
You must be signed in to change notification settings - Fork 263
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
Error mocking internal members of Trimmable assemblies on Android #834
Comments
Thanks for the report and repro @jamescrosswell. If this is being trimmed from the assembly then I'm not sure there is a lot we can do from the NSubstitute side? (Suggestions welcome! I'm not familiar with net8.0-android) |
Adding trimming support isn't trivial AFAIK. I'm tagging this as a feature request |
A colleague that does some work with this mentioned they used specific excludes (although in the context of linking not testing). They sent me these references:
Not sure if that helps at all but figured I pass them along. 🙇 |
I think that's probably the reality... especially given the dependency on DynamicProxy which, as it's name suggests, is all about dynamic code generation. The only solution that I can imagine is one that leverages Source Generators to create the mock objects, instead of using DynamicProxy. That would likely require a very different API for people to define the mocks though. |
Describe the bug
Tests that use NSubstitute to mock internal members of Trimmable assemblies fail when run on Android, with the
following error:
If we set
<IsTrimmable>false</IsTrimmable>
in the.csproj
file of the code being tested then the test pass.To Reproduce
I've provided a minimal reproducable example at:
The readme.md file in that repo describes how to run the tests using the included powershell script.
Expected behaviour
We'd like the tests to pass for assemblies marked with
IsTrimmable
. With the growth of frameworks like MAUI we're seeing more and more people wanting to trim their applications.Environment:
Additional context
We bumped into this in the device tests for the Sentry SDK for .NET. For the time being, I'll look at disabling trimming on the relevant assemblies for the purposes of running these device tests. Ideally we'd be able to run our tests against the same code we ship though and we ship with
<IsAotCompatible>true</IsAotCompatible>
(so implicitly<IsTrimmable>true</IsTrimmable>
).The text was updated successfully, but these errors were encountered: