Unable to use Box API after installing nuget package - c#

I started using Box.V2 in my asp dotnet core app in VSCode, but I was getting all kinds of annoying errors.
After finding that there is a specific nuget package for dotnet core, I uninstalled my existing box packages and installed Box.V2.Core - it appears to have installed successfully as I can see it on my installed packages list.
However, When I try using Box.V2.Core I get a
The type or namespace 'Box' could not be found
What am I supposed to do with this? Does the package actually not exist?
My csproj file:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="BuildBundlerMinifier" Version="2.6.362"/>
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.3"/>
<PackageReference Include="System.Runtime.InteropServices" Version="4.3.0"/>
<PackageReference Include="Microsoft.Windows.Compatibility" Version="2.0.0-preview1-25914-04"/>
<PackageReference Include="HtmlAgilityPack.NetCore" Version="1.5.0.1"/>
<PackageReference Include="RestSharp" Version="106.2.1"/>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.0.1"/>
<PackageReference Include="Box.V2.Core" Version="3.4.1"/>
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.1"/>
</ItemGroup>
</Project>

Something strange is definitely going on with that package. I suggest first installing one release down: <PackageReference Include="Box.V2.Core" Version="3.3.0" /> and then updating it back to 3.4.1.

Related

Azure function v4 migration. Could not load file or assembly 'Microsoft.Extensions.Configuration.Abstractions, Version=7.0.0.0, Culture=neutral

I'm currently migrating an Azure Function from v2 to Azure Functions v4. I already migrated my project to .NET6 and fixed all the package reference errors. I have in the solution 3 projects which I adjusted to .NET6 and Azure Function v4. For that I edited the .csproj files of each of those projects and upgraded/substituted packages which are not working with .NET6. The project file of each project looks like:
Azure Function Project:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<AzureFunctionsVersion>v4</AzureFunctionsVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Azure.Messaging.ServiceBus" Version="7.11.1" />
<PackageReference Include="Azure.Messaging.EventHubs" Version="5.7.5" />
<PackageReference Include="DocumentFormat.OpenXml" Version="2.18.0" />
<PackageReference Include="Microsoft.Azure.WebJobs" Version="3.0.33" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.EventHubs" Version="5.1.2" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.ServiceBus" Version="5.8.1" />
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="Microsoft.Extensions.Azure" Version="1.6.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="7.0.0" />
<PackageReference Include="Microsoft.Identity.Client" Version="4.48.1" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.1.3" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\PCM.1.z\x.1.z.csproj" />
</ItemGroup>
<ItemGroup>
<Compile Update="2.cs">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Compile>
<Compile Update="1.cs">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Compile>
<Compile Update="3.cs">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Compile>
</ItemGroup>
<ItemGroup>
<None Update="host.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="local.settings.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>
</ItemGroup>
</Project>
Second Project:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Azure.Messaging.ServiceBus" Version="7.11.1" />
<PackageReference Include="Azure.Messaging.EventHubs" Version="5.7.5" />
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.21.0" />
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
<PackageReference Include="Microsoft.Azure.Devices" Version="1.38.2" />
<PackageReference Include="Microsoft.Azure.WebJobs" Version="3.0.33" />
<PackageReference Include="SendGrid" Version="9.28.1" />
<PackageReference Include="StackExchange.Redis" Version="2.6.80" />
<PackageReference Include="Twilio" Version="6.0.1" />
<PackageReference Include="UnitsNet" Version="4.149.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\x.1.w\x.1.w.csproj" />
</ItemGroup>
</Project>
Third Project:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.0" />
</ItemGroup>
</Project>
When I build the project I got no errors. But when I debug the project I got an exception which looks like:
Exception:
Exception thrown: 'System.IO.FileNotFoundException' in Microsoft.Azure.WebJobs.Host.dll.
An exception of type 'System.IO.FileNotFoundException' occurred in Microsoft.Azure.WebJobs.Host.dll but was not handled in user code
Could not load file or assembly 'Microsoft.Extensions.Configuration.Abstractions, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.
I have tried the last two weeks different packages since when I googled this error, the suggestion was to see which packages are not supported by package:
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.1.3" />. I analyzed all my packages. After changing them back and force I got still the same error.
Can anyone help me and say what exactly I have to change?
As #Codebrane said, Microsoft.Extensions.Configuration.Abstractions, Version=7.0.0.0 has the issues in working with Azure Functions v4 Version and it has been shown practically in this thread.
Try by downgrading the Microsoft.Extensions.Configuration.Abstractions to Version 6.0.0 and check.
Microsoft.NET.Sdk.Functions depends on the NuGet Packages related to the Code but these can be suggested by VS IntelliSense and installed automatically, or it shows these packages required.
Also, NuGet Packages varies between In-Process and Out-of-Process worker type in Azure Functions. Refer to one of my threads for more information.
I am building an Azure function as v4 in net6. Since I also got the System.IO.FileNotFoundException regarding library Microsoft.Extensions.Configuration.Abstraction 7.0.0 when starting up the function,
I downgraded to Microsoft.Extensions.Configuration.Abstractions 6.0.0 and also had to downgrade other dependencies such as Microsoft.EntityFrameworkCore to 6.0.12 and, since I am using PostgreSQL also Npgsql.EntityFrameworkCore.PostgreSQL to 6.0.8. Now everything works.
I fixed it by including the package Microsoft.Extensions.Configuration.Abstractions 6.0.0 and building it. To include this package doesn't solve the problem directly it just shows which packages have a conflict. By downgrading these conflicting packages the project could be debugged. To check which packages are conflicting you have to open up the packages on the right side in visual studio and look where is a exclamation mark. Then you have to analyze these packages to know on what version you have to downgrade them. It changes from project to project.

