Skip to content
New issue

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

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

Already on GitHub? # to your account

False positive inspections. Attribute 'ExecuteInEditMode' and 'SerializeField' is not valid on this declaration type. #322

Closed
thsbrown opened this issue Jan 4, 2018 · 40 comments
Assignees
Milestone

Comments

@thsbrown
Copy link

thsbrown commented Jan 4, 2018

Seemingly randomly I started getting the above message when opening up a Unity project in Rider.

@thsbrown thsbrown changed the title he reference assemblies for framework ".NETFramework,Version=v3.5" were not found. The reference assemblies for framework ".NETFramework,Version=v3.5" were not found. Jan 4, 2018
@van800
Copy link
Member

van800 commented Jan 4, 2018

Is it only a notification or something else doesn't work? Could you please add a zip with logs from Help - Show logs in Files. Thanks! If you want to submit privately, please use youtrack.jetbrains.com

@thsbrown
Copy link
Author

thsbrown commented Jan 4, 2018

Nope for some reason it's having trouble resolving some packages it looks like.

@van800
Copy link
Member

van800 commented Jan 4, 2018

You may also try to change TargetFramework version for generated csproj in Unity settings
image

@van800
Copy link
Member

van800 commented Jan 4, 2018

But we are interested to see the logs, maybe there is a bug, which requires attention of the Rider team.

@thsbrown
Copy link
Author

thsbrown commented Jan 4, 2018

I checked and my settings match the above.

@van800
Copy link
Member

van800 commented Jan 4, 2018

You may change it to the following, force Unity to regenerate csproj by double clicking any script and see if it helps.
image

@thsbrown
Copy link
Author

thsbrown commented Jan 4, 2018

