Asp.NetCore 1.1->2.0 Migration Error - `System.Object' is not defined or imported - visual-studio

I have a project I've been messing with and adding features to, and it was aspnet core 1.1. I am migrating it to 2.0.
I use Visual Studio for Mac, and it's up-to-date.
I am following this documentation:
https://learn.microsoft.com/en-us/aspnet/core/migration/1x-to-2x/
The exact error I'm getting is:
The predefined type `System.Object' is not defined or imported

I found the answer:
In VS for Mac, it didn't let me get to a menu for selecting the target framework for a project. This is usually opened by right-clicking the project, and selecting "properties."
VS for Mac didn't show this.
Upon using my windows install on my iMac, I found the menu and saw AspNetCore2.0 wasn't listed (but 1.0 and 1.1 were). There was also another option to install more. this led me to:
https://www.microsoft.com/net/targeting?utm_source=getdotnetsdk&utm_medium=referral
At this page, there are SDK's for the AspNet Core 2.0 for macOS and windows 64-bit. You need to install these, and then it'll build.
The fact that visual studio doesn't indicate that you're missing a selected framework for the project you're trying to build (as defined in its config file) is absurd. They need to fix this to avoid these kind of headaches. I was under the impression that it wasn't needed, as the NUGET package for 2.0 had all o this.

Related

How do I fix missing NuGet references?

I'm using Visual Studio Professional 2017, version 15.6.6. A co-worker gave me a solution which he says I should be able to open and rebuild without any problems. There seems to be something wrong with either the NuGet packages and/or Framework. Co-worker will only say it must be something wrong with my computer, so I'm hoping someone here can help.
I tried right clicking on the solution and picking "Restore NuGet Packages". The references still have the yellow triangle by them. I tried to rebuild anyway and got the message "The reference assembilies for framework ".NETFramework, Version=v6.0" were not found. I looked at the project properties and saw the target framework was blank. I tried choosing .NET Framework 4.6, but that gave me multiple errors of the type "Package [name of NuGet package] is not compatible with net46(.NETFramework, Version=v4.6)." The co-worker had mentioned trying .NET Core before, so I tried downloading .NET Core 3.1 from this site: https://dotnet.microsoft.com/en-us/download/visual-studio-sdks?cid=getdotnetsdk. I installed it (including restarting my computer), but don't see .NET Core in the Target framework. Can anyone help guide me getting this solution running?
Here's an image showing the missing references (yellow triangle) on the right and the reference error message when I tried to rebuild.
Here's an image after I set the framework to 4.6 and showing the target framework choices I have available:
We can see that:
.NET 6 is supported by Visual Studio 2022 and Visual Studio 2022 for Mac (and later versions).
You can update to VS2022 and try again.

How to create a managed plugin for Unity with Visual Studio Community for Mac

I'm going to create my first managed plugin for Unity (2018.2) using Visual Studio Community for Mac (7.6.11 build 9).
I've read the documentation but I think that the step-by-step instructions are not meant to be followed on Visual Studio Community for Mac.
As you can see in the screenshot below, I've created several projects using each and every library template available.
All of them compiled successfully to a DLL targeting versions of .NET framework that are incompatible with Unity.
The only project I could change the .NET framework version to match Unity's 3.5 is the one based on the Other > .NET > Library.
Everything works fine but I'd like to know if the assumptions, the process and the final result are correct. Can you tell me, please?
I don't know the difference between the "Class" and the "Class Library" option but you're supposed to use the "Class Library" option. This is not the main point of this answer.
Two future issues you haven't solved yet:
1. Referencing Unity's API.
If you ever have to use any Unity library or API in youir plugin such as Vector3, you need to add Unity's UnityEngine.dll to your library settings. If you don't, you will run-time exceptions.
Go to Project --> Add Reference ---> Browse ---> Browse Button
then select <UnityInstallationDirecory>\Editor\Data\Managed\UnityEngine.dll. You can now build your managed plugin. Since you're using Mac, this path is different on your OS. On Mac, this could be /Applications/Unity/Unity.app/Contents/Frameworks/Managed/UnityEngine.dll. You just have to find where UnityEngine.dll is located.
2. Invisible stack trace
With your current setup, if you run into error with your managed plugin, the stack trace won't be there. You won't have the file names and line numbers and this makes is very hard to debug your plugin code.
When you build the project, Visual Studio generates a PDB file instead of an MDB file. Unity can't use this directly. You have to convert the PDB files into MDB files.
From command line, run this:
<UnityInstallationDirecory>\Data\MonoBleedingEdge\lib\mono\4.5\pdb2mdb.exe UnmanagedPlugin.dll
Again, the path might be different on Mac, you just need to find "pdb2mdb.exe" that converts the PDB files into MDB files.
After that, copy the MDB and dll file into the "Assets" folder in your Unity project.

