VS Code IntelliSense does not work with Unity. Why? - c#

VS Code IntelliSense does not work with Unity. Why?
I am using Unity with VS Code. When I type I do not get any suggestions which are related to Unity. E.g. I am not getting the gameObject suggested once I type this.:
Another example is that I can not go to the MonoBehaviour definition:
I saw this question. So, I checked that all of the extensions recommended in the answer are installed:
The extensions installation did not help. Could someone help with the issue, please?
I am using the Unity 2019.3.2f1.
If in Unity Editor I go to the Window - Package Manager - search for Visual Studio Code Editor I see it is there:
Actually I can not see the definition even for System. So, I believe there should be something wrong on the VS Code side:
Also, I followed the video. It did not help. Under the video there is the comment:
For anyone still cannot get the autocomplete to work, try installing the ".net framework 4.7.1 developer pack".
In my case, I am using Unity 2019.1.2, and I installed dotnet core 2.2 which comes with ".net framework 4.7.2.". Apparently Unity 2019.1.2 requires framework 4.7.1. You can find which .net framework version is required by checking the Assembly-CSharp.csproj file
I followed the comment suggestion. I checked what version is specified in my case in the TargetFrameworkVersion. It is 4.7.1. So, I downloaded the 4.7.1. While installing the version it told me that it is already installed and whether or not I would like to reinstall it. I reinstalled it and still it did not help.

It seems I was able to fix the issue. I went to Edit - Project Settings - Player - Other Settings - Configuration - Api Compatibility Level. Then I changed it from .NET Standard 2.0 to .NET 4.x. Then I reopened Unity, changed it back (to preserve the API restriction) and reopened Unity. And now the suggestions work as expected. Except for a few warnings I am getting on script opening (here is the question which is related to the warnings).

Related

SDK Resolver Failure - Net 7 - Net 6

