Nullable generic struct causes Fody exception
See original GitHub issueNullable generic struct causes Fody exception. Making it either not nullable or not generic fixes it.
1>------ Build started: Project: FodyStructException, Configuration: Debug Any CPU ------
1>MSBUILD : error : Fody: An unhandled exception occurred:
1>MSBUILD : error : Exception:
1>MSBUILD : error : Failed to execute weaver C:\Users\virzak\.nuget\packages\propertychanged.fody\3.2.8\build\..\weaver\PropertyChanged.Fody.dll
1>MSBUILD : error : Type:
1>MSBUILD : error : System.Exception
1>MSBUILD : error : StackTrace:
1>MSBUILD : error : at InnerWeaver.ExecuteWeavers() in C:\projects\fody\FodyIsolated\InnerWeaver.cs:line 202
1>MSBUILD : error : at InnerWeaver.Execute() in C:\projects\fody\FodyIsolated\InnerWeaver.cs:line 109
1>MSBUILD : error : Source:
1>MSBUILD : error : FodyIsolated
1>MSBUILD : error : TargetSite:
1>MSBUILD : error : Void ExecuteWeavers()
1>MSBUILD : error : Object reference not set to an instance of an object.
1>MSBUILD : error : Type:
1>MSBUILD : error : System.NullReferenceException
1>MSBUILD : error : StackTrace:
1>MSBUILD : error : at Mono.Cecil.ImportGenericContext.TypeParameter(String type, Int32 position) in C:\Code\Fody\cecil\Mono.Cecil\Import.cs:line 94
1>MSBUILD : error : at Mono.Cecil.DefaultMetadataImporter.ImportTypeSpecification(TypeReference type, ImportGenericContext context) in C:\Code\Fody\cecil\Mono.Cecil\Import.cs:line 648
1>MSBUILD : error : at Mono.Cecil.DefaultMetadataImporter.ImportType(TypeReference type, ImportGenericContext context) in C:\Code\Fody\cecil\Mono.Cecil\Import.cs:line 492
1>MSBUILD : error : at Mono.Cecil.DefaultMetadataImporter.ImportTypeSpecification(TypeReference type, ImportGenericContext context) in C:\Code\Fody\cecil\Mono.Cecil\Import.cs:line 640
1>MSBUILD : error : at Mono.Cecil.DefaultMetadataImporter.ImportType(TypeReference type, ImportGenericContext context) in C:\Code\Fody\cecil\Mono.Cecil\Import.cs:line 492
1>MSBUILD : error : at Mono.Cecil.DefaultMetadataImporter.ImportMethodSpecification(MethodReference method, ImportGenericContext context) in C:\Code\Fody\cecil\Mono.Cecil\Import.cs:line 724
1>MSBUILD : error : at Mono.Cecil.DefaultMetadataImporter.ImportMethod(MethodReference method, ImportGenericContext context) in C:\Code\Fody\cecil\Mono.Cecil\Import.cs:line 677
1>MSBUILD : error : at Mono.Cecil.DefaultMetadataImporter.ImportReference(MethodReference method, IGenericParameterProvider context) in C:\Code\Fody\cecil\Mono.Cecil\Import.cs:line 744
1>MSBUILD : error : at Mono.Cecil.ModuleDefinition.ImportReference(MethodReference method, IGenericParameterProvider context) in C:\Code\Fody\cecil\Mono.Cecil\ModuleDefinition.cs:line 915
1>MSBUILD : error : at ModuleWeaver.GetEquality(TypeReference typeDefinition)
1>MSBUILD : error : at ModuleWeaver.FindTypeEquality(PropertyData propertyData)
1>MSBUILD : error : at ModuleWeaver.FindComparisonMethods(TypeNode node)
1>MSBUILD : error : at System.Collections.Generic.List`1.ForEach(Action`1 action)
1>MSBUILD : error : at ModuleWeaver.FindComparisonMethods()
1>MSBUILD : error : at ModuleWeaver.Execute()
1>MSBUILD : error : at InnerWeaver.ExecuteWeavers() in C:\projects\fody\FodyIsolated\InnerWeaver.cs:line 174
1>MSBUILD : error : Source:
1>MSBUILD : error : Mono.Cecil
1>MSBUILD : error : TargetSite:
1>MSBUILD : error : Mono.Cecil.TypeReference TypeParameter(System.String, Int32)
1>MSBUILD : error :
1>Done building project "FodyStructException.csproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Minimal Repro
The failing unit test is in PR #624
using PropertyChanged;
[AddINotifyPropertyChangedInterface]
public class ParentOfNullableGenericStruct<T>
{
public GenericStruct<T>? ChildProperty { get; set; }
}
public struct GenericStruct<T>
{
public T Value { get; }
}
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:7 (5 by maintainers)
Top Results From Across the Web
Why NullGuard.Fody doesn't support value types
So, instead, I'm applying the NullGuard attribute only to the new classes I write, or those I can verify won't be negatively affected....
Read more >Structs - C# language specification
This chapter defines struct declarations. In many cases, the descriptions are defined using the differences between classes and structs.
Read more >Classes and Generics - C# 6.0 Cookbook, 4th Edition [Book]
Classes and Generics 1.0 Introduction The recipes in this chapter cover the foundation of the C# language. Topics include classes and structures, how...
Read more >Null Reference Exceptions
Null Reference Exceptions. A NullReferenceException happens when you try to access a reference variable that isn't referencing any object.
Read more >Null Pointer Exception In Java
NullPointerException is thrown when program attempts to use an object reference that has the null value. These can be: Invoking a method from...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@jbevain i was a bug on my side
@virzak sorry. yep good point.
@jbevain look like a cecil bug to you? want me to try for a repro in cecil ?