- Home /
The question is answered, right answer was accepted
How to fix "predefined type 'System.void' is not defined or imported"?
I have a brand new script in C# and it already has an error that I don't know how to fix.
I am using Version 2018.3.0f2
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ButtonManager : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
}
first and last bracket are wrong. how did they get the? a script starts with a using directive usually
@hexagonius When I was first typing this, the first few lines of the code would not appear in the box with the other code, it just stayed as normal text. So in an effort to fix that I tried to use those brackets but it didn't work and I forgot to remove them. But it appears to now have fixed itself.
Answer by lukiluc67 · Dec 24, 2018 at 03:57 PM
In Project settings > Player > Other settings, try to change the Api compatibility level to ".NET 4.x". That's what fixed it for me.
That didn't work for me -- it was already set to ".NET 4.x Equivalent".
Looks like you're looking at the "Scripting Runtime Version" dropdown. lukiluc67 was referring to "API Compatability Level." alt text
Hey, I'm getting the same error and changing the API compatibility level didn't affect the errors I'm getting in Visual Studio 2017. I'm running a clean install of Unity 2018.34f1
Edit: Updating Visual Studio 2017 fixed the errors!
I changed the "API Compatibility Level" to ".NET 4.x Equivalent" and upgraded the Visual Studio 2017 Comunity and this has fixed it for me.
Answer by PeterDrake · Feb 03, 2019 at 07:21 PM
I was able to fix my problem by updating Visual Studio. For about a year it would always pop up a "check for updates" window that never found anything, but this time it did. Installing the updates and restarting Visual Studio resolved the issue.
Answer by EmjadaGameDev · May 13, 2019 at 11:14 AM
I have another very simple fix:
In Visual Studio (I use 2017), find your Project and go under the References list, then delete the "netstandard.dll" reference. The error should go away after that. You can then close and reopen Unity & Visual Studio, and the reference will be back, but the error will still be gone.
Answer by M_R_M · Feb 03, 2019 at 06:50 AM
Just had this exact same issue, created a new script in Unity like I have many before, and it gave me this error out of nowhere.
The issue for me was that I had another script I was working on that was completely unrelated to this one that had an error I was in the middle of troubleshooting. Well apparently Unity can't handle completely unrelated scripts existing in the same project if one has an error, otherwise it'll create nonexistent errors in other scripts.
Short answer: It's a(nother) bug in the editor, check for any errors you may be getting with other scripts, even if they're completely unrelated to the one you're currently working on.
Update: Nope, just opened the script again, and it's giving me the same error out of nowhere, even after deleting the other script with the error. I closed out the script since it no longer had the error, then opened it back up and now the error has returned. I'm not sure what's going on, but seems like a bug.
Answer by Lurkace · Feb 16, 2019 at 11:32 PM
just got the same issue, and none of the answers above helped. I fixed it by: updating my visual studio version, creating a new project, creating a new c# script, running from visual studio (attach and play), getting an error, trying again, restarting the computer AND visual studio. ... and all this started when I updated from Unity 3.4 to 3.8, because I was trying to fix a different weird bug.. I'm not impressed with this Untiy program so far. may just create my game in Godot or something. I can't go through this every time there's an update.