Visual Studio 2012: Project cannot be referenced - c#

We developed a large solution containing ~35 projects with VS 2010, now we are thinking about migrating to VS 2012 Ultimate.
I converted the solution file to VS 2012 and generally, everything works fine.
But whenever I open the solution, I get some warnings on a certain project A in the solution:
"The project X cannot be referenced"
"The project Y cannot be referenced"
...
where A has project-references to X and Y.
When I build the solution, I get errors that the Metadata of each respective DLL could not be found.
When I look at the references in the solution explorer, they are marked with a yellow warning-symbol. As soon as I simply click on the reference, the warning goes away and the icon looks normal. Then I can build without errors!
The problem occurs each time I open the solution, the affected projects are always the same.
Did anyone else experience this odd behavior?
Deleting and adding the project references again did not help...
Thank you in advance.
EDIT: I checked the csproj file of the referencing project and I wonder that all project reference GUIDs having the above problem are written lowercase, other projects are uppercased.
<ProjectReference Include="..\Presentation.Net\Presentation.Net.csproj">
<Project>{04004c6b-76c8-4f2d-9fcf-5a866bb80fd4}</Project>
<Name>CMS.Presentation.Net</Name>
</ProjectReference>
While within the solution the GUIDs are uppercased:
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Presentation.Net", "Presentation.Net\Presentation.Net.csproj", "{04004C6B-76C8-4F2D-9FCF-5A866BB80FD4}"
Any ideas?

VS 2012 dropped support for some of the older project types. Not all of the VS 2010 project types are supported in VS 2012. For instance, the MSI setup project types have been replaced by InstallShield LE project types. Check the compatibility list here and see if any of your failing project types are an issue.

This pointed me into the right direction.
Visual Studio 2012 Randomly reporting: "The referenced component X could not be found"
At least the warnings go away. Have to check whether the metadata errors will occur again.

When I ran into this problem, it was due to differing versions of .NET between the projects. You need to make sure that the project you are trying to reference has a compatible .NET version with the current project.
For example if your target project is .NET 4.5.2 and the project you reference is on 4.6, you can get this error as the referenced project is using components that your current project cannot access.
To solve it, simply go to the target project's properties and select the correct compatible version of .NET. For all my projects in my solution I maintain the same .NET version for each of them, especially if they are referencing each other.

Try to clean the project/solution and then build it.

Related

Visual Studio Intellisense Can Find References But Build Fails Due To Missing References

I'm currently running into an issue (on Visual Studio 2022) where the test project within my solution is referencing a few other projects in my solution; however, trying to build the test project results in errors for these project references. Even more interesting is that this test project used to be working fine.
So far I've:
Double checked the pathing of the project dll's being referenced
Removed and re-added the project references.
Editing the file, Intellisense is able to find the references, but when building the console output shows errors.
Cleaned the solution
Seen recommendations online of clearing the Temp folder and AppData\Local\Microsoft\VisualStudio\17.x\ComponentModelCache for my user account and have done so
None of this has helped. Any guidance on what to research or things to try/insight to the problem would be much appreciated!
Thank you
-Austin
EDIT 1 (7/5/2022)
Error List Image
The error seem to resolve themselves when I click on them from the Error Lists (after viewing the place in the file where the reference error is occurring, the error disappears after a few seconds, removing it from the Error List and also the removing the red squiggle underline). However, the error does not actually resolve as there are still the same reference errors when trying to Build the test project.
For example, STEP.Entities is a project in the solution that is referenced by the test project. However, the test project can't find the referred Entities project.
I realized the issue was caused by packages used in the other projects of the solution were targeting different .NET versions than the same packages within the Test project.
(Firstly, to determine this I went to Tools > Projects and Solutions > Build and Run > select MSBuild Project Build Verbosity as Diagnostic. (I believe this generates more a detailed report of the status to the Output Console when building projects)).
Specifically, a lot of these packages in my test project were targeting .NET v 4.8 as opposed to v4.7.2 being targeted by packages in the other projects, and the Test project itself and other projects targeting v4.7.2. I updated my Test project to target v4.8 and everything works/references can be found.
I've had this problem recently with a project from GitHub, my best sugestion is to try checking the version you are using and maybe select an older version of the said references.
It took me a while to get it done but it worked.
I think I worked around this with following global.json in the root of my drive:
C:\global.json
{
"sdk": {
"version": "6.0.300",
"rollForward": "latestFeature",
"allowPrerelease": false
}
}
Or there might be a global.json in your solution somewhere, with a .NET SDK version that doesn't exist...
To list all installed .NET sdks on your computer, run
dotnet --list-sdks
and pick the correct version.

Visual Studio 2019 Error - Could not load file or assembly or one of its dependencies

