Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Registration Free Com Interop #23963

Closed
TonyValenti opened this Issue Apr 13, 2019 · 6 comments

Comments

Projects
None yet
3 participants
@TonyValenti
Copy link

TonyValenti commented Apr 13, 2019

Hi All,
I apologize in advance if this is not the right place to ask this kind of question.

I am using the Microsoft Office COM interop (Microsoft.Office.Interop.Word and Microsoft.Office.Interop.Outlook)

Often times customers have COM registry settings that aren't quite correct and it causes type mismatches when working with instances of the classes.

According to this article:
https://docs.microsoft.com/en-us/dotnet/framework/interop/registration-free-com-interop

It appears as though it is possible to tell my application not to use the registry to lookup COM information/types but I can't figure out how to do that with the assemblies above. Does anyone have any examples they can post?

@jkotas jkotas added the area-Interop label Apr 13, 2019

@jkotas

This comment has been minimized.

Copy link
Member

jkotas commented Apr 13, 2019

@jkotas jkotas added the question label Apr 13, 2019

@AaronRobinsonMSFT

This comment has been minimized.

Copy link
Member

AaronRobinsonMSFT commented Apr 13, 2019

@TonyValenti Great question. I have several interop examples in a repo https://github.com/AaronRobinsonMSFT/COMInterop.

Do you have a specific example of an issue you are hitting with respect to Office COM Interop?

@TonyValenti

This comment has been minimized.

Copy link
Author

TonyValenti commented Apr 13, 2019

@AaronRobinsonMSFT - Thanks for the help!
Here's an example coming from a client machine:
References:

Microsoft.Office.Interop.Word

Code:

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {

            var App = new Microsoft.Office.Interop.Word.Application();
            App.ShowMe();

        }
    }
}

Error:

System.InvalidCastException: 'Unable to cast COM object of type 'Microsoft.Office.Interop.Word.ApplicationClass' to interface type 'Microsoft.Office.Interop.Word._Application'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{00020970-0000-0000-C000-000000000046}' failed due to the following error: Error loading type library/DLL. (Exception from HRESULT: 0x80029C4A (TYPE_E_CANTLOADLIBRARY)).'

I notice that when I try to run the example, my reference to Microsoft.Office.Interop.Word also gets redirected to the GAC which I don't want.

Thoughts?

@AaronRobinsonMSFT

This comment has been minimized.

Copy link
Member

AaronRobinsonMSFT commented Apr 13, 2019

@TonyValenti This kind of issue was addressed by Type equivalence and embedded interop types. A video for Visual Studio 2010 also talks about how to enable the feature - the details still apply.

For Office there is also a .NET Core example that is almost identical to a .NET Framework project.

@TonyValenti

This comment has been minimized.

Copy link
Author

TonyValenti commented Apr 13, 2019

@AaronRobinsonMSFT I watched the video and it sounds like all I need to do is turn on "Embed Interop Types", however, I did that on the machine I'm getting teh error from and I still get that error. Any suggestions?

@AaronRobinsonMSFT

This comment has been minimized.

Copy link
Member

AaronRobinsonMSFT commented Apr 13, 2019

@TonyValenti That really should work. Please try the following demo and see if the same problem is observed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.