VS error when adding reference

This forum is meant for questions and discussions about the X# language and tools
stecosta66
Posts: 88
Joined: Mon Sep 26, 2016 12:59 pm
Location: Italy

VS error when adding reference

Post by stecosta66 »

Hi all,

Using VS 2022 (17.12.3) and X# 2.21

I'm getting a strage error when trying to add a reference to Microsoft Excel and Word to my project.

Following the example 4 to add an Ole Automation object I get: "Operation is not valid due to current state of the object"

Image

there is any way to solve this?

thanks
Stefano
User avatar
Chris
Posts: 4977
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Re: VS error when adding reference

Post by Chris »

Hi Stefano,

Thanks for the report I also see the problem, seems it happens with any COM reference. I'm sure Robert can fix this too for the upcoming build.
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
stecosta66
Posts: 88
Joined: Mon Sep 26, 2016 12:59 pm
Location: Italy

Re: VS error when adding reference

Post by stecosta66 »

Hi Chris,

thanks.

I tried in Xide to add COM reference but I don't see Microsoft.Office.Interop.Excel in the list of COM interop Assemblies

Stefano
User avatar
Chris
Posts: 4977
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Re: VS error when adding reference

Post by Chris »

Hi Stefano,

In XIDE, you need to create the assemblies first, by pressing the "Create COMM Assemblies" button (it's also available as a menu command under Tools) first, then they will be available for all apps in the COM references page.

In case you get an error doing that, plese check that XIDE has found correctly the location of the .Net SDK in Preferences/Folders, it should point to something like

C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.8 Tools
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
stecosta66
Posts: 88
Joined: Mon Sep 26, 2016 12:59 pm
Location: Italy

Re: VS error when adding reference

Post by stecosta66 »

Hi Chris,

it is in the 'Create COM interop Assemblies' that I do not see Excel or Word in the list.

this is what I see:

Image

in the Preferences/Folders I have:

Image

thanks
Stefano
User avatar
robert
Posts: 4558
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Re: VS error when adding reference

Post by robert »

Stefano,

If you install the "Visual Studio Tools for Office" from the VS Setup / Components page, then all the assemblies that you need are installed on your machine.

On my machine these are in:
"c:\Program Files (x86)\Microsoft Visual Studio\Shared\Visual Studio Tools for Office\PIA\Office14"
and
"c:\Program Files (x86)\Microsoft Visual Studio\Shared\Visual Studio Tools for Office\PIA\Office15"

Inside VS you can find these DLLs on the "Extensions" page.

Using these DLLs you do not need a COM reference.


Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
User avatar
Chris
Posts: 4977
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Re: VS error when adding reference

Post by Chris »

Hi Stefano,

I think it's the Office one, this should include all (Excel, Word etc). But I see your SDK folder option is empty, please put there the folder I mentioned earlier (might be slightly different in your machine).

But as Robert said, you can also directly reference the dlls if they already exist in your disk.
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
stecosta66
Posts: 88
Joined: Mon Sep 26, 2016 12:59 pm
Location: Italy

Re: VS error when adding reference

Post by stecosta66 »

Hi Robert and Chris,

thanks for all the input. I've installed the 'Visual Studio Tools for Office' and now I've all the assemblies installed exactly in the same path as Robert said.

I've added the dll to reference in my project, are this right?

Image

thanks
Stefano
User avatar
Chris
Posts: 4977
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Re: VS error when adding reference

Post by Chris »

Hi Stefano,

I think both of these need one more base dll, which is referenced by both, but not totally sure. What is the full list of the files in that folder in your PC?
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
User avatar
robert
Posts: 4558
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Re: VS error when adding reference

Post by robert »

The Excel dll has a reference to the dll "office.dll" and "Microsoft.Vbe.Interop.dll"
The Word dll has the same references.
Btw: I have located the problem and will be fixed in the next version of the VS integration.

Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
Post Reply