Project referencing Portable Class Library gives error in Visual Studio Code - visual-studio-code

I create a console application in Visual Studio 2015 RC and add Automapper 3.3.1 using nuget to the project.
If I then add the following snippet to my project:
public class Class1
{
public void Test()
{
AutoMapper.Mapper.Map<B>(new A());
}
}
And then open the same project in Visual Studio Code preview on Windows 10 then I get a red squiggly on the Map function.
The error message says:
The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e, Retargetable=Yes'.
My project is configured to use .NET 4.52 and there are absolutely no errors or warnings when building the same project using visual studio 2015 RC or using MSBuild from the command line.
Automapper is portable class library and this is what seems to trigger the problem.
Is this a known issue with Visual Studio Code or Omnisharp?
Are there any way to suppress these error messages?
Update:
I have now tested with VS Code version 0.3 and it is still not fixed.
To make it even simpler to reproduce I have also verified that the problem also exist for a ClassLibrary project containing only the 3 classes: Class1 as shown and class A and class B, which are just two dummy classes used to have something to map.
It does not matter which version of Visual Studio is used to create the project. The same problem exist if I create the class library project using VS 2013.

Maybe you added the reference in both dnx451 and dnxcore50 in project.json file.
I think the problem is Automapper did not support .NET Core 5.0, please refer this article for more detail about .NET core 5.0 and .NET framework 4.6.
http://blogs.msdn.com/b/cesardelatorre/archive/2014/11/18/what-is-net-core-5-and-asp-net-5-within-net-2015-preview.aspx.
This might be the limitation of multi-environment in .NET Core 5.0 when using available libraries. You should write by yourself or waiting for other libraries update if you want to use, otherwise, please remove dnxcore50 in project.json.
Happy coding!

This is actually a known issue with the OmniSharp-roslyn server which powers VS Code, see: https://github.com/OmniSharp/omnisharp-roslyn/issues/265
I suspect you might have better luck using the yeoman ASP.NET 5 generator to generate an ASP.NET 5 Console application.
See: http://docs.asp.net/en/latest/client-side/yeoman.html
And http://docs.asp.net/en/latest/dnx/console.html

Related

VS Code - Error check missing in some projects

