kswoll / ReactiveUI.Fody

C# Fody extension to generate RaisePropertyChange notifications for properties and ObservableAsPropertyHelper properties.
MIT License
154 stars 31 forks source link

An unhandled exception occurred: Value cannot be null. Parameter name: self #26

Open aalmada opened 8 years ago

aalmada commented 8 years ago

I'm using Fody for the first time and I'm getting an unhandled exception. It's a netstandard 1.1 library project. I added both Fody and ReactiveUI.Fody packages and then added the FodyWeavers.xml by hand. The view model has two constructors (one without parameters and another with a parameter). It has two ObservableAsProperty but exceptions still happens when I remove them.

1> Fody: Fody (version 1.29.4.0) Executing 1> Fody/ReactiveUI: ReactiveUI 7.0.0.0 1> Fody/ReactiveUI: ReactiveUI.Fody.Helpers 2.0.65.0 1> Fody/ReactiveUI: ReactiveUI 7.0.0.0 1> Fody/ReactiveUI: ReactiveUI.Fody.Helpers 2.0.65.0 1>MSBUILD : error : Fody: An unhandled exception occurred: 1>MSBUILD : error : Exception: 1>MSBUILD : error : Value cannot be null. 1>MSBUILD : error : Parameter name: self 1>MSBUILD : error : StackTrace: 1>MSBUILD : error : at Mono.Cecil.Rocks.TypeDefinitionRocks.GetConstructors(TypeDefinition self) 1>MSBUILD : error : at ReactiveUI.Fody.ObservableAsPropertyWeaver.Execute() in C:\projects\reactiveui-fody\ReactiveUI.Fody\ObservableAsPropertyWeaver.cs:line 41 1>MSBUILD : error : at ReactiveUI.Fody.ModuleWeaver.Execute() in C:\projects\reactiveui-fody\ReactiveUI.Fody\ModuleWeaver.cs:line 31 1>MSBUILD : error : at lambda_method(Closure , Object ) 1>MSBUILD : error : at InnerWeaver.ExecuteWeavers() in C:\projects\fody\FodyIsolated\InnerWeaver.cs:line 161 1>MSBUILD : error : at InnerWeaver.Execute() in C:\projects\fody\FodyIsolated\InnerWeaver.cs:line 82 1>MSBUILD : error : Source: 1>MSBUILD : error : Mono.Cecil.Rocks 1>MSBUILD : error : TargetSite: 1>MSBUILD : error : System.Collections.Generic.IEnumerable`1[Mono.Cecil.MethodDefinition] GetConstructors(Mono.Cecil.TypeDefinition) 1>MSBUILD : error : 1> Fody: Finished Fody 22ms.

aalmada commented 8 years ago

If I install only the ReactiveUI.Fody 2.0.65 package, NuGet states that will install Fody 1.13.0. The project compiles but, when I execute, it crashes because of a missing method. If I also install the Fody 1.29.4 package, NuGet states that it will upgrade Fody. When I compile, I get the error.

kswoll commented 8 years ago

Hi, sorry for not getting back to you sooner. I'll take a look at it this weekend.

aalmada commented 7 years ago

Looks like Fody doesn't support .NET Standard: https://github.com/Fody/Fody/issues/280

gtbuchanan commented 7 years ago

I'm running into this issue now trying to upgrade my projects to .NET Standard. The aforementioned issue has been closed, so Fody now supports .NET Standard. Any update on this?

RostislavST commented 7 years ago

PropertyChanged.Fody now works on .NET Standard but ReactiveUI.Fody not. https://github.com/Fody/Fody/issues/280

RostislavST commented 7 years ago

I managed to get it working with netstandard 1.6 as Solution Weavers project (local):

You need to replace in ObservableAsPropertyWeaver.cs

var exceptionType = ModuleDefinition.ImportReference(typeof(Exception));
var exceptionConstructor = ModuleDefinition.ImportReference(exceptionType.Resolve().GetConstructors().Single(x => x.Parameters.Count == 1));

to this

var systemRuntimeName = ModuleDefinition.AssemblyReferences.Where(x => x.Name == "System.Runtime").FirstOrDefault();
var systemRuntime = ModuleDefinition.AssemblyResolver.Resolve(systemRuntimeName);
var exceptionDefinition = systemRuntime.MainModule.Types.First(x => x.Name == "Exception");
var constructorDefinition = exceptionDefinition.GetConstructors().Single(x => x.Parameters.Count == 1);
var exceptionConstructor = ModuleDefinition.ImportReference(constructorDefinition); 
kswoll commented 7 years ago

Thanks for looking into it, @RostislavST, I'll get to it this weekend.

gtbuchanan commented 7 years ago

I see @RostislavST put up a NuGet package for netstandard 1.6. Unfortunately, I can't use it since I have to support UWP. Any chance of getting an official package soon, @kswoll?

RostislavST commented 7 years ago

UWP not supporting NET standard 1.6? https://blogs.msdn.microsoft.com/dotnet/2017/10/10/announcing-uwp-support-for-net-standard-2-0/

gtbuchanan commented 7 years ago

No. Not until Oct 17th. Even then, it won't be backward compatible. UWP currently only supports netstandard 1.4. From the article:

You also need to be running on and targeting Windows 10 Fall Creators Update, which will be released later this month.

I've already gone through the hassle of forking your repo, changing the namespace back to what it was so I don't have to refactor everything, targeting netstandard 1.4, and building a new package. Thanks anyway for the fix.