VS Code / OmniSharp failing to load project; Can't find a package that is present

When I start up VS Code or restart OmniSharp, I get the following error message:
[info]: OmniSharp.MSBuild.ProjectManager
Loading project: /Users/user/Documents/repos/proj/proj-backend/Application/Application.csproj
[fail]: OmniSharp.MSBuild.ProjectLoader
Package Microsoft.EntityFrameworkCore.Analyzers, version 3.1.5 was not found. It might have been deleted since NuGet restore. Otherwise, NuGet restore might have only partially completed, which might have been due to maximum path length restrictions.
[warn]: OmniSharp.MSBuild.ProjectManager
Failed to load project file '/Users/user/Documents/repos/proj/proj-backend/Application/Application.csproj'.
/Users/user/Documents/repos/proj/proj-backend/Application/Application.csproj
/usr/local/share/dotnet/sdk/3.1.301/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(234,5): Error: Package Microsoft.EntityFrameworkCore.Analyzers, version 3.1.5 was not found. It might have been deleted since NuGet restore. Otherwise, NuGet restore might have only partially completed, which might have been due to maximum path length restrictions.
Here is my csproj file:
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<ProjectReference Include="..\Persistence\Persistence.csproj"/>
<ProjectReference Include="..\Domain\Domain.csproj"/>
</ItemGroup>
<ItemGroup>
<PackageReference Include="MediatR" Version="8.0.0"/>
<PackageReference Include="MediatR.Extensions.Microsoft.DependencyInjection" Version="8.0.0"/>
<PackageReference Include="Newtonsoft.Json" Version="12.0.3"/>
<PackageReference Include="RestSharp" Version="106.10.1"/>
<PackageReference Include="Microsoft.IdentityModel.Tokens" Version="5.6.0"/>
<PackageReference Include="StandardModels" Version="0.1.3.15"/>
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="5.6.0"/>
<PackageReference Include="Microsoft.Extensions.Logging" Version="3.1.5"/>
<PackageReference Include="EPPlus" Version="5.1.1"/>
<PackageReference Include="AutoMapper" Version="9.0.0"/>
<PackageReference Include="Microsoft.EntityFrameworkCore.Analyzers" Version="3.1.5"/>
</ItemGroup>
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
</Project>
dotnet restore --no-cache works fine and building/running has no errors. I tried removing Microsoft.EntityFrameworkCore.Analyzers but it doesn't make a difference.
Any ideas why I can't get this to load?
Thanks in advance!
I resolved this issue by deleting the entire repository, recloning, and creating a new workspace file. The combination of those actions did the trick.

DynamicRouteValueTransformer does not exist

I get a missing reference error when I try to inherit from the class DynamicRouteValueTransformer in a class library but when I do it from my MVC app it works fine.
public class ProductRouteTransformer : Microsoft.AspNetCore.Mvc.Routing.DynamicRouteValueTransformer
DynamicRouteValueTransformer is in namespace Microsoft.AspNetCore.Mvc.Routing which is part of Microsoft.AspNetCore.Mvc.Core.dll. I've added the DLL to the class library using Nuget and can see that it is installed but I still get a missing reference error. The class is just missing from the namespace.
I'm using .NET Core 3.1.
The csproj is below:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AutoMapper" Version="9.0.0" />
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="7.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Http.Extensions" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Abstractions" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.2.5" />
<PackageReference Include="Microsoft.AspNetCore.Routing" Version="2.2.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.0" />
<PackageReference Include="NLog" Version="4.6.8" />
</ItemGroup>
<ItemGroup>
<Folder Include="Database\EntityUtils\" />
</ItemGroup>
</Project>
There's a topic in the docs that was introduced recently, which covers this in great detail:
With the release of .NET Core 3.0, many ASP.NET Core assemblies are no longer published to NuGet as packages.
If you take a look at the contents of your .csproj, you'll see that you've added references to 2.2.x versions of a few Microsoft.AspNetCore.* packages. I'm sure you intended to reference 3.1.x versions of these, but, as the docs quote above shows, these packages are no longer produced for 3.0+.
The next few lines from the docs explain what's happened here:
Instead, the assemblies are included in the Microsoft.AspNetCore.App shared framework, which is installed with the .NET Core SDK and runtime installers.
As of .NET Core 3.0, projects using the Microsoft.NET.Sdk.Web MSBuild SDK implicitly reference the shared framework. Projects using the Microsoft.NET.Sdk or Microsoft.NET.Sdk.Razor SDK must reference ASP.NET Core to use ASP.NET Core APIs in the shared framework.
As your project is referencing Microsoft.NET.Sdk, you'll need to add a FrameworkReference, as described above, and remove those old PackageReferences:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="AutoMapper" Version="9.0.0" />
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="7.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.0" />
<PackageReference Include="NLog" Version="4.6.8" />
</ItemGroup>
<ItemGroup>
<Folder Include="Database\EntityUtils\" />
</ItemGroup>
</Project>
Note that not all of the packages have been folded into the shared framework. For example, Microsoft.EntityFrameworkCore.SqlServer is still provided as a NuGet package.

