Page 1 of 2
VS error when adding reference
Posted: Wed Dec 11, 2024 6:32 pm
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"
there is any way to solve this?
thanks
Stefano
Re: VS error when adding reference
Posted: Wed Dec 11, 2024 11:22 pm
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.
Re: VS error when adding reference
Posted: Thu Dec 12, 2024 8:54 am
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
Re: VS error when adding reference
Posted: Thu Dec 12, 2024 9:03 am
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
Re: VS error when adding reference
Posted: Thu Dec 12, 2024 12:28 pm
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:
in the Preferences/Folders I have:
thanks
Stefano
Re: VS error when adding reference
Posted: Thu Dec 12, 2024 12:48 pm
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
Re: VS error when adding reference
Posted: Thu Dec 12, 2024 1:02 pm
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.
Re: VS error when adding reference
Posted: Thu Dec 12, 2024 3:39 pm
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?
thanks
Stefano
Re: VS error when adding reference
Posted: Thu Dec 12, 2024 4:22 pm
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?
Re: VS error when adding reference
Posted: Thu Dec 12, 2024 4:28 pm
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