Cycles detected
Asked Answered
B

14

17

My project does not add reference to another in the same solution.

I created a project for a website and and abstracted all the parts of the program into .Net Class Libraries (My models in a different class library, Interfaces in a different class library, business logic in a different class library). I referenced all the projects correctly and I also tried creating something I call EntityRepository which I initially kept the DbContext inside. But due to the reason that I wanted to use Microsofts' implementation of Identity and then scaffold the logic out, I could not find the DbContext from the other project which is required when scaffolding so I had to exclude that project out of the solution. Normally when you create a project and select Single user authentication, .Net core adds an initial DbContext into the project. So when scaffolding the implementation of AspNetCore Identity into my project, i have to choose the DbContext. Because of that, my business logic has broken into two sides. The other logic is inside another project in the same solution, the Identity and authentication is inside the startup project which is the web application. When I tried calling the services which implement the business logic from the other project into the web project, it could not add reference to the services project. I now added reference manually. After that I now saw an error written

Detail Error:
Severity    Code    Description Project File    Line    Suppression State
Error   NU1108  Cycle detected. 
  CBTSoftware.Web.Host -> CBTSoftware.Services -> CBTSoftware.Web.Host. CBTSoftware.Web.Host    C:\Users\Tavershima\source\repos\CBTSoftware\CBTSoftware.Web.Host\CBTSoftware.Web.Host.csproj   1```
How can I resolve this?
Bowra answered 7/9, 2019 at 23:50 Comment(3)
How did you add the reference manually? When you can't add the reference "normally" visuual studio has detected that you would create a dependency cycle. Check the usages between CBTSoftware.Services and CBTSoftware.Web.Host and choose for a direction which project should reference the other. You can't have references in both directions.Numb
ApplicationDbContext is located inside the Web.Host project, so I called it inside the services project to do all the database work there. Now I want to call all those services from Services project to the razor pages which is in the Web.Host project.Bowra
I added reference manually by editing the csproj fileBowra
D
2

Consider making a project to contain your EntityRepository, like CBTSoftware.Data, and adding a reference to it from your services project:

CBTSoftware.Services -> CBTSoftware.Data

Then, you can continue referencing your services project from your web project:

CBTSoftware.Web.Host -> CBTSoftware.Services

You'll still be able to configure your EntityRepository in your Startup.cs file because it will know about your CBTSoftware.Data project transitively. Just make sure to remove the reference to your web project from your services project, since this is creating a cycle.

Demoniac answered 8/9, 2019 at 0:50 Comment(0)
S
19

Fist I want to show gratitude to those who answered above because they put on the right track to solving this issue. In my case the issue was caused by untrack files causing NU1108 and was resolved by running git clean -fxd *git clean documentation

Sigurd answered 19/12, 2022 at 16:52 Comment(1)
I'm so glad I stumbled upong your post here! I was already looking for couple hours into this issue without getting one step closer. The git clean did fix the issue. I had strange cycles that only where visible in the referenced packages, but not in the packages themselves. Horrible to pinpoint the issue. So many many thanks I was getting clueless!Catholicism
F
9

I know that this is old but I'd like to add here as well.

I had the same situation as Sebastian Widz answer but what really worked for me was opening the Properties of the problematic project.

This reloaded the project files/dependencies and fixed the "Cycle Detected" issue.

Founder answered 12/9, 2022 at 11:53 Comment(0)
O
6

We also had this problem on Visual Studio 2022, with a project that has a name "containted" in other project namespaces.

The solution for us seems to be to de-check some "preview feature" in VS. In Options > Environment > Preview Features remove these checks.

Visual studio 2022 options

Ovariotomy answered 21/4, 2023 at 12:30 Comment(0)
V
5

In my case the problem had nothing to do with actual dependencies.

One day I opened a solution (which was fine the day before) and could not compile it. NU1108 Cycle detected error was reported in error log for several projects.

Solution:

  1. Examine all projects in the solution, check the solution content.
  2. If for some projects you see wrong content like if the project had files attached from a different project, expand its nodes and wait a bit, VS should refresh the nodes after a while
  3. You may also try to Clean Solution and Reload each project.
Vaudevillian answered 30/8, 2022 at 6:55 Comment(0)
C
4

In my case, I was adding a NuGet package that had a name like the project I created.

The project name was "MassTransit" and the package I needed was also "MassTransit". I renamed the project and I did not face the error again.

Chokecherry answered 25/1, 2024 at 8:6 Comment(4)
I do not see the difference between "MassTransit" and "MassTransit", please be explicit.Snitch
The difference between "MassTransit" as Package name and "MassTransit" as project name is "project"!="package". But why them being identical is a problem does not get clear to me from this answer. Solving it by renaming one of them is then clear again as a solution. (cough, cough, @Snitch )Rajasthan
@Rajasthan I see it now, I read the answer a few times though ;)Snitch
@Snitch Me too, that is why I tried not to give the wrong impression that this is a clear answer. If edits could get a feedback (not necessarily reputation-carrying) I'd click it for yours.Rajasthan
D
2

Consider making a project to contain your EntityRepository, like CBTSoftware.Data, and adding a reference to it from your services project:

CBTSoftware.Services -> CBTSoftware.Data

Then, you can continue referencing your services project from your web project:

CBTSoftware.Web.Host -> CBTSoftware.Services

You'll still be able to configure your EntityRepository in your Startup.cs file because it will know about your CBTSoftware.Data project transitively. Just make sure to remove the reference to your web project from your services project, since this is creating a cycle.

Demoniac answered 8/9, 2019 at 0:50 Comment(0)
M
2

In my case i was naming the project with the same name as the package so that was causing a namespaces conflicts

Misprize answered 19/6, 2023 at 10:4 Comment(0)
F
2

In my case Visual Studio was legitimately defending against a bogus, self-dependency reference.

I had hastily opened an edit window of a project file (ProjectA) to select all project references in order to copy/paste them into another project (ProjectB).

Example of ProjectA's dependencies:

<ItemGroup>
    <ProjectReference Include="..\ProjectB\ProjectB.csproj" />
    <ProjectReference Include="..\ProjectC\ProjectC.csproj" />
    <ProjectReference Include="..\ProjectD\ProjectD.csproj" />
</ItemGroup>

I didn't realize that one of those project references was for ProjectB, which is the same project I pasted all the dependencies into. After that, ProjectB's project file was referencing ProjectB as a dependency.

The solution was to remove the erroneous project reference line in ProjectB's project file:

<ItemGroup>
    <ProjectReference Include="..\ProjectC\ProjectC.csproj" />
    <ProjectReference Include="..\ProjectD\ProjectD.csproj" />
</ItemGroup>
Faulty answered 15/8, 2023 at 0:22 Comment(1)
This was my problem, basically had an old ProjectReference where that Project was removed but the ProjectReference tag from the main project .csproj wasntPopham
B
0

I have solved the problem by deleting the DbContext which i created in the Web Project and using the one which I created in another project which is a .Net Library then I added this line of code in my StartUp.cs file

services.AddDbContext<CBTDbContext>(options =>
                options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));

By adding it, I was able to find the DbContext in the Web Project. Then another problem has arisen when I'm trying to add migrations. Which I would open in another post

Bowra answered 8/9, 2019 at 14:33 Comment(0)
R
0

I also had this issue

In my case, I was using multiple projects in one solution. And in one of those projects, it's Dependencies was showing warning signs, within these Dependensies, there was a folder with included projects also each showing a warning sign.

I could solve it by right-clicking on the Dependencies, click on 'Add Project Reference' and then unselect all projects related to it/showing the warning signs.

After rebuilding, the cycle problem was gone.

Ruffle answered 8/2, 2023 at 13:57 Comment(0)
P
0

The problem in my case was that I was trying to create a POC for LiteDB and my project was named LiteDB. When trying to install LiteDB NuGet got this error. Changing project's name fixed the issue.

Pastime answered 28/6, 2023 at 7:35 Comment(0)
A
0

In my case, I deleted the 'FileContentIndex' folder (.vsidx files) and disabled the creation of this folder by removing the JSON file: C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\IDE\CommonExtensions\Microsoft\Editor\ServiceHub\Indexing.servicehub.service.json

Then, I performed a clean/reload solution.

  • VS Etreprise 2022
Agreed answered 7/11, 2023 at 13:39 Comment(0)
D
0

I opened a project that built happily yesterday and today showed the NU1108 message. Solution explorer showed a lot of files as missing; but missing from places where they should not have been.

I resolved it by closing VS. Deleting the .vs folder from the top level Solution directory. Reopened the solution in VS.

AFAIK deleting that .vs folder is always 'safe' it will remove personal settings such as the current startup project(s), the currently open files, but I don't believe it contains anything crucial.

Ditmore answered 4/12, 2023 at 13:12 Comment(0)
I
0

if your project name is OpenTelemetry, it could also be the problem. Rename your project name and try to add the dependencies.

Imbed answered 15/8, 2024 at 17:52 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.