Dapper and .net core 3 - asp.net-core-mvc

Im new to .netcore and trying to use dapper for some db interactions. Does dapper not work with .net core 3? Or am I doing something wrong :X
I created a new .net project:
dotnet new mvc
tried to add dapper
dotnet add package Dapper --version 2.0.30
Then I get the error:
info : Adding PackageReference for package 'Dapper' into project
C:\repos\dapper\dapper.csproj'.
info : Restoring packages for C:\repos\dapper\dapper.csproj...
error: Cycle detected.
error: dapper -> Dapper (>= 2.0.30).
info : Package 'Dapper' is compatible with all the specified frameworks in project 'C:\repos\dapper\dapper.csproj'.
error: Value cannot be null. (Parameter 'path1')

The reason is that csproj has the same name as the dependant PackageReference dapper,refer to https://github.com/NuGet/Home/issues/6754
A project and a dependency cannot have the same name.
Change the name of your project(not using dapper) will overcome it.

Related

Blazor Server project is not running after installing Blazorise.Snackbar component

In my Blazor Server project I have been using blazorise controls. I started this project 3 months before. Now I wanted to use Blazorise.Snackbar component. So I ran nuget package command to install the component. Now my project is not running. It shows exception in the below lines of code in the Program.cs file
builder.Services.AddBlazorise(options => { options.Immediate = false; })
.AddBootstrap5Providers()
.AddFontAwesomeIcons()
.AddBlazoriseRichTextEdit();
The error message is:
System.TypeLoadException: 'Method 'FocusTrap' in type
'Blazorise.Bootstrap5.Bootstrap5ClassProvider' from assembly
'Blazorise.Bootstrap5, Version=1.0.4.0, Culture=neutral,
PublicKeyToken=null' does not have an implementation.'
My Current Packages version:
Can anyone help me to solve the problem?
You should use the same version on all Blazorise packages to ensure that they are compatible with each other. Changing Blazorise.Snackbar version to 1.0.4 will fix your problem.

dotnet cli <> VS2017 nuget packages restore errors

I've used dotnet cli (2.0.0) to create 2 projects:
dotnet new webapi (name: webapiProject)
dotnet new xunit (name: testProject)
after that, on testProject project:
dotnet add reference webapiProject
test project is an integration test and it uses webapiProjects Startup.
when i do dotnet run on xunit one, all works fine. tests run, references work, all good.
But, when i load testProject.csproj in VS2017 (15.3.3), i get nuget NU1105 error:
Severity Code Description Project File Line Suppression State
Error NU1105 Unable to find project information for 'webapiProject'. The project file may be invalid or missing targets required for restore.
I am actually rather new to dotnet cli and i am not even sure i should be loading *.csproj in VS2017 but i did so because when i opened only my test class then i didn't have intellisense for it.
So, any advice would be highly appreciated about both:
the error
correct workflow

"No executable found matching command dotnet-ef" error with EF Core database-first

As you know, the newest version of Visual Studio 2017 abandons the 'project.json' and uses .csproj instead.
I'm using the RTM version and want to generate model from an exist database, following this guide. I got an error on the last step:
The Entity Framework Core commands for the Package Manager Console don't yet support csproj-based .NET Core projects. Use the .NET Command Line Tools (i.e. dotnet ef) instead. For more details, see https://go.microsoft.com/fwlink/?linkid=834381.
Following the error, I used the link it mentioned to switch to dotnet ef. Here is my package manager command:
PM> dotnet ef dbcontext scaffold "Server=.;Database=Jumpstart;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer
Then the error comes again:
dotnet : No executable found matching command "dotnet-ef"
I used the help command, I found that dotnet does not have a command called ef.
I just want to generate a model from an existing database.
Follow this tutorial
https://learn.microsoft.com/en-us/aspnet/core/data/ef-mvc/migrations
I had the same problem. Just edited the ItemGroup section in .csproj like this
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="1.0.0" />
</ItemGroup>
Accepted answer is the most probable cause of the error message. However, besides adding the proper reference within .csproj file also make sure that the current directory from Package Manager Console points to ASP.NET Core project, otherwise any dotnet ef command will fail with the error mentioned in the OP title.
My issue was solved by changing tools to:
"tools": {
"Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.1.0-preview4-final",
"Microsoft.EntityFrameworkCore.Tools.DotNet": "1.1.0-preview4-final"
},
Then execute these 2 commands:
dotnet restore - to restore packages
dotnet ef migrations
I solved the problem
in all answer mentioned adding Tools DotNet but not solved my problem because missed some command I mention below
The EF Core .NET Command Line Tools are installed by manually editing the *.csproj file.
Add Microsoft.EntityFrameworkCore.Tools.DotNet as a DotNetCliToolReference. See sample project below.
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="1.0.0" />
</ItemGroup>
for core version 2 changed the version
but after that should run 2 commands too
then importatn part in all answer missing (this command solved my problem in visuall studio 2017)
1 - Execute dotnet add package Microsoft.EntityFrameworkCore.Design
2 - Execute dotnet restore. If restore does not succeed, the tools may not have installed correctly.
more information
https://learn.microsoft.com/en-us/ef/core/miscellaneous/cli/dotnet
On NetCore 2.0 you just need to run Add-Migrations.
It will ask for a name and that's all. Just be sure you have a default connection string on appsettings.json

