No compile errors when reference added, but errors seen upon build - visual-studio

A solution was just converted from VS 2008 to VS 2010. My VS 2010 build is failing with the popular "The type or namespace X could not be found". When I go to the project and go to Add References and add the appropriate project dll, the class name appears in blue text as if .NET found the correct class. However, when I go to the Build menu and select "Build Solution" I get the "namespace not found error" and the class name is no longer blue.
Thanks.

Your project is probably using the .NET 4.0 Client Profile, rather than the full .NET 4.0 framework.
Go to Project > Properties > Application and set "Target framework" to .NET Framework 4.
For some reason Microsoft set this as the default framework instead of the full one for projects in VS2010, and compilation fails with this cryptic error message for any referenced types/namespaces in assemblies which were built against the full framework.

Related

Microsoft.Office.Core is defined in an assembly that is not referenced. You must add a reference to assembly office, Version=15.0.0.0

I'm using Visual Studio 2022. I have created a .net 6 project.
I added the COM references: Microsoft Excel 16 Object Library (Microsoft.Office.Interop.Excel) and Microsoft Office 16 Object Library (Microsoft.Office.Core).
The following lines of Excel interop code threw an error at SetElement(), could not build:
Chart c = (Chart)wbSheets.Application.Workbooks[1].Charts.Add();
chart.SetElement(Microsoft.Office.Core.MsoChartElementType.msoElementChartTitleAboveChart);
Microsoft.Office.Core... is defined in an assembly that is not referenced. You must add a reference to assembly office, Version=15.0.0.0, ..., PublicKeyToken=71e9bce111e9429c
A very strange error, that an Office 16 (Office 2016) libary needs references to Office 15 (Office 2013).
The exact same steps for COM referencing and c# code works perfectly in .NET 4.8 Framework. So the problem is specific to .NET 6 (possibly .NET 5 and all previous .NET Core versions).
Using a nuget command Install-Package MicrosoftOfficeCore -Version 15.0.0 to install the reference and manually removing the previous v16 reference, did resolve the code building error. But now the dependency had a yellow triangle warning, that the dependency is for .NET 4.6-4.8 Framework and might be incompatible with .NET 6.
Despite this, the code seemed to work and the Excel file was generated.
But I'll post a better fix in the answer.
The better fix is to go to:
Solution Explorer > project > Dependencies > COM > select Microsoft.Office.Core > properties pane.
The last property is Wrapper Tool, with a default value of tlbimp
Type in primary for the value, click somewhere else to update the field and the problem is solved. No nuget package required.
Found this obscure solution from here (bottom most post):
https://github.com/dotnet/project-system/issues/5735

The name 'Sitecore' does not exist in the current context

I have a new instance of Sitecore 9. I'm trying to create my first component, an ascx file with a codebehind file, and I have this line:
var item = Sitecore.Context.Item;
The build is failing with the error "The name 'Sitecore' does not exist in the current context"
please make sure that you have added the reference to "Sitecore.Kernel.dll". i would suggest you to also checkout the nuget packages provided from Sitecore:
Sitecore Nuget Feeds
Depending on your deployment Strategy it would be a good practice to use the nuget. Sitecore has created every nuget package with ".NoReferences" extension for example : "Sitecore.Kernel.NoReferences" which is great for dependency management.
If you are using MVC you will need also "Sitecore.Mvc.dll".
In my case, I had a error specification in the output window for this error which turned out to be an hint to solve this error.
The .NET framework version of my visual studio project was targeted at v4.6.1, updating the project's target framework to v4.6.2 fixed my error : "The name 'Sitecore' does not exist in the current context"!
It seems that the Sitecore.kernel.dll (responsible for using term 'Sitecore' for reference in code like controllers) with version 11.1.0.0 was built against the ".NETFramework,Version=v4.6.2" framework. This is a higher version than the currently targeted framework ".NETFramework,Version=v4.6.1" (of my visual studio project).
Here is the error specification (hint!) in my VS output window that I mentioned earlier:
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets(2110,5): warning MSB3274: The primary reference "Sitecore.Kernel, Version=11.1.0.0, Culture=neutral, processorArchitecture=MSIL" could not be resolved because it was built against the ".NETFramework,Version=v4.6.2" framework. This is a higher version than the currently targeted framework ".NETFramework,Version=v4.6.1".

