. Net and VBA (Excel) Interop issu-2147024894 (80070002)

Source: Internet
Author: User

I haven't written a blog for a long time

 

This issue is how to use the. net dll in COM.

When the local machine (win7) is developed, it can be used directly under COM, and there is no problem at all, but the dll is exported to other machines (windows xp, win 2003, win 7, etc) as shown in the following figure.

The reason is that Visual Studio automatically writes one to the Registry during local development:

HKEY_CLASSES_ROOT\CLSID\{71F5F31E-D86B-4FF1-89CA-BFCC3B8117BA}\InprocServer32\CodeBase=<path to your assembly>

But other machines do not have this. What should we do?

The solution is as follows:

1. If you have previously registered unregister old dll

C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727>RegAsm.exe /unregister ./ClientDLL
/TransferFile.dll
Microsoft (R) .NET Framework Assembly Registration Utility 2.0.50727.3053
Copyright (C) Microsoft Corporation 1998-2004. All rights reserved.

Types un-registered successfully

 

2. register again:

C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727>RegAsm.exe /codebase ./ClientDLL/T
ransferFile.dll
Microsoft (R) .NET Framework Assembly Registration Utility 2.0.50727.3053
Copyright (C) Microsoft Corporation 1998-2004. All rights reserved.

Types registered successfully

C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727>

Note: Before using/codebase, your dll must be singed. What is signed? See:

 

Best, test:

In Excel, you can call up the development interface directly by Alt + f11,

Test code:

Public Sub TestApp()
Dim obj As New TransferFile.TransferFile
Dim result As Boolean
result = False
result = obj.UploadFile("c:\xp_test.txt", "xp_test.txt", "D:\Test")
Debug.Print result
End Sub

 

Done.

There is another way to do this:

Put the DLL in GAC. Then register again. In this way, no/codebase is required during registration.

 

Reference: http://social.msdn.microsoft.com/Forums/nl-NL/clr/thread/65dc0c4a-a426-41a0-9e80-c7de37b10c73

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.