Cannot resolve symbol - string?

Answered

I am very confused on what Rider is trying to do here.  I am getting an error from Rider saying it can't resolve a symbol but the "symbol" is a string.  There is nothing to resolve.

It is frustrating because it is causing Rider to show an error in my project that is not an actual error.  The code is fine in Unity with no errors and works fine.

0
3 comments

Actually, I think this is a different scenario than the one in the YouTrack ticket linked by Sofia. What Rider is doing here is that it knows the "PostProcessingBehaviour" string literal is intended to refer to a class name - either a built in component, or a component in the project, so it will try to add a "reference", which links the usage of the string literal to the definition of the class itself. This reference link allows things like Ctrl+Click navigation on the string literal, and the results of Find Usages will include the string. And the string literal value would get also renamed when the class is renamed.

The screenshot is showing an error because Rider can't find the "PostProcessingBehaviour" class, which usually means it's not declared in source, or via a referenced assembly, and typically means the call will fail at runtime. However, it's possible that this will resolve at runtime if the current project is e.g. a class library to be used in another Unity project, or a Unity project that has an optional dependency on the post processing stack. 2018.3.2 changed this from an error to a warning. So you're still being warned that as far as Rider can tell, this call will fail at runtime, but it's essentially warning you that it will return null, and isn't a full error. It also means that this error isn't highlighted in the Solution Explorer/Unity Explorer. If you know that this call is going to succeed at runtime, then you can also use the Alt+Enter menu (via the "Inspection: …" sub-menu) to add a comment to this line to disable the warning.

1

Forgot to add this bit :)

Please can you check that you're on Rider 2018.3.2 (or the just released 2018.3.3), and if you think "PostProcessingBehaviour" should be resolved, can you let me know what the project structure is like - where is this component declared and how are you referencing the assembly, etc.?

0

Hi Matt, I will try updating today and see how that goes.

For further context on this.  You are correct in that PostProcessingBehaviour is not referenced, which is why it is using the string form of the call rather than the generic form.  I guess this is an area where Rider is trying to be extra smart and working against me :)

I can't really add an inspection override in this case because this is in 3rd party code, specifically in the SteamVR library.  I assume they have set it up this way as PostProcessing is an optional thing and you'll note the return value in this case is being cast just to GameObject because all the code cares about is if the component exists, it dosn't need to do anything with it except disable the overall GameObject it is on.

 

0

Please sign in to leave a comment.