I'm trying to add the ActiveX Microsoft Excel 11.0 Object library to my .NET project. It works fine on my computer, but when I check in my code, it doesn't work on my coworker's. Fixed it on his and it broke mine. When added, the namespaces are different between our machines.
It turns out the difference is that when I add the reference it uses tlbimp
as the WrapperTool, but for him it makes it a primary
reference.
How do I make it work for both of us the same way? His machine doesn't like a tlbimp
imported interop, and mine doesn't like a primary
interop.
Remarks. Tlbimp.exe performs conversions on an entire type library at one time. You cannot use the tool to generate type information for a subset of the types defined within a single type library.
The PIA are simply assemblies that allow you to call the Office COM object model from . NET. The COM objects which are hosted by the Office applications still need to be present for this to work.
To use the features of a Microsoft Office application from an Office project, you must use the primary interop assembly (PIA) for the application. The PIA enables managed code to interact with a Microsoft Office application's COM-based object model.
we had a similar problem, and the option "tlbimp" worked on all computers.
My (imperfect) understanding is: .NET uses wrapper assemblies to access COM components. If you specify "primary", you use an existing, pre-generated "primary interop assembly". According to http://msdn.microsoft.com/en-us/library/hfac4fky.aspx, "primary interop assemblies are provided by the same publisher as the type library they describe". If using "primary" does not work for you, this assembly does not exist on your computer.
The default is "tlbimp" and (from what I gathered) should normally work. If it does not work on your coworker's machine, the error message would be helpful. Errors were reported for VS2003 (search for the KB article "You receive an error message when you add a reference to a COM object in Visual Studio .NET after you install Windows XP Service Pack 2"), but I do not know if this applies to current versions of VS.
If you cannot make this work, I would suggest that you could read more about "Primary Interop Assemblies" and try to find where the primary interop assembly for Excel is located on your coworker's machine, then copy it to the machines of all developers.
Hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With