I made a new solution in .NET with a class library (dotnet new classlib) and an XUnit test project (dotnet new xunit). I then added a reference to the class library, from the test project (dotnet add <test-project> reference <class-library>).
Now I have live error checking (syntax highlighting) in the class library, but no in the test project. You can see an example below, where the class Foo doesn't exist anywhere, but doesn't generate a live warning in the unit test project (it still fails on build).
This is a VS Code issue only. If I open it in Visual Studio 2022, it works just fine.
What's going on here?
Thanks to this answer on Twitter I found a way to fix it...
I had to restart OmniSharp (the C# extension for VS Code). It can be done in the command palette (Ctrl+Shift+P). Search for "OmniSharp" and select "OmniSharp: Restart OmniSharp".

The type or namespace name 'FileIO' does not exist in the namespace 'Microsoft.VisualBasic' in Visual Studio Code

I am using Microsoft.VisualBasic.FileIO; in my C# code in VISUAL STUDIO CODE.
But I am getting the error 'FileIO' does not exist in the namespace 'Microsoft.VisualBasic'
Can anyone please help on how to add the reference for FileIO
enter image description here
Sounds like you are missing the reference to Microsoft.VisualBasic in your project. You will need to add the reference to your project.
Reviewing your screenshot it appears you are using Visual Studio Code. If this is a .NET Core application FileIO is not in the .NET Core library. Assuming you are trying to parse a file you will want to utilize System.IO.FileSystem instead https://www.nuget.org/packages/System.IO.FileSystem/

Method Not Found : Void Microsoft.VisualStudio.PlatformUI.DpiHelperLogicalToDeviceUnits

I need to use ADO.NET Entity Model Object in my project but when I select to add the item from Visual Studio 2013 Template dialog, I instead encounter the error below.
Method Not Found : Void Microsoft.VisualStudio.PlatformUI.DpiHelperLogicalToDeviceUnits
Does anyone know what I need to do to get rid of this?
I am on a Windows 7 machine, with Visual Studio 2013 and current SDKS installed
There is a bug in the version of the designer included in this CTP that will cause the error to appear when trying to use the EF Tools.
Fix is here
http://blogs.msdn.com/b/adonet/archive/2014/08/18/visual-studio-14-ctp-3-and-entity-framework.aspx

Can't compile project after importing stored procedure

After importing a stored procedure into my datamodel the project stopped compiling.
It keeps giving me error:
The best overloaded method match for
'System.Data.Entity.Core.Objects.ObjectContext.ExecuteFunction<TicketDataModel.sp_get_orphanjobgrades1_Result>
(string, params System.Data.Entity.Core.Objects.ObjectParameter[])'
has some invalid arguments C:\Users\nikolaev\Documents\MySoft\TicketManager-06 11 2013\TicketManager\TicketDataModel\TicketDataModel\TicketEntities.Context.cs 105 20 TicketDataModel
and
`Argument 3: cannot convert from 'System.Data.Objects.ObjectParameter' to
'System.Data.Entity.Core.Objects.ObjectParameter'
C:\Users\nikolaev\Documents\MySoft\TicketManager-06 11 2013\TicketManager\TicketDataModel\TicketDataModel\TicketEntities.Context.cs 79 143 TicketDataModel`
The code in context.cs is as follows:
public virtual ObjectResult<sp_get_orphanjobgrades1_Result> sp_get_orphanjobgrades1(Nullable<System.DateTime> start_date, Nullable<System.DateTime> end_date)
{
var start_dateParameter = start_date.HasValue ?
new ObjectParameter("start_date", start_date) :
new ObjectParameter("start_date", typeof(System.DateTime));
var end_dateParameter = end_date.HasValue ?
new ObjectParameter("end_date", end_date) :
new ObjectParameter("end_date", typeof(System.DateTime));
return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction<sp_get_orphanjobgrades1_Result>("sp_get_orphanjobgrades1", start_dateParameter, end_dateParameter);
}
I read that this may be because of EF 6 and that one needs to download VS 2012 Update 1 and/or EF 6 Tools for VS 2012. I downloaded the tools and I already have update 4 installed, but that doesn't help.
Why is this?
The problem is that your model don't know anything about new parameters. I guess that it happens when your model using EntityFramework (EF) lower version (5.0 for example), but in code you are trying to use EF 6.0.
So, you should either downgrade your code to EF 5.0, or upgrade your model to 6.0.
Upgrading model:
Open Tools -> NuGet Package Manager -> Package Manager Console;
Choose project, that contains your model as Default project on the
top of Console.
Type "Uninstall-Package EntityFramework" and press Enter;
After removing, type "Install-Package EntityFramework -version
6.0.0" and press Enter again;
Go to YourModelName.Context.cs and YourModelName.Context.tt and replace "using
System.Data.Objects; using System.Data.Objects.DataClasses;" with "using
System.Data.Entity.Core.Objects;". Also, you may need to make the
same in all files, where this problem appears.
Or you can downgrade EF version, used in your code. For this, you should do all the same in first 3 steps but in the fourth replace "-version 6.0.0" with "-version 5.0.0". The 5th step is not needed for this.
To fix this issue:
If version conflicts, install package for respective version of EF.
If version is same, change the above namespace to System.Data.Entity.Core.Objects
You can download new verions in msdn.
Download Tools for Entity Framework 6.1.0 or new versions
in http://www.microsoft.com/en-us/download/details.aspx?id=40762
Use in Package Manager Console
Install-Package EntityFramework -version 6.1.0 and enter
Restart your visual studio.
4.Check your package Manager and finish.
I just want to add that this happened to me after starting a brand new project. The issue was that I had created a new project, and then proceeded to update the Entity Framework, ASP.Net MVC, and other packages through the NuGet Package Manager. So, the code generated for my project no longer matched what I had installed.
The quickest solution for me was to just create a new project since I hadn't done any real work yet. I hope this helps somebody else out there.
My situation was a new project, and I went to nuget with Install-Package EntityFramework which installed the 6.0 version, however apparently my project was already set up with an earlier version? Not sure how, maybe the default of MVC 4.0 project...
So I had to do an Uninstall-Package -force EntityFramework followed by
Install-Package EntityFramework -version 5.0.0
Everything worked after that.

A constructible type deriving from DbContext could not be found in the selected file (EF Power Tools Beta 2 + VS 2012))

I'm using VS 2012 (Ultimate) together with Entity Framework Power Tools Beta 2 and entity framework 5.0 (using nuget).
I've created a DbContext class. When I right-click on the corresponding file in the solution explorer and select "Entity Framework / View Entity Data Model (Read-only)", I get the error "A constructible type deriving from DbContext could not be found in the selected file." error in VS 2012.
I tried the workaround described at http://blogs.msdn.com/b/adonet/archive/2012/04/09/ef-power-tools-beta-2-available.aspx, but my registry does not contain the key "{BFC24BF4-B994-4757-BCDC-1D5D2768BF29}" in "HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\11.0_Config\BindingPaths\".
After restarting visual studio and following the same steps, a dialog pops up indicating "Exception has been thrown by the target of an invocation".
BTW. I'm able to execute my test application that creates the database from my DbContext and O can insert/delete/etc data in this database.
Any help/hints would be very appreciated.
Kind regards,
Merijn
Uninstalling VSCommands for Visual Studio 2012 should get things working again. Unfortunately, this extension does not play nicely with the EF Power Tools. It loads it's own version of EntityFramework.dll into the main VS process which prevents the DbContext discovery logic from working properly.
As mentioned by Brice, this may be caused by compatibility issue with Visual Studio Extensions.
Latest version of VSCommands fixes this problem. You can get if from Visual Studio Gallery.
Many thanks to Brice and EF Team for their help in diagnosing the problem!
Having seen this error intermittently even without the extensions listed in the other answers, I found deleting the solution's local .suo file worked - although this was very much a when-all-else-fails answer!
I had a similar issue with a different Visual Studio Extension. In my case it was Visual Studio Tools for Git (Version 1.0.0.0).
I just disabled the extension, restarted VS2012 and I was able to use generate the model from a code first EF project.