Problem adding initial migration and my configuration and services don't have references

I just started learning how to create asp.netcore web applications using mvc 2.0 pattern...i encountered;Problem adding migration...and most of the configuration and services in my startup.cs don't have any reference hence they dont change color.I was told I have to install one nuget package but I already installed some...it is still not working. Hence I can't add initial migration. In the picture above I have included an evidence of the Nuget packages I installed on my system
Try to add Microsoft.EntityFrameworkCore.Design in your project.
If you are using asp.net core 2.2(2.1+), you do not need to add additional EF core packages which are included in the Microsoft.AspNetCore.App metapackage. The default .csproj file is:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<UserSecretsId>aspnet-{Project Name}-{GUID}</UserSecretsId>
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.2.0" />
</ItemGroup>
</Project>
For asp.net core 2.0,
<Project Sdk = "Microsoft.NET.Sdk.Web" >
< PropertyGroup >
< TargetFramework > netcoreapp2.0</TargetFramework>
<UserSecretsId>aspnet-{Project Name}-{GUID}</UserSecretsId>
</PropertyGroup>
<ItemGroup>
<PackageReference Include = "Microsoft.AspNetCore.All" Version="2.0.9" />
<PackageReference Include = "Microsoft.EntityFrameworkCore.Tools" Version="2.0.3" PrivateAssets="All" />
<PackageReference Include = "Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.0.4" PrivateAssets="All" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include = "Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.3" />
<DotNetCliToolReference Include = "Microsoft.Extensions.SecretManager.Tools" Version="2.0.2" />
<DotNetCliToolReference Include = "Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.4" />
</ItemGroup>
</Project>
You could show your .csproj file(Right-click project -> Edit csproj) and check the missing packages.
I upgraded my .netcore SDK software to 2.2 so I could run asp.netcore MVC 2.2 since all my nuget packages are versions 2.2.n....it is working well and I've been able to add migration ....thanks to you all for your help

Issue with creating initial migration in ASP.Net Core

I've been working on the basics of an ASP.Net Core MVC Project and I'm wondering why I can't create my initial Migration.
I go into the project folder and run "dotnet ef" in CMD and get an error of "No executable found matching command dotnet-ef".
I figure that this is odd, so I try to build my application in VS2017 and I get this error:
Severity Code Description Project File Line Suppression State
Error NU1605 Detected package downgrade: Microsoft.NETCore.App from 2.0.6
to 2.0.0. Reference the package directly from the project to select a
different version.
FiberLocator -> Microsoft.EntityFrameworkCore.Tools.DotNet 2.0.2 ->
Microsoft.NETCore.App (>= 2.0.6)
FiberLocator -> Microsoft.NETCore.App (>= 2.0.0) FiberLocator
C:\Users\user\Google Drive\ASP.Net Core
Projects\FiberLocator\FiberLocator.csproj 1
My .csproj file looks like this.
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Folder Include="Data\Migrations\" />
<Folder Include="wwwroot\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.2" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.0.3" />
</ItemGroup>
</Project>
From what i understand, the ..Tools.DotNet is the package that gets me the ability to use "dotnet ef". I even tried setting the version to the latest at this time of writing (a preview build even) and it still wouldn't work, giving me the "unknown command" error from above.
How can I change my NETCore.App package to 2.0.0, or allow the Tools.DotNet package to be compatible? There isn't a later version than 2.0.2 on the NuGet site, so I have no idea what to do here.
Any help is appreciated.
Thanks
Microsoft.EntityFrameworkCore.Tools.DotNet is dotnet-ef command line tool. In order to use it in your project change the element referencing it in your csproj from PackageReference to DotNetCliToolReference. Like so:
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.2" />
Version 2.0.2 requires Microsoft.NETCore.App (>= 2.0.6). So you should be ok. For more versions and dependencies have a look at: nuget.org
Microsoft.EntityFrameworkCore.Tools contains equivalent tools, but for Nuget's Package Manager Console in Visual Studio

Categories