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

Fix decompilation of record with missing base type #3021

Merged
merged 1 commit into from
Jun 22, 2023

Conversation

andrewcrawley
Copy link
Contributor

Problem

As described in #3020, the decompiler fails with a NullReferenceException when attempting to decompile a record type whose base type cannot be determined (e.g. because the base type is defined in another assembly that is not loaded).

Solution

This commit updates RecordDecompiler to null check the baseClass field before making use of it. With this fix, the null ref is avoided, but the generated code for the record will contain unnecessary [CompilerGenerated] members:

internal record RemovedSettingRegistration : SettingRegistration
{
	public RemovedSettingRegistration(SettingRegistration original)
		: base(original)
	{
	}

	[CompilerGenerated]
	public override string ToString() { ... }

	[CompilerGenerated]
	protected override bool PrintMembers(StringBuilder builder) { ... }

	[CompilerGenerated]
	public override int GetHashCode() { ... }

	[CompilerGenerated]
	public sealed override bool Equals(SettingRegistration? other) { ... }

	[CompilerGenerated]
	public virtual bool Equals(RemovedSettingRegistration? other) { ... }

	[CompilerGenerated]
	protected RemovedSettingRegistration(RemovedSettingRegistration original)
		: base((SettingRegistration)(object)original)
	{
	}
}

This commit updates `RecordDecompiler` to avoid a null ref when the
decompiler is unable to determine the base type of a record (e.g.
because the base type is defined in another assembly that is not
loaded).
@dgrunwald dgrunwald merged commit dcd1a07 into icsharpcode:master Jun 22, 2023
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

Successfully merging this pull request may close these issues.

2 participants