Can't get Microsoft.Office.Interop reference to work - c#

I have a C# winforms app and I am simply trying to open an Excel sheet. When I try to add a reference to Microsoft.Office.Interop, the "Office" part is red and says "Can't resolve symbol 'Office'".
When I attempt to build, the error is:
The type or namespace name 'Office' does not exist in the namespace 'Microsoft'
(are you missing an assembly reference?)
I have Office 2012 installed, and I think I have the Primary Interop Assemblies installed... but I'm not positive.
I know that this should be so easy, but I've been looking around for an answer to this for almost an hour and just can't figure it out. Thanks in advance!

Use NuGet Package Manager in VS2015
Right click references in your visual studio project
Select Manage NuGet Packages
Type microsoft.office in the search box
Select Microsoft.Office.Interop.Excel
Click Install
Rebuild your solution

You need to add the library assembly reference to your project.
They are referred to as "Primary Interop Assemblies".
(Assuming Visual Studio 2010)
Procedure
open the solution explorer window
expand your project folder accordion.
right click on the references element
select "add reference" from the dropdown
select the .NET tab and look for the object library called Microsoft.Office.Interop.Excel.
click ok
The object library should now appear in your references.

I had the same error this morning, with a Winforms app which had always built perfectly in the past. All that had changed was that our company had upgraded our laptops from Excel 2007 to Excel 2013.
After some investigating, I realised that the app was a .Net 3.5 app, and although the Solution Explorer suggested that all the refererences were fine..
...actually, they weren't. The tell-tail sign was that, when I tried to re-add the References in the app, they couldn't be found...
What I needed to do was:
update the app from .Net 3.5 to .Net 4.5
remove the Office-related References (the first 5 shown in my first
screenshot above)
re-add the References (now shown as version 14 or 15)
I also had to change one line of code from:
excel = new Excel.ApplicationClass();
to
excel = new Excel.Application();
Once I'd done this, the app built without errors, and ran successfully again.

Easier way to add this package in VS 2015:
on the line code using the package press "Alt+Enter" then select "Find this namespace on nuget.org"
Install it and enjoy :)

I think you are missing the dll reference. Add Microsoft.Office.Interop.Excel.dll to project reference and then try.

You need to install Office 2013 to clean this build error.

Related

Visual Studio 2017 - Unable to add "ReportViewer" to "Windows Form"

I know this question is exactly the same as this but even after following it's solution i am still stuck up with this error
error CS0234: The type or namespace name 'Reporting' does not exist in
the namespace 'Microsoft' (are you missing an assembly reference?)
Things i did to install Report Viewer
I followed the below link to install the report viewer
Download and Install Report Viewer For Visual Studio 2017 - YouTube
(this link shows how to install it from NuGet Manager and Extensions and update)
and i was able to make a Report as well as add Report Viewer to my Windows Form
but i am getting the above mentioned error on building the program
Solutions i have tried
I tried re-adding the reference by right-clicking on References folder in my project and then selecting Add Reference. and then adding Assemblies > Extensions > Microsoft.ReportViewer to the references.
I tried unloading the project and changing it's .csproj file and manually mention the version
Also cleaned the whole solution and manually removed any other remaining files in the output directory and rebuilding it.
BUT
when i try to see the designer of the form in which ReportViewer has been inserted then the Tooltip says that it is recognizing the namespace
Now, I am left with no solutions now. Any piece of advice will be appreciated.
Maybe you should try to use NuGet Package for install Reporting Service on your Winform application.
I use this NuGet and it's working fine for me.
Microsoft.ReportingServices.ReportViewerControl.Winforms
The answer was to change my .Net Framework from 4.0 Client Framework to 4.0. I guess it needs full features of that framework rather than the client version for it.

Quiksoft.EasyMail.SMTP reference not found in visual studio 2015

We recently started using Visual Studio 2015 at work instead of 2013, and now we have found an issue that some of our projects are not building due to some references not being found, nothing has changed at all, just using vs2015 instead of vs2013.
One of the references is Quiksoft.EasyMail.SMTP, the error is the classic "The type or namespace name 'Quiksoft' could not be found (are you missing a using directive or an assembly reference?)"
Me and a couple of coworkers have been trying to solve this, searching in the internet and we have not found why this is happening. We have the dlls (for example SMTP.Net.dll) and it is included in the References of the project.
We are out of ideas at this moment.
Have any of you had this issue in vs2015. I'm using this library as example but I wonder if there are more issues with vs2015 loading/finding references.
I hope is something silly and just need to turn on/off an option in vs2015.
Thank you in advance for the help.
Because your older project had a reference to the dll. Look in the bin folder of your old project or the lib folder if you have one, there will be a dll for it. Right click on references, "Add Reference" and navigate to the dll. Quicksoft is not a native assembly. You will most likely have to update the license on it as well.

Unable to add project reference in Visual Studio 2015

