You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Unhandled exception. System.InvalidProgramException: Common Language Runtime detected an invalid program.
at Dummy.<>OnPropertyChanged(PropertyChangedEventArgs eventArgs)
at Dummy.set_Test(String value) in C:\Users\sewer\Desktop\Projects\DummyProjects\Fody.PropertyChanged.Net7\Fody.PropertyChanged.Net7\Program.cs:line 11
at Program.<Main>$(String[] args) in C:\Users\sewer\Desktop\Projects\DummyProjects\Fody.PropertyChanged.Net7\Fody.PropertyChanged.Net7\Program.cs:line 7
My guess based on the codegen is that Fody isn't boxing the value type, instead trying to pass it by reference; and earlier runtimes were able to tolerate that to some capacity; but the new one isn't.
I.e. There is nothing that resembles:
ldarg.0
ldobj // Copy Dummy by Ptr
box // Box the Dummy
Temporary Workaround
Manually add OnPropertyChanged to struct types that implement INotifyPropertyChanged such that .
Fody.PropertyChanged will then delegate the calls to your OnPropertyChanged and this should avoid the issue.
About
This is probably a relatively niche bug; usually consumers wouldn't use INotifyPropertyChanged with value types.
I'm not asking/expecting a fix (or any action etc. to be taking) I'm just reporting this to raise awareness and hopefully help someone out there who may run across this.
The text was updated successfully, but these errors were encountered:
Sewer56
changed the title
Invalid Codegen for Value Types which Breaks .NET 7
Invalid Codegen for Value Types (Breaks .NET 7)
Oct 12, 2022
This should definitely be fixed. I guess one possible "fix" would be to remove support for value types, but I think adding the box instruction would be a better solution as it would keep backwards compatibility.
Out of curiosity, why do you use INPC with value types?
Out of curiosity, why do you use INPC with value types?
Normally doing this wouldn't make much sense as boxing would be costly.
In my specific case, I had a collection of small objects (which itself grouped reference types, <4 registers in size) that would be more efficient to access in a sequential manner; so naturally I used a struct.
I used INPC because I was working with WPF and one of these objects had a caption which could be edited by the user. Normally this caption would be automatically filled so in most cases, it would not be edited; therefore sticking with value types logically made sense.
Describe the issue
Runtime changes in .NET 7 make the weaved code for the common use case (define
PropertyChanged
only) non-executable/invalid.Minimal Repro
Build with
net7.0
TFM to observe the issue.Stack Trace:
Problematic CodeGen:
My guess based on the codegen is that Fody isn't boxing the value type, instead trying to pass it by reference; and earlier runtimes were able to tolerate that to some capacity; but the new one isn't.
I.e. There is nothing that resembles:
Temporary Workaround
Manually add
OnPropertyChanged
to struct types that implementINotifyPropertyChanged
such that .Fody.PropertyChanged will then delegate the calls to your
OnPropertyChanged
and this should avoid the issue.About
This is probably a relatively niche bug; usually consumers wouldn't use
INotifyPropertyChanged
with value types.I'm not asking/expecting a fix (or any action etc. to be taking) I'm just reporting this to raise awareness and hopefully help someone out there who may run across this.
The text was updated successfully, but these errors were encountered: