catel / catel.fody Goto Github PK
View Code? Open in Web Editor NEWCatel.Fody
License: MIT License
Catel.Fody
License: MIT License
For a repro, see https://github.com/byrialsen/CatelTest
The reason is that CompilerGenerated attribute is not found for WinRT compilations. This causes the generated OnPropertyChanged not to be marked as compiler generated. For the next property that requires auto-change notifications, the method will be ignored because it's not compiler generated (non-compiler generated methods are untouched to prevent unwanted side-effects).
Spoke to @SimonCropp :
well it does a few things for u
but it is optional
Sounds like a great candidate for 3.1.
public static void SetIsToolTipsEnabled(this DataGridSettings settings, bool isToolTipsEnabled, DataGrid dataGrid)
{
Argument.IsNotNull(() => settings);
var rowToolTipExtension = dataGrid.Extensions.FirstOrDefault(x => x is RowToolTipsExtension) as RowToolTipsExtension;
if (rowToolTipExtension == null)
{
return;
}
rowToolTipExtension.EnableToolTips = isToolTipsEnabled;
}
Platform:
.NET version:
Valid IL
Invalid IL
By default the properties are public, but this might hinder assemblies with obfuscation. By allowing this to be customized (should still default to public).
Property name could be:
"GeneratedPropertyDataAccessibility" (default is Public)
ViewModel
Catel.Core 6.0.1
Catel.Fody 4.9.0
Windows 11
Here is test code:
// Simple model class
public class TestModel : ObservableObject
{
private int _coutner;
public object Property { get; set; }
private void OnPropertyChanged()
{
_coutner++;
Debug.WriteLine($"Property changed: {Property} {_coutner}");
}
}
// ViewModel
public class MyDerivedViewModel : ViewModelBase
{
[Model]
public TestModel Model { get; set; }
[ViewModelToModel]
public object Property { get; set; }
public MyDerivedViewModel()
{
Model = new TestModel();
Model.Property = "test";
}
}
We have TestModel object and a ViewModel that uses it. ViewModel exposes the property from the TestModel object by using the attribute [ViewModelToModel].
after changing the property function OnPropertyChanged() should be called, one time.
OnPropertyChanged() is called twice. And output from creating MyDerivedViewModel is:
Property changed: test 1
Property changed: test 2
If instead of " Model.Property = "test";" we will use the code Property = "test"; OnPropertyChanged is called once
IF IT IS A NEW FEATURE REQUEST, INCLUDE THIS PART:
If it is an auto property, weaving should be good.
[ViewModelToModel(nameof(Source), nameof(Name), Mode = ViewModelToModelMode.OneWay)]
public override string DisplayName { get; }
It can work when the above code exists.
Platform: Windows
.NET version: 452
I think the NuGet package is bad.
.NetStandard 1.0 is implemented in NET45 and higher.
https://docs.microsoft.com/en-gb/dotnet/standard/net-standard
Originally coming from here: Fody/Fody#312
It's caused when a combination of this is used:
public bool ShowErrors { get; set; } = true;
Initially created via Catel/Catel#835
in VS 2015 we can write PropertyName{get;}
and init property in ctor.
// ViewModel try Exception
[Model]
[Expose("Name")]
public AnyType PropertyName{get;}
// this is OK
[Model]
[Expose("Name")]
public AnyType PropertyName{get;set;}
change the way calculated properties are weaved to short-circuit using nested ifs
currently ,
Weaving readonly properties will place multiple IF statements in OnPropertyChanged
like so :
if (e.PropertyName.Equals("X"))
{
base.RaisePropertyChanged("Y");
}
if (e.PropertyName.Equals("Z"))
{
base.RaisePropertyChanged("Y");
}
if (e.PropertyName.Equals("H"))
{
base.RaisePropertyChanged("B");
}
if (e.PropertyName.Equals("A"))
{
base.RaisePropertyChanged("C");
}
make the method short-circuit if it finds a suitable match, e.g.
if (e.PropertyName.Equals("X"))
{
base.RaisePropertyChanged("Y");
}
else if (e.PropertyName.Equals("Z"))
{
base.RaisePropertyChanged("Y");
}
else if (e.PropertyName.Equals("H"))
{
base.RaisePropertyChanged("B");
}
else if (e.PropertyName.Equals("A"))
{
base.RaisePropertyChanged("C");
}
This way it won't have to check every possible property name when it finds it early
Can anyone please help me how to use Costura.Fody to package LevelDB.Standard ? Got this error System.TypeInitializationException: ""LevelDB.LevelDBInterop" This is the Demo code I made for reference. matjazbravc/Embedded-SQLite-Demo#1
ths very much
Init only properties are not being weaved, causing this code to have runtime issues:
[Model]
[Expose(nameof(MyModel.SubProperty))]
public MyModel ModelProperty { get; }
Since the property does not get weaved, the Expose will not be handled either and causing runtime issues.
The solution is to always weaver such properties when decorated with the Model attribute.
What component is this issue occurring in?
Catel/Fody
Latest Prerelease as advised.
Mostly W10 (I am not sure if we have users on W7)
No Fody errors
The error still pops when making changes in the project and then building it again.
Rerunning build after this will make it launch without issues.
During Github build this issue is maybe a bit clearer to see :
https://github.com/WolvenKit/Wolvenkit/runs/1914026534#step:6:1094
As of Fody 3.2.5 the strategy to lookup weavers has changed:
https://github.com/Fody/Fody/wiki/AddinSearchPaths
The legacy lookup will be no longer supported in the next versions of Fody, so this weaver needs to add the props file to the NuGet package to be usable with future Fody versions.
PCL is now obsolete.
Catel/Fody
Custom build from latest release in the case of orchestra (Mahapps + fluent, instead of one or the other) otherwise standard latest release.
All the OS's
Press green button once to build and run the debug.
Need to press green button twice always.
Hi Geert,
I just have updated Catel.Fody from v2.14.0 to v2.17.0 (Fody from v1.29.4 to v2.1.0) and got this error:
[...]
2: Fody/Catel: Finished 'Catel' in 1867ms
2: Fody: Adding weaving info
2: Fody: Finished in 1ms
2: Fody: Writing assembly to 'D:_git\K3PO\src\K3PO.Core\obj\x64\Debug\K3PO.Core.dll'.
2: Error (0,0): Fody: An unhandled exception occurred:
Exception:
Value does not fall within the expected range.
StackTrace:
at Mono.Cecil.Pdb.ISymUnmanagedWriter2.DefineLocalVariable2(String name, Int32 attributes, Int32 sigToken, Int32 addrKind, Int32 addr1, Int32 addr2, Int32 addr3, Int32 startOffset, Int32 endOffset)
at Mono.Cecil.Pdb.NativePdbWriter.DefineScope(ScopeDebugInformation scope, MethodDebugInformation info, MetadataToken& import_parent)
at Mono.Cecil.Pdb.NativePdbWriter.Write(MethodDebugInformation info)
at Mono.Cecil.Cil.CodeWriter.WriteResolvedMethodBody(MethodDefinition method)
at Mono.Cecil.Cil.CodeWriter.WriteMethodBody(MethodDefinition method)
at Mono.Cecil.MetadataBuilder.AddMethod(MethodDefinition method)
at Mono.Cecil.MetadataBuilder.AddMethods(TypeDefinition type)
at Mono.Cecil.MetadataBuilder.AddType(TypeDefinition type)
at Mono.Cecil.MetadataBuilder.AddTypes()
at Mono.Cecil.MetadataBuilder.BuildTypes()
at Mono.Cecil.MetadataBuilder.BuildModule()
at Mono.Cecil.MetadataBuilder.BuildMetadata()
at Mono.Cecil.ModuleWriter.<>c.b__2_0(MetadataBuilder builder, MetadataReader _)
at Mono.Cecil.ModuleDefinition.Read[TItem,TRet](TItem item, Func3 read) at Mono.Cecil.ModuleWriter.BuildMetadata(ModuleDefinition module, MetadataBuilder metadata) at Mono.Cecil.ModuleWriter.Write(ModuleDefinition module, Disposable
1 stream, WriterParameters parameters)
at Mono.Cecil.ModuleWriter.WriteModule(ModuleDefinition module, Disposable`1 stream, WriterParameters parameters)
at Mono.Cecil.ModuleDefinition.Write(String fileName, WriterParameters parameters)
at InnerWeaver.WriteModule() in C:\projects\fody\FodyIsolated\ModuleWriter.cs:line 18
at InnerWeaver.Execute() in C:\projects\fody\FodyIsolated\InnerWeaver.cs:line 89
Source:
Mono.Cecil.Pdb
TargetSite:
Void DefineLocalVariable2(System.String, Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32)
2: Fody: Finished Fody 2525ms.
I am in the beginning of finding the problem but I do not really know how und where to look.
But if I remove Catel from FodyWeavers it builds and no error occurs.
I also found you issue Fody/Fody#312 but this one is different.
Perhaps you have any idea on how I can get more info on this?
Fody Version 2 is out and you will need to do an update for your addin to be usable with it
Specifically:
Please ping me if u need help
I had to disable this because the current implementation caused PE Verify issues. Will need to look into this with a fresh mind in the future.
Catel.Fody weaving properties
4.5.0
win 10
use the attached repro.
properties declared as virtual should also be included in OnPropertyChanged if they have been used in a calculation property.
only not virtual properties will be included in OnPropertyChanged
Argument and properties are not weaved for Catel itself. This weaver should generate an error incase Argument.IsNotNull(() => someArgument) is used.
Ignore argument weaving when method is decorated by this attribute.
Platform: VisualStudio 2013
.NET version: .NET4.5.2
As on the classes
We have an error :
Fody/Catel : The object reference is not defined ...
What component is this issue occurring in?
Catel.Fody
4.7.0
Reference should be found and property should be weaved.
Reference is not found. Repro can be found here: https://github.com/pascalgross/FodyNet6
What component is this issue occurring in?
Catel/Fody
4.7.0
VM.SetValue
of course) public class VM : ViewModelBase
{
[Model]
public Test Test { get; set; }
[ViewModelToModel]
public string Prop { get; set; }
public void SetValue(string a)
{
}
}
public class Test
{
public string Prop { get; set; }
}
It should generate right code
it generates gibberish:
[Model]
public Test Test
{
[CompilerGenerated]
get
{
return GetValue<Test>(TestProperty);
}
[CompilerGenerated]
set
{
//IL_000d: Expected O, but got I4
_ = TestProperty;
((ViewModelBase)(object)value).SetValue<!!0, !!1, !!2>((!!0)1);
}
}
[ViewModelToModel("", "")]
public string Prop
{
[CompilerGenerated]
get
{
return GetValue<string>(PropProperty);
}
[CompilerGenerated]
set
{
//IL_000d: Expected O, but got I4
_ = PropProperty;
((ViewModelBase)(object)value).SetValue<!!0, !!1, !!2>((!!0)1);
}
}
which finally leads to System.MissingMethodException: 'Method not found: 'Catel.Data.PropertyData Catel.MVVM.ViewModelBase.SetValue(!!0)'.'
with code
new VM().Test = new Test { Prop = "Whatever"};
Catel.Fody
Windows 10 20H2
Sample solution has been attached (WpfApp2.zip)
Property weaving should complete successfully as designed in release 4.5.0
Numerous exceptions are thrown:
1>MSBUILD : error : Fody/Catel: Type 'System.CodeDom.Compiler.GeneratedCodeAttribute' cannot be found, please report this bug
1>MSBUILD : error : Fody/Catel: Type 'System.Runtime.CompilerServices.CompilerGeneratedAttribute' cannot be found, please report this bug
1>MSBUILD : error : Fody/Catel: Type 'System.Diagnostics.DebuggerNonUserCodeAttribute' cannot be found, please report this bug
1>MSBUILD : error : Fody/Catel: Type 'System.ComponentModel.PropertyChangedEventArgs' cannot be found, please report this bug
1>MSBUILD : error : Fody/Catel: Type 'Void' cannot be found, please report this bug
1>MSBUILD : error : Fody/Catel: Failed to handle property 'PersonModel.BirthDate'
Rolling back to release 4.5.0 is the current workaround. It appears the issue may have been introduced as a side effect of #274 (or possibly #291)
Catel.Fody / Fody
Tested with
Catel.Core 5.12.9 + Catel.Fody v4.4.0.0 + Fody 6.2.4
Catel.Core 5.12.10 + Catel.Fody v4.4.0.0 + Fody 6.2.4
Catel.Core 5.12.10 + Catel.Fody v4.5.0.0 + Fody 6.2.4
Catel.Core 5.12.10 + Catel.Fody v4.5.0.0 + Fody 6.3.0
win 10, net472
2> Fody/Catel: MyModel - adding static constructor
2> Fody/Catel: MyModel - added static constructor
2> Fody/Catel: MyPair - adding GetValue call
2> Fody/Catel: MyPair - adding SetValue call
Property change
The build fails with a NullException
Fody/Catel: Object reference not set to an instance of an object. CatelFodyNullException
Having either the KeyValuePair (base class) created in the local assembly, or removing one of the interfaces of the base class resolves the issue..
Here is a simple reproduction (using the current latest versions of each library)
Is there a way to expose all member of a model without including each member with the [Expose()] attribute?
In a lot of cases, the imported module is static and a lot of stuff (like the compiler generated attributes) only have to be resolved / imported once.
Add attribute to suppress message
Method 'XXXX' matches automatic change method name but has parameters and will not be used as automatic change callback. Rename the method to remove this warning or remove parameters to use as automatic callback method.
fx I had class
class SomeBaseViewModel<T> : ViewModelBase
{
public T SelectedItem { get; set; }
protected virtual void OnSelectedItemChanged(T item) { }
[SuppressMessage("CodeQuality", "IDE0051:Remove unused private members", Justification = "Used by generator")]
private void OnSelectedItemChanged()
{
OnSelectedItemChanged(SelectedItem);
}
}
I would like to my build be silent
resolution:
add some code here
to not take method with some attribute into account
Hello. Apologies if this is not the right place to post this - I haven't found any place to get help.
I updated the NuGet packages for my project and now I get:
Fody: Fody (version 2.0.2.0) Executing
MSBUILD : error : Fody: The weaver assembly 'Catel.Fody, Version=2.15.0.0, Culture=neutral, PublicKeyToken=null' references an out of date version of Mono.Cecil.dll (cecilReference.Version). At least version 0.10 is expected. The weaver needs to add a NuGet reference to FodyCecil version 2.0.2.0.
... is this something I can fix on my end ? If so how? Thanks.
This code causes invalid IL:
protected override void UpdateCellContainer(Tile cellContainer, Cell cell)
{
Argument.IsNotNull(() => cell);
var border = (TiledBorder) cellContainer;
border.BackgroundColor = DataGridCellStyleColors.HeaderBackground;
}
A few allocations from the async methods can be removed.
Check out CheckForNullWithMultipleParametersWithoutContent
generated code.
I'm not sure if it's bug in Catel.Fody or Fody/Mono itself but I'm getting
BadImageFormatException: Próbowano załadować program w niepoprawnym formacie.
with code
namespace CatelFodyBug
{
using Catel.Fody;
using Catel.MVVM;
using System.Collections.Generic;
public class TestViewModel : ViewModelBase
{
[Model]
[Expose("ID")]
public Model Model { get; set; }
public static void Main(string[] args)
{
var vm = new TestViewModel();
}
}
public class Model : BaseModel<Model>
{
}
public class BaseModel<T> : EntityBaseWithID<int, T> where T: BaseModel<T>
{
}
public class EntityBaseWithID<T, S> where S : EntityBaseWithID<T, S>
{
public T ID { get; set; }
//this is why I'm using S
public override bool Equals(object other)
{
if (other is S n)
return n.ID.Equals(ID);
return false;
}
//irrelevant for this example
public override int GetHashCode()
{
var hashCode = 509650306;
hashCode = hashCode * -1521134295 + EqualityComparer<T>.Default.GetHashCode(ID);
hashCode = hashCode * -1521134295 + GetType().GetHashCode();
return hashCode;
}
}
}
obviously it's because generated code is wrong
public static readonly Catel.Data.PropertyData IDProperty = Catel.Data.ModelBase.RegisterProperty("ID", typeof(!0));
public !0 ID
{
get..
set..
}
seems like weaver can't resolve generic type
Instead of this:
public string ExistingProperty
{
get => _existingProperty;
set
{
_existingProperty = value;
RaisePropertyChanged(nameof(ExistingProperty));
}
}
into:
public string ExistingProperty
{
get => _existingProperty;
set
{
if (_existingProperty == value)
{
return;
}
_existingProperty = value;
RaisePropertyChanged(nameof(ExistingProperty));
}
}
ViewModel
Catel.MVVM 6.0.0-alpha1271
Catel.Fody 4.9.0
Windows 11
public class AppSettingsModel : ViewModelBase
{
public string SelectedThemeName { get; set; }
}
public class AppSettingsViewModel : ViewModelBase
{
[Model]
[Expose("SelectedThemeName")]
public AppSettingsModel AppSettings { get; set; }
public AppSettingsViewModel(AppSettingsModel appSettings)
{
AppSettings = appSettings;
}
private void OnSelectedThemeNameChanged()
{
// This method is called when AppSettings.SelectedThemeName have old value, not the current one
}
}
OnPropertyChanged should be called after property gets its new value.
OnPropertyChanged is called before the property value changes.
But if we get the value of property using dynamic object it will be correct. For example:
private void OnSelectedThemeNameChanged()
{
var oldValue = AppSettings.SelectedThemeName; // Old value
dynamic thisDynamic = this;
var theme = thisDynamic.SelectedThemeName; // Correct value.
}
Also if we expose property as below:
public class AppSettingsViewModel : ViewModelBase
{
[Model]
public AppSettingsModel AppSettings { get; set; }
[ViewModelToModel("AppSettings")]
public string SelectedThemeName { get; set; }
OnSelectedThemeNameChanged works correctly and has the current value.
Output:
Fody/Catel: Weaving auto log to specific log for 'Prefix.Controls.DataGrid'
Fody/Catel: Weaving auto log to specific log for 'Prefix.Controls.DataGrid'
Fody/Catel: Weaving auto log to specific log for 'Prefix.Controls.DataGrid'
Fody/Catel: Weaving auto log to specific log for 'Prefix.Controls.DataGrid'
Fody/Catel: Weaving auto log to specific log for 'Prefix.Controls.DataGrid'
Fody/Catel: Weaving auto log to specific log for 'Prefix.Controls.DataGrid'
Fody/Catel: Weaving auto log to specific log for 'Prefix.Controls.DataGrid'
Fody/Catel: Weaving auto log to specific log for 'Prefix.Controls.DataGrid'
Fody/Catel: Weaving auto log to specific log for 'Prefix.Controls.DataGrid'
Fody/Catel: Weaving auto log to specific log for 'Prefix.Controls.DataGrid'
Fody/Catel: Weaving auto log to specific log for 'Prefix.Controls.DataGrid'
Fody/Catel: Weaving auto log to specific log for 'Prefix.Controls.DataGrid'
Fody/Catel: Weaving auto log to specific log for 'Prefix.Controls.DataGrid'
Fody/Catel: Weaving auto log to specific log for 'Prefix.Controls.DataGrid'
Fody/Catel: Weaving auto log to specific log for 'Prefix.Controls.DataGrid'
Fody/Catel: Weaving auto log to specific log for 'Prefix.Controls.DataGrid'
Fody/Catel: Weaving auto log to specific log for 'Prefix.Controls.DataGrid'
Fody/Catel: Weaving auto log to specific log for 'Prefix.Controls.DataGrid'
Fody/Catel: Weaving auto log to specific log for 'Prefix.Controls.DataGrid'
Fody/Catel: Weaving auto log to specific log for 'Prefix.Controls.DataGrid'
Fody/Catel: Weaving auto log to specific log for 'Prefix.Controls.DataGrid'
Fody/Catel: Weaving auto log to specific log for 'Prefix.Controls.DataGrid'
Fody/Catel: Weaving auto log to specific log for 'Prefix.Controls.DataGrid'
Fody/Catel: Weaving auto log to specific log for 'Prefix.Controls.DataGrid'
1 time is sufficient ;-)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.