Skip to content

System.FieldAccessException Because of Inlining Method #8

@WalkerCodeRanger

Description

@WalkerCodeRanger

Using InlineMethod.Fody 0.7.2 and Fody 6.8.1 on .NET 8. The below code throws a System.FieldAccessException because Clear is inlined. It makes sense to me why the runtime might enforce access restrictions that cause this exception. But the method should not be inlined in a case like this and a warning should be issued that it can't be inlined because it would access an inaccessible field.

using System.Collections.Generic;
using InlineMethod;

public class Example
{
    private List<int> values = new();

    [Inline]
    public void Clear() => values.Clear();
}

public class User
{
    public void Caller() => new Example().Clear();
}

Exception:

System.FieldAccessException
Attempt by method 'User.Caller()' to access field 'Example.values' failed.
   at User.Caller() in C:\dataFast\azoth-lang\azoth.tools.bootstrap\Compiler.Core\Attributes\User.cs:line 14

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions