-
Notifications
You must be signed in to change notification settings - Fork 8
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
[Solution] Nullable attributes are not discovered in WPF projects #11
Comments
Hey, sorry to hear that you are having this issue. I've done some testing/browsing and can reproduce it locally (Project Download Here - open It seems that the issue arises from the way WPF projects are compiled. There are some GitHub issues which may provide more insights into why the problem occurs:
To summarize the issue: During the build, WPF creates a temporary project (for compiling XAML, I believe). In this temporary project, the NuGet packages are not imported, hence the build error that the attributes could not be found. This problem also affects other source code only packages similar to Nullable. Unfortunately I am currently unsure how this might be fixed. Maybe there's a chance to develop a workaround, but ultimately, the issue should be fixed at the root, i.e. in the WPF build process. Nontheless, I don't want to leave you hanging - maybe there are other ways to solve your problem until a real solution arrives for this issue. Here are some suggestions:
If you (or anyone else) has any ideas how the problem can be worked around from the perspective of the Nullable package, feel free to share your ideas! |
(Thanks for your answer. Will look into those!) |
So, I tried approach 1, and… they have a similar issue (which sounds… more fixable?):
It looks like someone else already discovered that: tunnelvisionlabs/ReferenceAssemblyAnnotator#81 2 seems… not fun. I might be able to live with 3. But now I'm tempted by the additional features in the project mentioned in 1… |
Alright, thanks for testing! I'm not sure about the CS0122 being more fixable. On first sight, the only solution seems to be to make the attributes public, but that should never be done, because it will quickly lead to naming conflicts when another referencing project also declares these attributes. Hence why they are declared as internal. (The only exception where public attributes are okay-ish is a project which is not published - there you have full control over it.)
I totally recommend using ReferenceAssemblyAnnotator instead of Nullable then! It is indeed an awesome project. If they cannot fix the CS0122 error which you posted above, you might even be able to combine ReferenceAssemblyAnnotator with Option 3 above, i.e. you could manually create the NullableAttributes.cs file in your project to have access to the attributes and disable RAA's attribute generation in your cs project: |
Yeah, makes sense to me. This is the one I ran into, but I think I want the "IDE" approach for my use case. They did figure out a fix, which appears to work for me (once I explicitly set |
Check out microsoft/CsWin32#7 for a discussion of this and how the latest .NET SDK fixed their bug so Nullable should Just Work going forward. |
That sounds amazing! I’ll close this as resolved then and make a mental note to document this in the README so that it is immediately clear to WPF users! |
I have a relatively complex solution with lots of legacy stuff, but I did manage to modernize some of the assemblies to the Sdk style and
PackageReference
instead ofpackages.config
. I can add your NuGet package and then write code like this, in .NET Framework 4.7.2:This looks great during design-time builds. But when I actually do a full build, I get an error that the attributes can't be found:
I've tried both a regular reference like so:
And the adjusted one from the README:
I think the
…**wpftmp**.csproj
portion may be a clue. However, with a test project that also contains WPF, I wasn't able to reproduce the issue.The text was updated successfully, but these errors were encountered: