Visual Studio & Circular Dependency woes - c#

I have a legacy system that's made up of 15 different projects and when I've tried to reference one from the other Visual Studio complains that it cannot do so as that would cause a circular dependancy.
My problem is that I can't see how it would cause a circular dependancy as the project I'm trying to reference ('XScript') doesn't have any sort of refence to the project that's trying to reference it ('WPF_Forms').
From researching around on here I've found people suffering similar fates though their problems seem to have obvious circular dependencies.
I've downloaded a demo copy of NDepend as recommended on a few posts from here and despite working through the various dependency tools on there there's still no obvious link.
I've right-clicked on the projects involved and used the "Project Dependencies" option but I can't see any link. I've also re-started Visual Studio and tried "Clean Solution" and "Re-build Solution" to no avail.
The only way round that I've been able to come up with is to reference 'XScript' by referencing the built DLL and not the project itself, however that feels a bit dirty and I want to know why this is happening rather just hack round it.
Can anyone suggest anything I may have missed or any strategies I could employ to work out what's going wrong?
EDIT 1 : XScript used to reference WPF_Forms but that reference has since been deleted (and the project cleaned and rebuilt with no dependencies showing on the 'Project Dependencies' window. I suppose it could be possible that VS has retained a link somewhere or that it thinks the projects are linked somehow.
EDIT 2 : Following on from BitBonk's suggestion I've ran used VS's Code Map feature and worked out the project topology. XScript and WPF_Forms are only referenced by the main .exe and nothing else. I'm beginning to suspect this is a VS issue and I may have to create a new project and add all the sub-projects in again to get it working.

And the problem was: Visual Studio 2012.
After using Code Map like Bitbonk suggested I could see no references that would cause the problem. So, I removed both XScript and WPF_Forms from the project, ran a clean, added XScript back in ran a clean and then added WPF_Forms back in and ran a clean.
After that adding the reference from WPF_Forms to XScript didn't cause any problems. I can only guess this is a bug in VS that was triggered by it not recognising there was no longer a dependency from XScript to WPF_Forms.
Hopefully this question and the suggested answers will help someone else in future.

As already stated by others your circular dependency might involve multiple levels. You can easily visualize the dependency graph using the code map feature of viusal studio 2012. That way you might be able to spot where this would happen.

Maybe your circular dependency involves more than 2 projects.

Related

Need to Add Visual Studio 2015 Shared Project References to a Github Repository

Okay, so, really quick question that I hope I can provide enough detail to get an answer for.
Programs used: Visual Studio 2015, Github
The problem is occurring whenever the developer makes a change that includes the references within Visual Studio and commits his changes to our Github. I am our tester and am told that the code is ready for testing, only to find that I cannot compile at times due to the Project References not being correct. We have discovered that this is because Github does not synch changes to the References that a Project has. The Reference that is giving us the most problems is an internal reference to another project within the solution, and appears in the "Shared Projects" section of the Reference Manager in VS2015. The developer is trying to soothe these issues as well, but our progress is being slowed significantly by this problem while he searches for an in-code solution.
Is there a way to force Github to add these Reference changes when making a commit? Due to the terminology used, I have not been able to find a solution to the problem anywhere, or at least one that I understood. I am not well versed in Visual Studio, so I am not sure if there is an option to change somewhere or another simple fix. If there is, please let me know.
I hope that I have provided adequate information without breaking my company's NDA. If you need further info to aid in this matter, I can ask the developer for further clarification, although it may take up to 24 hours for him to respond. Thank you in advance!

Remove GAC Dependency that does not appear in Prerequisites

This is so frustrating. For some reason I have added a dependency Microsoft.VisualStudio.Text.Logic into my application so when I deploy it, it gives me the typical "Unable to install or run the application. The application requires that assembly XXX be installed in the Global Assmebly Cache (GAC) first". No big deal.
So I went to the application files section and it doesn't show up. Then I checked my references and nothing shows up. As a last ditch effort I checked under the "Add References" panel and it's not there. For some reason my Build Server has it, but all my end users as well as my development machine do not. Is there anywhere that I can check as to what dependencies are required and remove them? I cant find any code in my application that would required this DLL.
I guess this question can be generalized as this: "What is the best way to find dependencies for a project to prevent new ones from being created"?
So i found a solution that probably doesnt directly solve it for most people, but it is something good to keep in mind. What i didnt realize was that the Visual Studio versions were different and for some reason the one on the build server was adding a bunch of dependencies (like 15). I solved the issue by updating the server to contain the same visual studio version as my development machine.

Visual studio cannot find my referenced DLL's namespace

This is a very frustrating problem. All of a sudden I cannot use referenced DLLs. I added an assembly reference to a project in the same solution and the namespace is unrecognised. I can even see the reference in the object viewer. I've also changed the projects to .NET 4 and 3.5 without the client profile to no avail.
Based on your screenshot, you have references to the same "ServerLibrary" DLL in multiple projects, however, it looks like one referenced version is compiled in .NET 3.5 and the other referenced version (the project reference it appears), is compiled in .NET 4. Make sure all projects point to the same version of the DLL and recompile all. That should fix your problem.
I faced this problem, and I solved it by closing visual studio, reopening visual studio, cleaning and rebuilding the solution. This worked for me. On some other posts, I have read the replies and most of users solved the problem by following this way.
I removed DLL name and namespace from the path where I was using it. And for some wierd reason it worked.
Make sure that the classes are public classes too. I had this issue when I couldn't find my model classes. Silly mistake but frustrating when unnoticed.
This is mostly cause becauese of using diffrent version of same packages at diffrent projects at same solution. I recommend to update all packages to lastest version at all projects.
Right click to project that has downgrade packages --> manage nuget
packages --> click the updates tab --> check the 'select all packages' checkbox -->
click the update
Do this for all prjects at solution.
I had this problem using Visual Studio 2019 with Resharper. I resolved it by clearing the Resharper cache.
Extensions\Resharper\Options
General Page
"Clear caches" button.
After clicking "Clear caches", I restarted Visual Studio and did a Clean/Rebuild.
VS2019 July 2022: I had to deal with same issue for more than a day.
The comment by JaredPar helped to resolve it :"most likely cause of
this problem is the referenced DLL is itself invalid. Have you tried
loading it in reflector to see if it contains members? –
So If you reference an assembly and IT DOES NOT CONTAIN at least ONE public type(Class, Property ,Enum, .. etc) still it does not show after the using keyword. This behavior makes 100% sense, because what is the point of referencing something which is useless?
However Microsoft could easily have added a Message/Warning in VS to make the life of the developer less Miserable.
Something like "Warning: Reference ABC does not contain any public members"`

Visual Studio 2010 issue with a class that doesn't compile

I have a Visual Studio 2010 C# webforms solution with various projects in it. There is a certain class in one of them that acts strangely. If I open some code in another project and then use the "go to declaration" command to get to the class in question, Visual Studio shows me meta data from the DLL instead. However, if I do the same for another class in the same project (while still using "go to declaration" from another project), I get to the actual code just fine.
Same thing happens when I try to compile. I alter code in this class to no avail, Visual Studio simply doesn't compile the changes. Again only for this one class, all the rest seems to work just fine.
Using "go to declaration" from inside the same project works.
I believe this was caused by our upgrading the solution from .net 3.5 to 4 recently, which brought about a variety of issues that we were able to fix though. This particular issue only seems to exist on my own machine currently, as the code in question is still in development and not checked in yet.
I don't think it matters, but for the sake of completeness: the class in question is an interface.
I've tried "clean solution" and deleted a variety of Visual Studio cache files, nothing seems to have helped so far. Any possible solutions very welcome.
It might be a problem with your references - it may be referencing the compiled assembly instead of the project.
Try deleting each reference to that assembly and add them back in as project references.

Visual Studio 2010 suddenly can't see namespace?

My C# WinForms solution has two projects.
A DLL which is the main project I'm working on, and an executable WinForms I call "Sandbox" so that I can compile/run/debug the DLL easily in one go.
I'm working in .Net 4.0 for both projects.
Everything was working fine until I added some seemingly innocent code, and a reference to System.Web in the DLL.
Now my Sandbox project can't see the namespace of the DLL project. I didn't change anything which I believe should have affected this.
If I delete the project reference to the DLL from the Sandbox references and re-add it, then the red underlines all disappear and the colour coding comes back for all my classes etc; but as as soon as I try to build the solution, the whole thing falls apart again.
When I right-click the DLL project in the Sandbox's references and view in object browser, I can see the namespace and all the stuff in there.
I have a feeling this might be some sort of bug?
Is this some sort of VS2010 bug? I had this same issue a few months ago and I could only fix it at the time by making a whole new project and re-importing my files. This time, however, I have a bajillion files and will only do that as a last resort!
Edit:
After panickedly going through and undoing all my changes, trying to find what caused the problems, it seems to be this line:
string url = "http://maps.google.com?q=" + HttpUtility.UrlEncode(address);
If I comment out this line, then I get no namespace errors and the project builds fine. I can't see anything wrong with this line though.
I'm ready to declare this a bug in VS2010, this has bitten way too many programmers already. The fix is easy: Project + Properties, Application tab, change Target Framework to ".NET Framework 4" instead of the Client Profile that is selected by default.
System.Web is not included in the client profile. Having this option in the first place is quite silly, the client profile is only 15% smaller than the full version of .NET 4.0. Having it selected by default is even sillier. But I digress.
UPDATE: mercifully this all got fixed in VS2012. Which no longer makes the client profile the default for a new project. And the client profile got retired completely in .NET 4.5, good riddance.
Check to make sure that both projects are using the non-client profile for their target framework (go to each project's properties to do this).
One possibility is that the target .NET Framework version of the class library is higher than that of the project.
I faced this problem, and I solved it by closing visual studio, reopening visual studio, cleaning and rebuilding the solution. This worked for me. On some other posts, I have read the replies and most of users solved the problem by following this way.
Try building only the project with the Sandbox dll first independently.
Then point your executable project to the required dll and ensure copy local is set to true. in reference settings.
Tthen build the executable project.
Changing the target framework from the ".NET Framweork 4 Client Profile" to ".NET Framework 4" worked for me with a similar problem. I agree that the client profile doesn't seem to have much of an advantage to using it. I seem to get nailed with weird errors that I hunt for until I remember that Visual Studio defaults to the client profile. I guess the moral of the story when getting an error is: if "Rebuild Solution" doesn't work, check the Target framework...
If you tried already doing the Framework change, and still not worked, I hope this works for you (as it did for me): Simply add the necessary references from within your projects. Very obvious but I was doing it wrong until I found what was the issue.
I just had this issue and it turned out to be I had multiple namespaces being used that had the same object name (i.e. business objects had the same names as mvc models);
Fully qualifying the names fixed the issue for me.

Categories

Resources