Issue with Fody 2.3.0+ in VB assemblies
See original GitHub issueI found the following error when trying to upgrade one of our VB projects to use the latest version of Fody:
Error Fody: An unhandled exception occurred:
Exception:
Failed to execute weaver C:\Users\jwoods\.nuget\packages\janitor.fody\1.6.1\netclassicweaver\Janitor.Fody.dll
Type:
System.Exception
StackTrace:
at InnerWeaver.ExecuteWeavers() in C:\projects\fody\FodyIsolated\InnerWeaver.cs:line 208
at InnerWeaver.Execute() in C:\projects\fody\FodyIsolated\InnerWeaver.cs:line 103
Source:
FodyIsolated
TargetSite:
Void ExecuteWeavers()
Object reference not set to an instance of an object.
Type:
System.NullReferenceException
StackTrace:
at CecilExtensions.Find(TypeDefinition typeReference, String name, String[] paramTypes) in C:\projects\janitor\Janitor.Fody\CecilExtensions.cs:line 110
at ModuleWeaver.FindCoreReferences() in C:\projects\janitor\Janitor.Fody\ReferenceFinder.cs:line 7
at ModuleWeaver.Execute() in C:\projects\janitor\Janitor.Fody\ModuleWeaver.cs:line 9
at InnerWeaver.ExecuteWeavers() in C:\projects\fody\FodyIsolated\InnerWeaver.cs:line 204
Source:
Janitor.Fody
TargetSite:
Mono.Cecil.MethodDefinition Find(Mono.Cecil.TypeDefinition, System.String, System.String[])
At first, I thought this was an issue with the Janitor weaver, but after trying to make a failing unit test in the Janitor project, I found that it ran correctly in the unit test.
Then I also noticed a similar error upgrading another VB project to use the latest version of Anotar.
I did a little digging and found that Janitor 1.5.2 works correctly with Fody 2.2.1, but if I just upgrade Fody to 2.3.0, I start getting this error. I also upgraded both Janitor and Fody to the latest versions available (1.6.1 & 3.0.4, respectively) and still get the error (I’ve created a repo to show this error).
This error only occurs when running Fody on a VB assembly using the full .Net Framework.
Here are the test cases I used:
Language | Framework | Result |
---|---|---|
C# | netstandard2.0 | no error |
C# | net462 | no error |
VB | netstandard2.0 | no error |
VB | net462 | ERROR |
After looking into the issue a bit, I found that on line 7 (from the Janitor weaver) the code ModuleDefinition.TypeSystem.Object.Resolve()
returns null
when running using Fody (again, it worked from the unit test, so that seems to indicate the error is not in Mono.Cecil).
My suspicion is that the error is somewhere in the Fody.Isolated project. I’ve been trying to write a unit test to confirm my suspicion, but I have been having trouble doing that.
I just wanted to go ahead and raise this issue up here as you may have more success at adding a failing unit test than I’m currently having.
I’ll update this issue if I find any further details.
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (6 by maintainers)
adding
<Reference Include="mscorlib" />
fixes the issue. weird that that’s not automatically included in VB projects.yes, it can be closed