I previously asked a similar question regarding Visual Studio 2013 but now I'm running into the same problem with Visual Studio 2015 but it seems to work differently, which makes the previous answer not applicable to this question. This is my previous question: Visual Studio 2013 - How to debug a project within a solution
I'm attempting to add a project reference. I have a library I'm working on in a separate solution/project and a console application I want to use to test and debug the library.
I tried: Add Reference > Projects > Solution > Browse
But the open file dialog does not contain .sln files in the filter list and if I force it to display them by typing *.sln and then select the Solution I get:
"Please make sure the file is accessible and that it is a valid assembly or COM component."
What am I doing wrong? How do I properly add a Solution/Project reference?
For me issue was due to difference in Target framework. One was .NET Framework 4.5 and other was .NET Framework 4.5.2
Verify if the Target framework is same for your project and the project reference that you are trying add reference.
(Right click on project -> properties -> Application Tab(Target frame work))
Right click on your solution file in Solution Explorer window, click Add and select Existing Project...
Once the project is a part of the solution, you will be able to add project reference.
In case anyone else runs into this here is something that I found. I had almost the exact same issue in VS 2015. I created a console app and then a class library project but could not add a reference to the class library.
It turns out I didn't create a class library project as I had thought, but rather a class library (package) project. These are different things and I was unaware of what the (package) part meant when I selected it. This is for creating Nuget packages, apparently.
I'm not sure if this is something new to VS 2015 but I had not run across it before and it caused me some grief. The error message ('A reference to ClassLibrary1 could not be added') was totally worthless in trying to debug it.
You should add project to your solution first; after adding project to your solution, you can reference it.
To add an existing project to your solution:
Add reference menu:
Add references dialog:
In order to add a project reference, the project has to be part of the solution.
For me issue was due to a difference in the types of projects. One was a C# Windows forms project and the other project was a C# Universal Windows project.
The Windows Forms project couldn't reference the Universal Windows project. The error was "Unable to add a reference to project "XYZ".
It appears you can have a library shared between both types of projects by folloing this answer: What kind of class library works with both Universal and Winform projects?
I ended up having a different solution. I had three projects in the solution which referenced a NuGet package which was no longer available. I had the library locally but I was unable to add it. I found that because of the BUILD ORDER and DEPENDENCY of my projects, I had to add it to the project that was built first, then I could add it to the projects that were dependent on that project.
I had this problem today and I looked at the configuration manager for the solution. The projects had different platform settings. I made them both Any CPU and rebuilt. Then I could reference the project.

Added JWT with nuget, but why does error list still says jwt does not exist in the current context? [duplicate]

I am using the MagicLibrary for a few components. I knew it was written in Visual Studio 2003 and recompiled it in Visual C# Express 2010. It compiled just fine and I could see the library in the folder.
I then created a new project in Visual C# Express 2010 and added the components MagicalLocalLibrary.dll to the Toolbox. They appeared fine with no errors. I put in a control from the Toolbox to my form, and it seemed fine. I then debugged (to see if any errors would occur) and I saw that the reference MagicalLibrary disappeared and I got the error:
The type or namespace name 'Crownwood' could not be found (are you missing a using directive or an assembly reference?)
The thing is that, the reference shows fine under References in Solution Explorer but I can't import it with using or use it in the code (simply is not listed in InstelliSense either) but if i go into the Object Browser and choose "My Solution" it is not listed. I can click on the Reference in Solution Explorer and just change the Copy Local property to True or False, then it will appear in the Object Browser but whenever I debug my project again it disappear.
Any idea why it does this? Thanks in advance.
Check that you are using the .Net 4 framework and not the client profile version
You find that setting when you right-click on your project, choose properties. And under application there is a setting for target framework. If you have chosen the .Net 4 framework Client Profile, then this behavior that you described can happen
I ran into a very similar issue once. In my case the problem turned out to be a missing dependency for the "vanishing" namespace's assembly. What finally gave me the information I needed was the suggestion in this StackOverflow answer to raise the MSBuild output verbosity level. After raising the verbosity setting the IDE should give you a more specific reason why the compilation fails.

Add FreeImage .NET to solution

I have followed the posts on this, but i am still not getting a few steps. I am new to C#, and that is probably the issue. I would love a little help (I have been banging on this all day).
I can open the FreeImage.NET solution (Win7 64 bit machine btw) in Visual Studio. This post says i need to Build it to get the C# dll. When i build it, i get hundreds of errors "type or namespace 'Name' could not be found".
Does it need the C++ DDL added first? I dragged and dropped it onto the solution, but still the errors.
Am i doing something simple and wrong?
Specifically what i am trying to do is add FreeImage to project in C# Visual Studio Express 2012.
Thanks,
Dan
After downloading the version of FreeImage.NET , I opened the following VS2005 Solution File in VS2012.(Thats the only one I have)
FreeImage3154\FreeImage\Wrapper\FreeImage.NET\cs\FreeImage.NET.2005.sln
After upgrading the project and building it for the first time, I saw around 491 errors. If you open the references of the UnitTest.2005 project, you will see that the nunit.framework assembly is missing. If you have nuget installed , in VS2012 you can
Right Click references > Manage NuGet Packages > Search for NUnit and install it.
In the image below we see that the nunit.framework assembly is correctly linked.
After doing this there were only 50 errors remaining and they were all because the Xml Documentation file checks were enabled. You can disable this check as shown below in the Library.2005 project.
Build again, and it should succeed.
NOTE: The FreeImage website provides only a 32-bit version of the DLL, thus to use this DLL you will have to ensure that you set your project version to 32-bit. To obtain a 64-bit version of the FreeImage DLL you will have o download their source code project and manually do a 64-bit build as show in this blog.

Categories

Resources