System.Web.Http.GlobalConfiguration does not contain a definition for 'Configure

In global asax cs file i have this line:
protected void Application_Start()
{
GlobalConfiguration.Configure(WebApiConfig.Register);
}
which causes this error.
I have tried as suggested on other forums:
Open the Package Manager Console for the project with the error.
Type in Install-Package Microsoft.AspNet.WebApi.WebHost and hit Enter
Rebuild your project and all should be right with the world (or at least right with your project)
The output was:
Attempting to resolve dependency 'Microsoft.AspNet.WebApi.Core (≥ 5.2.2 && < 5.3.0)'.
Attempting to resolve dependency 'Microsoft.AspNet.WebApi.Client (≥ 5.2.2)'.
Attempting to resolve dependency 'Newtonsoft.Json (≥ 6.0.4)'.
'Microsoft.AspNet.WebApi.WebHost 5.2.2' already installed.
SM.EORD.Web already has a reference to 'Microsoft.AspNet.WebApi.WebHost 5.2.2'.
and error is still there. What could be wrong?
br, Simon
After hours of investigating i have found out that after I have installed ASP.NET Web API 2.2, the reference path of all dlls was from some old Web API - it didn't take the new ones.
The new dlls has been installed in packages folder, while the old one were in bin folder inside project.
if you want to update your references as well next time try upgrading from the package manager console you can update all or just specify the package name. Update package will upgrade vs installing a new package and you have manually go update your references.
Update-Package
In my case, the problem was that I renamed the Namespace of my project, and I did not know I needed to manually edit the namespaces section of the Views\Web.Config to match my new namespace.

VS2010 Build of .NET v3.5 projects fail due to a potential .NET v4.0 reference

Attempting to build a Visual Studio 2010 solution with 132 projects which do not use any file references (only project references). When I build the entire solution, I get many build errors like this:
The type or namespace name 'xxxx' does not exist in the namespace '<namespace name>' (are you missing an assembly reference?)
The target framework version for ALL projects in the solution is v3.5.
Hence I started building projects one by one based on the Project Build Order. And on one of the projects (say project A), I get the below info in the Build Output (note the framework version). This project A builds successfully.
When I build the next project, say project B, which references project A through a project reference (not file reference), then it throws the above build error. Hence it seems project B is the culprit.
Compile complete -- 0 errors, 54 warnings
<ProjectName> -> <filepath>\<filename>.dll
Microsoft (R) .NET Global Assembly Cache Utility. Version 4.0.30319.1
Copyright (c) Microsoft Corporation. All rights reserved.
Details of project B
Solution configuration is Debug.
In the References tree of project B, the properties of the project A reference shows
1) "Runtime Version" as v2.0.50727.
2) "Copy local" as True.
3) "Strong Name" as True.
4) "Version" as 1.0.xxxx.xx (as specified in the AssemblyInfo.cs of project A)
5) There is no "Specific Version" key (because it is a project reference)
the AssemblyInfo.cs of project B has the following:
1) [assembly: ComVisible(false)]
2) [assembly:Guid("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx")]
3) [assembly:AssemblyVersion("1.0.xxxx.xx")]
4) [assembly:AssemblyFileVersion("9.0.xxxx.xx")]
the project B properties has the following:
1) "Target Framework" as ".NET Framework 3.5"
2) "Output Type" as "Class Library"
3) "Treat warnings as errors" as "None"
My Question(s)
Now, the target framework specified in the properties of ALL my projects is .NET Framework 3.5.
How does the build engine use a GAC Utility of v4.0 when my target framework is v3.5?
Searched all files to see if .NET 4.0 is configured somewhere but could not find it.
This seems to be potentially the root cause of the above issue. Or am I missing something else? I believe I have covered the usual suspects.
Also why does the Runtime Version of project A reference in project B say v2.0.50727 when the target framework version for both projects is v3.5?
PS:
I tried removing the project reference and adding its file reference instead, still gives the same build error. (This usually used to work before when it was a long name issue but its not in this case).
UPDATE 1:
The build output for the above build error is:
Compile complete -- 13 errors, 0 warnings
C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(1360,9):
warning MSB3258: The primary reference "<project A reference name>" could not be resolved
because it has an indirect dependency on the .NET Framework assembly
"mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=xxxxxxxxxxx"
which has a higher version "4.0.0.0" than the version "2.0.0.0" in the current target framework.
UPDATE 2:
The Post-build event command-line for project A has the following which explains why the build uses the GAC Utility of v4.0! Now I need to figure how to get the v3.5 Gacutil in there.
My second question still stands though.
cd "$(ProjectDir)"
cd ..\..\..\Bin
gacutil.exe /if "$(TargetPath)"
To answer your second question:
.Net 3.0 and .Net 3.5 are simply new DLLs that run on the existing CLR 2.0.
There are no runtime versions between 2.0 and 4.0.

Resources