Adding System.Data.SQLite through NuGet doesn't add a reference to the project

I'm trying to make a very simple Xamarin.Forms test application to explore some features of the System.Data.SQLite package (namely encryption). However, I can't seem to get Visual Studio 2012 to add a reference to the package to the project.
Here are the steps I am taking:
Created a new Xamarin.Forms Portable blank app.
Right-click on TestApp (core project) and select Manage NuGet Packages
Search for "sqlite"
Install the "System.Data.SQLite (x86/x64)" package. (This package is version 1.0.97.0 and it is described as "the official SQLite database engine for both x86 and x64 along with the ADO.NET provider.")
According to NuGet, the package was successfully installed.
However, I cannot see the reference added under my project's "References" folder, and I also cannot write "using System.Data.SQLite" without errors ("cannot resolve symbol 'Data'"). Does anyone have any idea why this is happening?
On a side note, I can follow the exact same process described above except instead of creating a Xamarin.Forms Portable blank app, I choose a regular C# console app. This allows me to install the NuGet package fine and it shows up in references as expected.
Posting an update to share what I've learned.
So as Jason sort of alluded to in his answer, the reason I was not able to reference the package in my Xamarin.Forms project is because Xamarin.Forms is, by definition, a PCL project. It's meant to work on all platforms. The package I was referring to in my question is not a PCL, which means that anything in the package that is platform dependent is inaccessable (which is basically the entire package). The SQLite.Net-PCL package is basically the same thing as System.Data.SQLite, but in PCL form, which means it is compatible for use in a Xamarin.Forms project.
Following this logic, it makes sense that I was able to access System.Data.SQLite from a console project, since a console project is not a PCL project and it targets a specific platform.
For PCL projects, use SQLite.Net-PCL.

cannot build in release only in debug

I have a project built in VS 2013, for some reason I cannot build in release mode only debug mode. If I build in release mode I get a bunch of errors that doesn't really seem relavant. Anyone got any suggestion on where to begin looking for errors?
From your error I can guess that you're using an external library, either through NuGet or locally.
You have to set up the environment to use this library in both release and debug mode. That means installing it on either one through NuGet or setting up the correct include/library paths in the project settings.
In my case it was an unrelated Nuget package that had a higher .Net Framework version than my project.
I had a similar problem, with the same error of Invalid pointer, and it turned out that I had uninstalled Telerik from machine.
1. Make sure that you have Telerik installed , on my machine it is under "C:\Program Files (x86)\Telerik\UI for ASP.NET AJAX Q3 2015\"
The file "Telerik.Web.UI.dll" is available in the Bin[nn]-folders, select the one you want (perhaps the latest version).
2. In visual studio; if your reference to "Telerik.Web.UI" has a yellow warning triangle it indicates that Visual Studio cannot locate the dll file.
Add new reference by browsing your Telerik Bin[nn] folder and selecting the file "Telerik.Web.UI.dll" (and repeat this for all projects using the Telerik components in your solution)

Target Framework does not change in Visual Studio 2010

When I change the target framework of any project in Visual Studio 2010 it does not actually change the System assembly references. For example if I target v2.0 and check the properties of System and System.Data I can see that they are still both v4.0. If i change the target to v3.5, System stays at v4.0 but System.Core changes to v3.5.
Because of this I am truly not targeting anything except v4.0.
There may be something strange in your install. I just created a WPF project, keeping the default settings, thus targeting .NET 4. Then, I switched to 3.5. VS asked to reload the project and then the targeted runtime of the references was v2 (correct) and their version was 3.5 (with an error that Microsoft.CSharp and System.Xaml were missing, which is understandable).
Then, I did the same for .NET 3 and 2 and got the same results: after reloading the project, the version of the referenced DLLs had changed were it made sense (System.Data is always v2.0).
When using the CLR v2, the vshost debug helper had its name changed to something like vshost-clrv2.
I've reinstalled Visual Studio several times and it hasn't solved anything. After uninstalling there is 10.0 stuff laying all over the place leading me to believe the uninstaller is also leaving what ever is causing this issue. I'm going to have to reinstall the OS to get the issue to go away.
I also wanted to link to my earlier post because this post has more information about how I originally discovered this issue, contains a link to the Microsoft Connect bug report I opened and links to several other users experiencing the same problem: Visual Studio 2010 Can no longer build .NET v3.5

Resources