ReactiveUI
ReactiveUI copied to clipboard
[Feature Request] Fody does not support property initializers (C# 6+) on generic classes
This is an odd one but is extremely easy to reproduce:
- Create a new project, i.e. a console app.
- Create a generic class derived from
ReactiveObject
. - Add a property with an auto-property initializer (a feature of C# 6) to the class.
- Decorate the property with the
[Reactive]
attribute. - Construct the class and run the code.
Here's the code:
// This class throws an exception
public class GenericFoo<T> : ReactiveObject
{
[Reactive] public object FooObj { get; set; } = new object();
}
// This class works fine
public class Foo : ReactiveObject
{
[Reactive] public object FooObj { get; set; } = new object();
}
You can construct the Foo
class but when ctoring the GenericFoo
you will get an exception. For example, running the code:
var f2 = new GenericFoo<object>();
Throws the following runtime exception:
System.MissingFieldException: 'Field not found: 'FodyBug.GenericFoo`1.<FooObj>k__BackingField'.'
Workaround: The workaround is not to use auto-property initializer and just initialize the property in ctor. This only happens in generic classes. This took me a few hours to figure out since I started with a regular class, made it generic and was suddenly getting the strange exception.
The .Net Core 3.1 console project to reproduce the issue: FodyBug.zip
Tested on: Windows 10 x64, Visual Studio 2019 v16.5.5, RxUI/Fody v11.4.1, .Net Core 3.1
Personal note It's kind of a strange notion, to use these initializers on Fody-ed properties in the first place, but it does work on non-generic classes which is pretty awesome actually. Purely based on that I'm guessing it can work just the same on generic classes which is why I labeled this as a bug.
Same behavior on my side. Very strange error message 'Common Language Runtime detected an invalid program'.
[Reactive] public decimal dummy{get;set;} =0m;
Hard to find, easy to reproduce.
Tested on: Windows 10 x64, Visual Studio 2019 v16.6.0, RxUI/Fody v11.4.1, .Net 4.8, Desktop
Btw. it is not limited to RxUI/Fody v11.4.1 I stopped testing downwards on v.11.3.1
This is currently being worked on and is fixed in a rewrite of the fody btw.
Hello, "rewrite of the fody"? You mean like upcoming versions?
Thanks
Yes. We are working to fix some of the internals of Fody. It should be coming in a near future release.
Is there a tracking issue on the progress over at Fody?
The fody is going into maintenance-only mode at the moment while we work on a new project which will replace the functionality in general. Keeping this open to track for the new project.
The fody is going into maintenance-only mode at the moment while we work on a new project which will replace the functionality in general. Keeping this open to track for the new project.
Hi, what is the new project called?
Any updates on the issue? Still present in the newest versions.
@Metadorius See https://github.com/reactiveui/ReactiveUI/issues/2416#issuecomment-957094991
@glennawatson I have seen that, and I asked with that in mind. There were no news on that new project in this issue which you said you will leave open to track and Fody is still being used, so you may treat my question as "what happened to that initiative". Thanks.
https://github.com/reactiveui/ReactiveObject.Generators Is a repo for the new generators. There's been some offers from the community to start coding but hasn't been started in. I've had too much real life lately to get started and hoping it'll clear up soon.
GitHub
Contribute to reactiveui/ReactiveObject.Generators development by creating an account on GitHub.
Thanks much for the response (and for the project(s) in general) and good luck with IRL stuff :)
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.