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 - office-interop

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

Related

Upgrading from Entity Framework 6.2 to 6.3.0 in NuGet

Entity Framework 6.3.0 was published on 2019 Sep 23. I have two projects in my solution that were using 6.2 and I tried to upgrade to 6.3.0 via NuGet.
One project called DatabaseInterface has an output type of "class library". The other project outputs a "console application".
When I run the upgrade from NuGet the following error happens for the project that is the class library.
An error occurred while applying transformation to 'App.config' in
project 'DatabaseInterface' No element in the source document matches
'/configuration/configSections/section[#name='entityFramework']'
This project, called DatabaseInterface does not even have an App.config file so the error is referring to a file that does not exist. This project has a packages.config file.
Published problems with a similar error are related to web projects so they are probably not closely relevant to my problem. What is the solution to this problem?
Context: Visual Studio 2017 Community, Visual Studio 2019 Community, Windows 10
Uninstall 6.2 and then install 6.3. This seems to cause the automatic deletion of packages.config and there will be no error associated with App.config nor will there be the creation of that file. Subsequent builds do not seem to require the presence of packages.config.

Visual Studio Solution DLL error

I have a visual studio solution which works fine on one machine and when I copy the complete same solution to another machine it misses few external dlls.
Both the machine have same configuration and same version of visual studio.
I tried removing reference and adding again.I am able to reference the dll and use code but when I re-build,It gives the same error.Any pointers on what could have gone wrong?
The error message I get is as below
The type or namespace name 'NameSpaceName" could not be found (are you missing a using directive or an assembly reference?)
Also the warning shows.
The primary reference "NameSpaceName" could not be resolved because it was built against the ".NETFramework,Version=v4.5" framework. This is a higher version than the currently targeted framework ".NETFramework,Version=v4.0".
Both the machine have Visual Studio 2010 installed. It works on one and doesn't work on another machine
The reference you have added to the project is likely not in a subfolder of your project but referenced from the Global Assembly Cache (GAC). Since you probably didn't copy the GAC, this reference is now of a different version. Figure out which (3rd party ?) component is affected and install an older version of that component.
Typically, Visual Studio cannot target .NET 4.5, unless you applied a workaround. In that case, you can go to the project properties, Application and change Target Framework from 4.0 to 4.5.

Convert SharePoint 2010 Solution to 2013 and Visual Studio 2012

I am trying to convert a SharePoint 2010 solution (custom web parts, content types, lists, event receivers, etc.) developed in Visual Studio 2010 to SharePoint 2013 and Visual Studio 2012. When I open the project in VS 2012, it converts a couple of the project files but won't compile because of reference issues.
I copied the DLLs (mostly Microsoft.SharePoint..., although I needed to copy the Microsoft.Office.SecureStoreService.dll too) that were causing issues from my 2010 server to the 2013 server and fixed the references. However, the Microsoft.Office.SecureStoreService.dll still gives me compiler errors claiming "Error 203 The type or namespace name 'Office' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)" when visual studio has no problem with the namespace and finds the SecureStoreProvider class inside it just fine.
I've also tried to change the target framework from 3.5 to 4 and only see "Install other frameworks..." in the target framework dropdown.
I'm sure that others have dealt with this, but have been unsuccessful in framing the right google search query. I'm relatively new to SharePoint in general and any help would be appreciated.
thanks,
Mike
I was able to get my solution upgraded from a 2010 project to 2013 using the following. Note that this will update your solution to use the new 2013 API. It is possible to update just the project file but still run in 2010 mode.
First edit your .csproj file (for c#).
Modify the target framework to this:
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
Add this a node for the office version, I put mine directly below the TargetFrameworkVersion tag
<TargetOfficeVersion>15.0</TargetOfficeVersion>
Update references
Reload the project and update your referenced assemblies. If you haven't specified a specific version they should already be referencing the v15 (SharePoint 2013) assemblies.
Do a find replace for 14.0.0.0 to 15.0.0.0. This updates any references on your pages, layouts, and master pages to the v15 assemblies.
Change calls
Change any calls to SPUtility.GetGenericSetupPath() to SPUtility.GetVersionedGenericSetupPath()
Check each file to do a check for any hive references. You'll need to add a /15/ to these. EG: _layouts/ to _layouts/15/
Open the package "folder" in visual studio then update the properties for that package to use version 15.
Clean up
Finally do a compile clean up any missed items. Deploy your solution and make sure to test thoroughly.

No compile errors when reference added, but errors seen upon build

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.

Visual Studio 2010 error: Type universe cannot resolve assembly

I've loaded a WPF project initially created in Visual Studio 2008 into Visual Studio 2010. The conversion process goes smoothly, but on certain XAML files the VS2010 designer throws several errors related to project references, including this one:
System.Reflection.Adds.UnresolvedAssemblyException
Type universe cannot resolve assembly: GalaSoft.MvvmLight, Version=3.0.0.31869, Culture=neutral, PublicKeyToken=3e875cdb3903c512.
This assembly reference works just fine in the Expression Blend 4 designer, but not in VS2010.
I can build and run the solution successfully.
My solution targets the .Net Framework 3.5 SP1.
I can't quite tell if you're having the same problem I had or not, but I was getting that type universe error all the time with the Ninject .dll. I solved it by "Unblocking" the zip file before extracting it. I think this only affects Vista and Win 7 dev machines but it's worth a try. I posted a blog entry last week with details on the error and the solution. Scroll down to the "Foiled by a Blockhead" section.
Check which version of the MVVM Light assemblies you are referencing.
When you install the MVVM Light Toolkit binaries, you get separate WPF 3.5 and WPF 4 versions. You can find the WPF 4 assemblies (assuming default install location) in
c:\Program Files\Laurent Bugnion (GalaSoft)\Mvvm Light Toolkit\Binaries\WPF4
I found a workaround, but I'm not happy with it. If I change the target framework setting for the project from ".NET Framework 3.5" to ".NET Framework 4 Client Profile" the designer works just fine. But I'd rather not change my target framework just to get designer support!

Resources