Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blank VB project on .NET Framework does not compile when PropertyChanging.Fody is added #569

Closed
xeniorn opened this issue Feb 3, 2025 · 8 comments

Comments

@xeniorn
Copy link

xeniorn commented Feb 3, 2025

Describe the issue

When using a .NET Framework VB project, adding the PropertyChanging.Fody makes the project not compile. This happens regardless of the version of PropertyChanging.Fody or Fody (tested with Fody 1.x.x - 6.x.x).

The same does not happen with C#, which will compile normally.

Error text:

Fody: An unhandled exception occurred:
Exception:
Failed to execute weaver C:\Users\juraj.ahel\source\repos\FodyTests\packages\PropertyChanging.Fody.1.30.3\build\..\weaver\PropertyChanging.Fody.dll
Type:
System.Exception
StackTrace:
   at InnerWeaver.ExecuteWeavers() in C:\projects\fody\FodyIsolated\InnerWeaver.cs:line 222
   at InnerWeaver.Execute() in C:\projects\fody\FodyIsolated\InnerWeaver.cs:line 113
Source:
FodyIsolated
TargetSite:
Void ExecuteWeavers()
Object reference not set to an instance of an object.
Type:
System.NullReferenceException
StackTrace:
   at ModuleWeaver.HasPropertyChangingEvent(TypeDefinition typeDefinition)
   at ModuleWeaver.HierarchyImplementsINotify(TypeReference typeReference)
   at ModuleWeaver.HierarchyImplementsINotify(TypeReference typeReference)
   at ModuleWeaver.PopulateINotifyNodes(List`1 typeNodes)
   at ModuleWeaver.BuildTypeNodes()
   at ModuleWeaver.Execute()
   at InnerWeaver.ExecuteWeavers() in C:\projects\fody\FodyIsolated\InnerWeaver.cs:line 186
Source:
PropertyChanging.Fody
TargetSite:
Boolean HasPropertyChangingEvent(Mono.Cecil.TypeDefinition)

A fresh VB.NET project at first gives a different error, like in the related PropertyChanged.Fody library, solved as shown here:
Fody/PropertyChanged#313

But after solving that part, gives the quoted error.

Minimal Repro

VB.NET .NET Framework 4.8:
FodyVb.zip

On .NET Core and above, the issue does not occur.

Make an effort to fix the bug

The workaround for VB.NET is to add the following to the .vbproj file:

<Reference Include="Microsoft.VisualBasic" />

@SimonCropp
Copy link
Member

are you a sponsor of the project?

@xeniorn
Copy link
Author

xeniorn commented Feb 3, 2025

I am not. I consider it simply as a bug report, not a support request. I don't expect you to solve it unless you consider it a matter of general interest for the project. My assumption is that this is a small but still valuable contribution, both for you to know of the issue, and for anyone else encountering the issue to have a documented workaround.

Would you prefer not to get bug reports from non-sponsors?

@xeniorn
Copy link
Author

xeniorn commented Feb 3, 2025

I'm a sponsor now, considering how useful Fody is, I don't mind contributing. :)

@tom-englert
Copy link
Member

Looking at the workaround you supposed, I don't see any other way to fix this, since Fody can't know what language the assembly was created from.

@xeniorn
Copy link
Author

xeniorn commented Feb 6, 2025

@tom-englert - PropertyChanged.Fody does not require this change when using the same setup, so it's not a general Fody issue. There must be a difference in implementation causing this repo to have a dependency on this, which most likely could be averted.

The question is how many users of VB.NET/NET4.8 are around and if it's worth solving it "elegantly", or it's rather better to document the requirement explicitly in the setup instructions / notes and leave it at that. Since there's already a requirement to inject mscorlib / System.Object in legacy VB.NET/NETFramework projects.

@tom-englert
Copy link
Member

Since both VB and NetFramework are retired technologies, I would rather recommend to document this requirement.

Can you provide a PR?

@xeniorn xeniorn mentioned this issue Feb 7, 2025
3 tasks
@xeniorn
Copy link
Author

xeniorn commented Feb 7, 2025

Agreed

@tom-englert
Copy link
Member

Added info to the Wiki

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants