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

nameof should not cause CS0012 (The type 'type' is defined in an assembly that is not referenced.) #76726

Closed
datvm opened this issue Jan 12, 2025 · 1 comment

Comments

@datvm
Copy link

datvm commented Jan 12, 2025

Version Used: 17.12.12.57101

Steps to Reproduce:

  1. Refer to an assembly A.dll that depends on B.dll but do not refer to B.dll itself. In my context, I am writing a game mod that patch the game so B.dll is loaded by the game and is not needed for my project.
  2. Use nameof(A.SomeClass.SomeMethod). For some reason, even though this specific method signature and the method implementation do not use anything from B.dll, the following error is reported:

Image

The type 'TickableComponent' is defined in an assembly that is not referenced. You must add a reference to assembly 'Timberborn.TickSystem, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'.

Diagnostic Id:

N/A

Expected Behavior:

nameof should not raise any error here.

Actual Behavior:

CS0012 is reported.

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels Jan 12, 2025
@jaredpar
Copy link
Member

Refer to an assembly A.dll that depends on B.dll but do not refer to B.dll itself.

In this case the you've given the compiler an incomplete reference graph. While the compiler takes care to not dig into missing references if possible, there are no guarantees around this. The compiler has, and will in the future, introduce bug fixes that require us to dig into missing assembly references and issue an error when they are not available. The behavior of this space is overall not defined: there are cases it will work but that should be considered the exception not the rule. The compiler at is core requires a complete reference graph.

@jaredpar jaredpar closed this as not planned Won't fix, can't repro, duplicate, stale Jan 16, 2025
@dotnet-policy-service dotnet-policy-service bot removed the untriaged Issues and PRs which have not yet been triaged by a lead label Jan 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants