question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Nullable generic struct causes Fody exception

See original GitHub issue

Nullable 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:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
SimonCroppcommented, Aug 30, 2020

@jbevain i was a bug on my side

1reaction
SimonCroppcommented, Aug 26, 2020

@virzak sorry. yep good point.

@jbevain look like a cecil bug to you? want me to try for a repro in cecil ?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found