Build .net standard 1.4 class library TFS 2015 on premise

We are building a web API application for a Xamarin forms app. I included a .NET standard class library project to use as my view models. The idea being as we build out the web api endpoints - I will publish the updated class library to our internal NuGet server.
Our CI is failing. When I check in the code - I am getting a build error (using TFS 2015 on premise). The first error I received was
The default XML namespace of the project must be the MSBuild XML namespace. If the project is authored in the MSBuild 2003 format, please add xmlns="http://schemas.microsoft.com/developer/msbuild/2003" to the element. If the project has been authored in the old 1.0 or 1.2 format, please convert it to MSBuild 2003 format.
So I added the XML namespace to the csproj
Now I get this:
There is no target in the project.
Which version of Visual Studio do you use? Can you build the project locally with VS or build with msbuild in command line?
Anyway, based on the error message, it seems related to the version of VS which created the project and the msbuild version (New .csproj project format applied in VS 2017). You can reference below threads to troubleshoot the issue:
For the first error:
The default XML namespace of the project must be the MSBuild XML namespace
Visual Studio .NET 2015 can't open migrated project
For the second error:
Visual Studio 2010 Project Targets
Add the following attribute to the Project element:
DefaultTargets="BuildTarget"
That will tell MSBuild to use the target named "BuildTarget" when we do a build. Next add the following subelement to the Project element (just before the last line, which has "</Project>"):
<Target Name="BuildTarget">
<Message Text="Build selected" Importance="high"/>
</Target>
Then save the file and close the edit window. Then return to the Solution Explorer and right-click on the solution and select "Reload Project". Then build the project. You should get the message "Build selected" along with the output of the build, as in:
So answer is not possible. I have tried install VS 2017 on the agent - that didn't work.
We did find an article that TFS needed to be upgraded beyond Update 3.
I will end up upgrading us to 2017 in a few months - which will make this a moot point.
Thanks for the answers.

While Creating setup showing Error in visual studio

I am working on visual studio 2010. I am trying to Rebuild my setup project but I am getting these 3 error(s):
1: An error occurred generating a bootstrapper: Unable to finish updating resource for C:\Users\IBS Support\Desktop\Evalet Without Printer & Stored Procedrure\1\EVallet-Desktop\EvaletSetup\Debug\setup.exe with error 80070005
2: General failure building bootstrapper
3: Unrecoverable build error
I am using MS Visual Studio 2010, version 10.0.30319.1
(.Net FrameWork Version 4.5.50709)
This post should help you.
Quote from the post:
This happens because The .NET framework version required by the setup project is different than the .NET framework version targeted by the application.
To verify this:
In Solution Explorer, select the setup project.
On the View menu, point to Editor, and then click Launch Conditions. Click .NET
Framework.
In the Properties window, change the Version property to the version of the .NET Framework that you want the setup project to check for and install.
Hope this helps?

Why does visual studio not recognize System.Web.SessionState?

I am trying to go through the example at http://msdn.microsoft.com/en-us/library/aa719643(VS.71).aspx
Visual studio 2010 does not recognize System.Web.SessionState and various others.
I tried adding a .net reference to them but they do not exist on my system. I have .Net 4 installed.
Why would these examples use namespaces that are not recognized by visual studio?
alt text http://www.phantix-llc.com/system.web.sessionstate_missing.jpg
System.Web isn't shown because VS2010 defaults to using the .NET4 Client Profile which doesn't include it. (You can see the "Filtered for .NET Framework 4 Client Profile" text at the top of the Add Reference dialog.)
You need to change your project's properties so that it targets the full version of the framework, then you'll be able to select System.Web.
System.Web.SessionState (and the others shown unrecognized) are in System.Web.dll. Verify that reference exists.

Resources