Just downloaded and installed SDK Net 7.0.100 and it broke existing applications and they won't load any more in VS 2022 or Rider.
Copied the follwing error:
error : SDK Resolver Failure: "The SDK resolver "Microsoft.DotNet.MSBuildSdkResolver"
failed while attempting to resolve the SDK "Microsoft.NET.Sdk". Exception: "Microsoft.NET.Sdk.WorkloadManifestReader.WorkloadManifestCompositionException: Workload definition 'wasm-tools' in manifest 'microsoft.net.workload.mono.toolchain.net7' [C:\Program Files\dotnet\sdk-manifests\7.0.100\microsoft.net.workload.mono.toolchain.net7\WorkloadManifest.json] conflicts with manifest 'microsoft.net.workload.mono.toolchain' [C:\Program Files\dotnet\sdk-manifests\7.0.100\microsoft.net.workload.mono.toolchain\WorkloadManifest.json]
at Microsoft.NET.Sdk.WorkloadManifestReader.WorkloadResolver.ComposeWorkloadManifests()
at Microsoft.NET.Sdk.WorkloadManifestReader.WorkloadResolver.Create(IWorkloadManifestProvider manifestProvider, String dotnetRootPath, String sdkVersion, String userProfileDir)
at Microsoft.NET.Sdk.WorkloadMSBuildSdkResolver.CachingWorkloadResolver.Resolve(String sdkReferenceName, String dotnetRootPath, String sdkVersion, String userProfileDir)
at Microsoft.DotNet.MSBuildSdkResolver.DotNetMSBuildSdkResolver.Resolve(SdkReference sdkReference, SdkResolverContext context, SdkResultFactory factory)
at Microsoft.Build.BackEnd.SdkResolution.SdkResolverService.TryResolveSdkUsingSpecifiedResolvers(IList`1 resolvers, Int32 submissionId, SdkReference
I experienced a similar problem.
I uninstalled the 7.0.100-preview.5.22307.18 sdk using add remove programs and then changed the TargetFramework in the project file to use 7.0 and then I was able to load the projects.
EDIT: This is officially documented in the release notes known issues.
I'm from the .NET SDK team. Sorry you're going through this. I would love to comment on the other answers, but I don't have the reputation to do so.
What Tim Farley suggested is an officially endorsed workaround; uninstalling any preview 7 SDKs with add/remove programs should resolve the problem.
As for why this happened and why uninstalling preview SDKs will fix the issue, there's a bit of an explanation I put here: https://github.com/dotnet/sdk/issues/28947#issuecomment-1307987337.
TLDR: Some workloads were renamed in the middle of .NET 7 preview development to support things like multitargeting, and when you download the new RTM old preview files interfere can with it.
Updating the TargetFramework is recommended but it's unrelated to this issue. Usually breaking changes for each .NET version and related new features are gated behind your TargetFramework (TFM), so things don't break until you update the TFM, not when you update the SDK. (Unfortunately, not true in this case.)
In response to whether this will happen again or not when upgrading to .NET 8, per Scott: with how workloads are currently structured this issue would happen again. We're discussing how to make changes to prevent this from happening again though as it's not ideal. We're also considering adding dotnet workload clean or something to repair this for you. Communicating with us on the SDK GH thread, or with me here, is a good way to send us feedback about this.
Repairing Visual Studio installation did not help me. Neither did uninstalling .net 7 faulty workload ('wasm-tools'), since any attempt to uninstall or repair it ended up in the same error message.
Being ran out of conventional options to address the issue, I just went ahead and physically deleted the conflicting folder: microsoft.net.workload.mono.toolchain, leaving second one microsoft.net.workload.mono.toolchain.net7 intact. It luckily solved problems on my machine. From now on I'll be more cautious on installing Ms RC packages
I had a similar problem, even on new .Net projects. I uninstalled the 7.0.100-preview.2.22153.17 SDK using add remove programs and I was able to create a new project again. I am now left with only one .Net 7.0 SDK (from Visual Studio) as shown below.
Uninstall Microsoft .Net SDK 7.0 preview
I had the same issue as above except on my M1 mac. I followed the following guide and manually removed all the directories for all the .net 7 runtimes and sdks. Then reinstalled .net7 and all seems to be well now. rider can open my projects and the dotnet cli no longer complains
Not sure if a similar scorched earth approach will work for the windows folks.
https://devkimchi.com/2021/11/24/removing-dotnet-sdks-from-macos-manually/
I had the same issue, except that no preview version of .NET 7 was currently installed on my system, but the preview artifacts were still in the C:\Program Files\dotnet\sdk-manifests\7.0.100 directory. My solution was to uninstall the stable version of .NET 7 (not the version from VS 2022), then install and uninstall 7.0.100-preview.7. Doing so resulted in the preview artifacts being removed and this error being resolved.
I had same problem, but i think the problem because M1 mac
Had the same problem. Deleted manually installed net 7 sdks in windows uninstaller.
I found out that I needed to rm -rf **/obj
(delete all folders named obj) in the solution root folder after upgrading from net 6 to net 7, in addition to dotnet clean

Can't find UnityEngine.UI namespace after installing Visual StudioTools for Unity

I have been using Visual Studio 2015 community (version 14.0.25123.00 Update 2) with .Net framework v4.6.01038 with Unity Tools for VS2015 which I used to debug my unity projects. Everything seemed to work fine but after I tried to work with UnityEngine.UI VS start showing errors saying that the namespace can't be found. I have used the exact same project files in to another pc where the only difference was in .Net framework version (v4.6.01055)and that worked. If I remove the unity tools from my previous pc, the build error goes away but I guess there is no way to debug without the unity tools. Is this a issue with .net framework or I am missing something?
- I tried to export and re-import all unity assets and packages but that did not solve the issue
- VS2015 was uninstalled and reinstalled from scratch - still did not work
- unity tools was also reinstalled
- Also deleted the projectFolder\Library\UnityAssemblies folder and restarted VS2005.
None of these methods seems to work for me. Tried to find the exact version of .net framework but failed too. Is there a specific solution to this problem?
So I finally found a workaround of this issue and I pretty much think that the .Net framework version was not occurring any problem here. The solution is to Setting the Api Compatibility Level from ".NET 2.0 Subset" to ".NET 2.0". To do this in unity perform the following steps:
Unity > Edit > Project Settings > Player > Api Compatibility Level
From: ".NET 2.0 Subset"
To ".NET 2.0"
Do perform a restart to both Unity and VS2015 (if the above solution doesn't work right then)
Go to: Edit > Preference > External Tools. in External script editor > click on browse > go to unity file > Editor File and click on mono develop.

error cs0103 The Name 'IEnumerator' does not exist in the current context

I have problem in C# development in monodevelop tool for unity.
In that many methods and Interfaces not found like IEnumerator and Array.Length.
I found Same question but it's not work for me.
because solution of that question is import System.Collections namespace but I was already imported it then also throw compile time error.
I Have installed latest .Net Framework on Windows 8.1 Os.
How i solve this problem?
I have had that problem before. I was using the latest .net framework and I went to Programs and Features within control panel (if you're using Windows) and selected the box to also run .net framework 3.5 I think it was.
I then shut down my project after saving, restarted my machine and it worked fine
Close the project from MonoDevelop by doing Right Click. And open the *.sln file manually in MonoDevelop
I'm using Debian and I had your error, this error, and both was fixed by installing these packages:
mono-reference-assemblies-2.0
mono-reference-assemblies-3.5
Using APT:
sudo apt install mono-reference-assemblies-2.0 mono-reference-assemblies-3.5

Can't access Microsoft.Xrm namespace

I've downloaded CRM Dynamics SDK and keep it in a local directory. In my code, I'm using EntityCollection (amongst other classes related to Xrm namespace), which means that I need to add using Microsoft.Xrm.Sdk;.
The problem is that during compilation I get errors saying that:
The type or namespace name 'Xrm' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)
So, I double check that the reference is made and, very accurately, I see that microsoft.xrm.sdk indeed is in my list. Just to be sure, I've removed it and added it again by pointing to the DLL with the same name. To no avail, though... The flabbergasting thing is that my colleague uses the same code and it compiles on his machine (the only difference being that he's on Win 7 and I'm on Win 8).
How do we kill this problem?
Double check in your project settings to see which Target Framework you are using. If it is .NET Framework 4 Client Profile try changing it to .NET Framework 4.
I received this when replacing my crm 2013 dlls with the new 2015 ones.
None of the above solutions worked for me.
But what eventually led me on the right track was this warning (it was listed as a warning below the namespace errors):
The primary reference "Microsoft.Xrm.Client, Version=5.0.9689.2166,
Culture=neutral, PublicKeyToken=31bf3856ad364e35,
processorArchitecture=MSIL" could not be resolved because it was built
against the ".NETFramework,Version=v4.5.2" framework. This is a higher
version than the currently targeted framework
".NETFramework,Version=v4.5.1"
And when I checked I only had .Net 4.5.1 installed so after installing .Net 4.5.2 Developper pack and switching the target framework of my projects to this everything worked again.
The regular 4.5.2 update is not enough to get this version of .net in VS, you need the developper pack
Source: http://www.syntaxwarriors.com/2015/using-crm-2015-sdk-gives-error-that-xrm-does-not-exist-in-the-namespace/
I had my framework already set to .NET Framework 4 therefore solution of switching between 4 Client profile and regular 4 did not apply. A trick I did was changing .NET Framework into 3.5 and then back to 4.0. I hope this will help some people.
Thx #Jason Lattimer. Your answer gave me a clue how to solve my problem.
Good luck CRM developers!
This may not match this specific problem, but I'll add this as something to check for others in case Google directs them here like it did for me.
In my case, I was getting a lot of errors like, "error CS0234: The type or namespace name 'Client' does not exist in the namespace 'Microsoft.Xrm'".
Adding the "Microsoft.CrmSdk.Extensions" NuGet package fixed my compilation issues.
After changing to .NET Framework 4 and changing .NET Framework into 3.5 and then back to 4.0, my poject was still not working.
It didn't work when I selected the option given by the "add Reference" window.
What worked for me was to click on the browse button in the "add Reference" window and look for the Microsoft.Xrm.Sdk.dll file
I had .NET 4.0 as my target framework and I had this compiler error. I tried changing it back to 3.5 and then back to 4.0 and that didn't fix it.
What did fix the problem for me was deleting the bin, obj and tools folders in my project directory. I don't understand the details of why this worked, but it worked for me.
I had this error and in my case, after trying all the above solutions and others on the web with no success, finally I came to a solution.
The problem was in the version of CRM SDK that I was using: 2015 (donĀ“t wanna know why!).
Downloaded CRM 2013 SDK version, changed the assembly references to that version and the problem was gone.
Reason for it is CRM 2015 SDK was built on .Net 4.5.2 Framework and the Visual studio does not support 4.5.2.
Just download .Net Framework 4.5.2
Goto Project Properties and change the framework.
I was having the same issue with my CRM 2011 Plugin. In my case none of the above solution worked.
In my code I am using early bound class. When generating this class file i was using following line along with other settings which was causing the error.
/codeCustomization:"Microsoft.Xrm.Client.CodeGeneration.CodeCustomization, Microsoft.Xrm.Client.CodeGeneration"
Once I added this new class file without codeCustomization, it removed all errors.
As mentioned before,
Reason for it is CRM 2015 SDK was built on .Net 4.5.2 Framework and
the Visual studio does not support 4.5.2.
Just download .Net Framework 4.5.2 Goto Project Properties and change
the framework.
Alternate way could be to replace Microsoft.Xrm.Sdk.dll with file from older CRM SDK. I use VS2010, and CRM 2011 SDK file solved all compiler errors.
P.S. Switching project to .NET 3.5 and back to 4.0 did not helped
Updating NuGet Package helped me to solve the problem

Prexisiting dlls (.NET 4 framework) issue with mono for android

I am creating a fresh Mono for android application using http://xamarin.com/monoforandroid
I selected Mono for Android Application using Visual C# option.
My Android target version is :
I went to references of the project and tried adding my pre existing dlls (made in .NET 4 Framework)
and I got this error:
The strange stuff is there is no option to change the .NET Framework from project properties. Can you tell me what I am missing?
The problem here is that you're trying to reference a .NET 4 DLL from a project that isn't .NET 4. Mono for Android uses its own profile for .NET, which is very similar to that of Silverlight (but not exactly the same). While it's possible that adding a DLL compiled for a different profile will work, it's very risky as you will probably run into problems at runtime where your app will crash, due to something being missing from the Mono for Android profile.
The best answer right now is to create a Mono for Android class library, link in the appropriate files from the library you want to use, and reference that. This will give you compile-time checking that you're not using anything unsupported by the Mono for Android profile, and help keep you more sane in the long run. I have an old blog post up here that talks about how to link files across projects.
That said, in this case you're in luck because someone else has already done that last part for you! Check out this fork of Json.NET which provides versions for MonoTouch and Mono for Android.
The strange stuff is there is no option to change the .NET Framework from project properties. Can you tell me what I am missing?
It's not particularly strange - that dialog box was written by Microsoft, with its own project types in mind. It sounds like Mono for Android doesn't have the same options available.
I strongly suspect you'll just have to use a version of JSON.NET targeting .NET 3.5.
(Having said that, Mono for Android claims to support "dynamic language features" which sounds like it should be targeting .NET 4. Odd. I suspect the fix is the same though.)

Categories

Resources