I have some trouble with running my project. When I try to run, the following error appears:
FileNotFoundException: Could not load file or assembly 'Dapper,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its
dependencies. The system cannot find the file specified
Context:
I have a Class Library X and a Web Application Y which have dependencies on X. When I try to run my API project, it throws the above error.
BUT, when my colleagues try to run the same API project, it works fine (no errors, and in /bin folder, it loads all the .dll libraries..)
I did those approaches:
Restart Visual Studio, clean and build a solution
Remove the class library references and add it again
Tools > Import and Export Settings Wizard > Reset all settings (maybe some setting was not well configured). I also tried to import colleague settings and didn't work either.
I tried various approaches(even in a different machine, but same VS settings) but none of these worked for me.
Visual studio 2019 16.4 Enterprise.
I'd also try:
1) Deleting your bin and obj folders in your solution before a rebuild.
2) Check that you've not got multiple versions of the same package across the solution (right click on solution in solution explorer -> manage nuget packages for solution).
3) Check that the properties of the reference (right click in solution explorer on the reference in question) shows a path to the package that you'd expect relative to the solution (eg not in mydocuments/nuget packages or something!).
4) Try a fresh clone of the repo (this should in effect replicate your co-workers' set up) and see if the problem still exists then.
I suppose another cause could be that your coworkers have a locally installed package / dll that they're happily referencing without realising, but you don't have?
When you copy a project from someone or another system, you need to download and install all components. normally VS will give you the option to "restore packages" when you load a newly imported from git but not sure if it does when you open an existing solution from a different system.
Right Click your project, Manage Nuget Packages
Browse -> Search for Dapper. Install
In the error you receieve, it tells you what version of the package should be installed as well. Installing a significantly different version might cause other unexpected errors.
thank you for your solutions but I found the problem:
The project solution has some projects with .net standard 2.0 and some with .net framework 4.8. Somehow, when I run the app, some packages are not loaded correctly and it throws an error.
That line below solved my problem:
<RestoreProjectStyle>PackageReference</RestoreProjectStyle>
Put it in all .net framework 4.8 projects on first XML tag.
Thank your for all.
Regards.
I had exactly the same Dapper error message today when referencing a .Net Standard 2.1 class library in a .Net Core 3.1 WinForm app. My resolution was to double-click the class library name in Solution Explorer to open the .csproj file, and then add a CopyLocalLockFileAssemblies tag to the PropertyGroup tag and setting it to true.

Missing namespaces when downgrading to asp.net 4.0

I just had to downgrade my ASP.Net 4.5 application to an ASP.Net 4.0 application, because our servers don't support 4.5. The way I downgraded it was pretty simple:
Project -> Properties -> Application -> Target Framework
When it finished doing stuff, I restarted the solution, tried to start debugging, but it stopped right after I started debugging, giving me first some errors (which say they can't find some namespaces) for a fraction of a second and after the errors disappeared it gives me 127 warnings that all look like this:
Now I know what the problem is here, but I don't know how to solve this issue.. Does anyone know how to fix these warnings?
Thanks in advance
INFO
I'm using Visual Studio 2015 Community
Remove your current references to the Dlls in question and them add them again, it should load the correct versions of the Dlls. Because you had references to the 4.5 versions and then changed the project target the references are invalid now because they are build against a higher version framework. Changing the projects framework version target does NOT update the references in most cases
It is actually not that easy when it comes with ASP.NET. You have to go through all web.config(s) and downgrade referenced libraries. If its new project, just create new ASP.NET on .NET 4 and compare its web.config(s) with yours.

When adding a reference from the GAC VS automatically changes it to a local dll

I have this strange issue where I add a reference to an assembly in the GAC and Visual Studio insists on changing it to a reference to a local assembly in the bin folder. I am not sure how to fix that.
The only time I've seen this is in Visual Studio 2015 when I tried to add a reference to a project built with .NET 2.0 to a project targeting .NET 4.5. At this point, Visual Studio throws up a warning message saying it's going to use a local file reference.
This is mentioned in the MSDN page here: https://msdn.microsoft.com/en-us/library/hh708954.aspx
In Visual Studio 2015, a file reference instead of a project reference is
created if the target version of the .NET Framework of one project is version
4.5, and the target version of the other project is version 2, 3, 3.5, or 4.0.
Might be useful to check if the .NET versions match on the referenced library and your project.
Verify that the Copy Local property of the reference is set to false.
I actually had to delete the .dll files altogether to stop VS from referencing them and after I did that I started getting a warning saying
“The primary reference "xxxx" could not be resolved because it was built against the ".NETFramework,Version=v4.5.2" framework. This is a higher version than the currently targeted framework ".NETFramework,Version=v4.0".
So it seems we need to upgrade our Visual Studio from 2010 to 2013 to be able to use these libraries in our project.

Reference Component Microsoft.CSharp could not be found

I found this problem on my C# project which I started at Visual Studio 2010, when I go to another PC I use in 2008, I open the project.csproj:
A get or set accessor expected
and warning:
The referenced component 'Microsoft.CSharp' could not be found.
I thought that it was about .NET Framework or Microsoft.CSharp is not located, because it says that:
Could not resolve this reference. Could not locate the assembly "Microsoft.CSharp". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors
but I'm not sure about the problem, can you guys give me a solution? Really appreciated.
It sounds like you are targeting .NET 4.0 in the project, and then trying to load it in VS2008 which only targets up to .NET 3.5.
If you need to use the project in VS2008, then you should re-target the project at .NET 3.5:
and then remove any incorrect references (they'll probably have yellow warning triangles on them anyway).
The A get or set accessor expected also suggests you're using new C# syntax, for example dynamic. If you need to target older C# compilers, you'll have to not do that. If you are using multiple IDE versions and it is being a problem, then to ensure you don't do that accidentally you can set the language version for the project via Project Properties -> Build -> Advanced:

Categories