Wen't ahead and tried what you said and still didn't resolve anything. Still getting errors saying certain pieces of code are not allowed when they clearly should be :(

@thsbrown
Copy link
Author

thsbrown commented Jan 4, 2018

So far here is what I have tried to resolve this issue.

  • Reinstalling rider
  • Deleting Library from project
  • Deleting all assembly files
  • Invalidating Caches and restarting
  • Pointing to the Mono file in Unity from within Rider

Quite a few other small things as well :(

@van800
Copy link
Member

van800 commented Jan 4, 2018

Please check which msbuild is used in Rider
image

Just to be sure that it is not the dotnetcore one.

C:\Program Files (x86)\MSBuild\14.0\bin\MSBuild.exe should be best for Unity project.

@van800
Copy link
Member

van800 commented Jan 4, 2018

Issue seem related to https://youtrack.jetbrains.com/issue/RIDER-11917

@thsbrown
Copy link
Author

thsbrown commented Jan 4, 2018

image

@thsbrown
Copy link
Author

thsbrown commented Jan 4, 2018

Very strange that Rider was working great for the entire time I've been using it. I close it and reopen it and I begin getting errors.

Checked the bug you sent along. It does seem like it could be the same thing.

@van800
Copy link
Member

van800 commented Jan 4, 2018

Try also to remove the mono executable path.
Do I understand right, that solution builds fine in Rider?
What kind of errors do you have exception warning ".NET Framework Not Installed: Download and install .NET Framework 3.5 Developer Pack"?

@thsbrown
Copy link
Author

thsbrown commented Jan 4, 2018

1/4/2018
11:49 AM	Project 'Assembly-CSharp' load finished with warnings: The reference assemblies for framework ".NETFramework,Version=v3.5" were not found. To resolve this, install the SDK or Targeting Pack for this framework version or retarget your application to a version of the framework for which you have the SDK or Targeting Pack installed. Note that assemblies will be resolved from the Global Assembly Cache (GAC) and will be used in place of reference assemblies. Therefore your assembly may not be correctly targeted for the framework you intend. at (1111:5)

11:49 AM	Project 'Assembly-CSharp-firstpass' load finished with warnings: The reference assemblies for framework ".NETFramework,Version=v3.5" were not found. To resolve this, install the SDK or Targeting Pack for this framework version or retarget your application to a version of the framework for which you have the SDK or Targeting Pack installed. Note that assemblies will be resolved from the Global Assembly Cache (GAC) and will be used in place of reference assemblies. Therefore your assembly may not be correctly targeted for the framework you intend. at (1111:5)

11:49 AM	Project 'Assembly-CSharp-Editor' load finished with warnings: The reference assemblies for framework ".NETFramework,Version=v3.5" were not found. To resolve this, install the SDK or Targeting Pack for this framework version or retarget your application to a version of the framework for which you have the SDK or Targeting Pack installed. Note that assemblies will be resolved from the Global Assembly Cache (GAC) and will be used in place of reference assemblies. Therefore your assembly may not be correctly targeted for the framework you intend. at (1111:5)

11:49 AM	Project 'Assembly-CSharp-Editor-firstpass' load finished with warnings: The reference assemblies for framework ".NETFramework,Version=v3.5" were not found. To resolve this, install the SDK or Targeting Pack for this framework version or retarget your application to a version of the framework for which you have the SDK or Targeting Pack installed. Note that assemblies will be resolved from the Global Assembly Cache (GAC) and will be used in place of reference assemblies. Therefore your assembly may not be correctly targeted for the framework you intend. at (1111:5)

11:49 AM	.NET Framework Not Installed: Download and install .NET Framework 3.5 Developer Pack

Removed mono path. Solution builds fine in rider however it reports a few errors on code that shouldn't exist.

@van800
Copy link
Member

van800 commented Jan 4, 2018

Does it build?
image

@thsbrown
Copy link
Author

thsbrown commented Jan 4, 2018

image
Build does indeed succeed

@van800
Copy link
Member

van800 commented Jan 4, 2018

Any red code maybe?

@thsbrown
Copy link
Author

thsbrown commented Jan 4, 2018

Yes indeed. I'll go post some pictures of that.

@thsbrown
Copy link
Author

thsbrown commented Jan 4, 2018

image

image

image

@van800
Copy link
Member

van800 commented Jan 4, 2018

And have you cleared the Mono Executable Path, right?
image

@thsbrown
Copy link
Author

thsbrown commented Jan 4, 2018

Yup went ahead and cleared that.

@thsbrown
Copy link
Author

thsbrown commented Jan 4, 2018

image

@van800
Copy link
Member

van800 commented Jan 4, 2018

If you change TargetFramework version and save, does it help?
image

@van800
Copy link
Member

van800 commented Jan 4, 2018

It is really a weird issue,
I will show it to other team members tomorrow, if no new idea will come,
we can have a call with sceenshare or teamviewer, if you like.

@thsbrown
Copy link
Author

thsbrown commented Jan 4, 2018

That sounds great to me thanks!

@van800
Copy link
Member

van800 commented Jan 5, 2018

You may try

  1. Check that in csproj hintpath to UnityEngine.dll is correct.

2.1. Switch Rider to internal mode
https://rider-support.jetbrains.com/hc/en-us/articles/207327910-How-to-run-JetBrains-Rider-in-Internal-Mode

2.2. Call internal Action "Reload project and show logs"
image

If it will not give a clue, I am ready to have a call today. Next week I will be on vacation, so lets do it today.
Please ping me on skype van800 or google hangout van800_a_t_gmail.com

@thsbrown
Copy link
Author

thsbrown commented Jan 5, 2018

Ok wen't ahead a did what you suggested. Should I post the log here?

It looks like it wants ToolsVersion="4.0". Maybe that's whats causing the issue.

@van800
Copy link
Member

van800 commented Jan 5, 2018

Please post it.

@thsbrown
Copy link
Author

thsbrown commented Jan 5, 2018

Here you go. Thanks once again for the help.

Log.txt

@van800
Copy link
Member

van800 commented Jan 5, 2018

If you expand References node in Solution Explorer, are there any yellow unresolved references?

@van800
Copy link
Member

van800 commented Jan 5, 2018

I have reproduced one of your red-code pieces.

public class Class1:UnityEditor.Editor
{
[ExecuteInEditMode]
private void OnEnable()
{
throw new System.NotImplementedException();
}
}
It clearly states that [ExecuteInEditMode] applies only to class not method.

\Assets\Plugins\Editor\JetBrains\Class1.cs:114 Attribute 'UnityEngine.ExecuteInEditMode' is not valid on this declaration type. It is valid on 'Class' declarations only.

@van800
Copy link
Member

van800 commented Jan 5, 2018

https://docs.unity3d.com/ScriptReference/SerializeField.html

  • CANNOT serialize properties.

So the error is not a false one.

@thsbrown
Copy link
Author

thsbrown commented Jan 5, 2018

Sorry it's been a long day and didn't have time to check this till now. That error should not be displaying there.
I have had that library in place since day 1 and no problem has every occured.
Furthermore there is another error that it encounter that shouldn't be thrown due to the existence of a library in place.

Hopefully this makes sense.

Thanks in advance!

For reference check out this http://www.sirenix.net/odininspector/faq/30/why-is-odin-not-serializing-or-showing-my-field-or-property

@van800 van800 changed the title The reference assemblies for framework ".NETFramework,Version=v3.5" were not found. False positive inspections. Attribute 'ExecuteInEditMode' and 'SerializeField' is not valid on this declaration type. Jan 6, 2018
@van800
Copy link
Member

van800 commented Jan 6, 2018

@citizenmatt please take a look.

The code piece above shows 2 errors, which are implemented in resharper-unity, not Rider itself.
@spartanace1024 claims that they are not errors for his project (powered by odininspector)

using UnityEngine;
using UnityEngine.Collections;

namespace Assets.Plugins.Editor.JetBrains
{
public class Class1:UnityEditor.Editor
{
[ExecuteInEditMode]
private void OnEnable()
{
throw new System.NotImplementedException();
}

[SerializeField]
public bool ForceUpdate { get; set; }

}
}

@citizenmatt
Copy link
Member

This behaviour was added in the last update. Some of Unity's attributes can only be usefully applied to certain targets - classes, fields, methods, etc. - but some of them don't declare these targets, which makes it hard to know if they're applied correctly, and difficult to see why they're not working (e.g. because they're in the wrong place). So this behaviour was added to help show when attributes where applied to the wrong code element, with the aim of helping the user know when something was wrong, and hopefully, why it wasn't working.

But it's only an error in the editor. The attributes can be applied to any code element, and the compiler and Unity will allow it. Rider is just trying to help point out that these attributes don't do anything useful in these locations. As far as Unity is concerned, [SerializeField] can only be applied to fields, and [ExecuteInEditMode] should be applied to the class.

Of course, it's entirely likely I've got this wrong :) Can we just confirm that they are actually working where you've applied them? Then we can look at how best to fix this.

I've had a scan through the page you've linked, and don't see an example of [SerializeField] working on properties. Does Odin Inspector actually use this attribute to make properties serializable? Or is it serializing the property because it's public? What happens with Odin Inspector if you remove the [SerializeField] attribute?

And does the OnEnable method actually get called? If we look at the UnityDecompiled project, the only usage is looking for it to be applied to a class.

@thsbrown
Copy link
Author

thsbrown commented Jan 7, 2018

According to one of there developers as long as Odin Inspector sees the [SerializeField] on an auto property it will be serialized by Odin and shown in the inspector.

However I do see what you mean by the errors showing up in Rider and yet them not effecting compile time. I would say though, if this is in fact a feature that is meant to be helpful I strongly urge you guys to turn those errors into warnings. This error has caused a great deal of confusion on my part and if Unity still allows the compilation it doesn't feel like it is in fact is an error then.

The code where those errors do show up though has been in plugin code rather then my own code so I just assumed that the plugin developers knew what they were doing. ( Photon / Amplify Color are the two plugins to blame )

Hopefully this all makes sense.

Thanks in advance!

@thsbrown
Copy link
Author

thsbrown commented Jan 7, 2018

Ok some good news here. After @citizenmatt updated me on why Rider was spitting out those errors I went ahead and did some digging into installed plugins.

Updated Photon and error went away for all photon scripts. Confirmed it was there error from there changelog. It reads Removed: surplus attribute ExecuteInEditMode in Editor script..

That's one problem fixed. I still stick to my statement earlier though. Not sure these should be errors but warnings 😅 .

Now to fix the .Net problem.

@citizenmatt
Copy link
Member

I've been thinking about this, and I think that if it was only user code, I'd leave it as it is - the attributes are in the wrong place, and won't work (usually), so an error is fine. The idea behind the current implementation is that Unity didn't set valid targets on these attributes, so I added them, and this is the standard error that ReSharper displays when an attribute is applied to an incorrect target.

However, we also have to deal with code downloaded from the asset store, and I think it's unfair to show an error in code that maybe you didn't write, or that you're not maintaining, especially when the code will compile just fine. So I think it would be a good idea to downgrade this to a warning, most likely greyed out "redundant" code, since it's technically fine to apply to this target, but does nothing. I'll open another issue to track that.

@thsbrown
Copy link
Author

thsbrown commented Jan 9, 2018

Sounds like exactly what I was thinking @citizenmatt. Great idea.

To give Rider / Resharper-Unity credit I went ahead contacted all the plugin authors where the errors were displaying and told them the attributes were not taking effect. I'm sure they were happy the bug was caught before it became a problem 👍. They all told me they would fix it in the upcoming updates.

Thanks once again for the stellar help guys. Kudos @citizenmatt & @van800

@citizenmatt
Copy link
Member

Lovely feedback, thanks! This is what we're aiming at - helping find issues without having to debug, or switch to Unity or know some weird rules. Thanks for reporting to the plugin authors!

@citizenmatt citizenmatt added this to the Rider 2018.1 milestone Feb 23, 2018
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants