Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / July 2003

Tip: Looking for answers? Try searching our database.

Registry problems with .Net/COM interop

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Taft - 25 Jul 2003 10:13 GMT
I'm having a recurring problem which renders a .Net dll useless to the
COM clients I am distributing the dll to.

The .Net dll has been defined in all of the proper ways.  At the
assmbly level, I hardcode (with attributes) the GUID of the library
and the version of the library, as well as specifying that all classes
should not be COM visible by default.  I mark (again with attributes)
each class to be exported with a valid GUID as well as specifying that
the class is COM visible and not to generate a COM interface.  Instead
of generating the COM interfaces via tlbexp, I create the interfaces
myself, marking them with a valid GUID and as COM visible.  The
exported classes then implement the defined interfaces.

Also, I created a valid secrutiy key file and set my assembly to use
the key file with an attribute in the Assembly.cs file.

To compile the assembly, I use the Visual Studio Development
environment which places the resulting dll in the bin\Debug directory
of my project home. Then, from the command line, I issue the following
two commands:

regasm /codebase MyAssembly.dll
tlbexp MyAssembly.dll

Then, in a separate project, I try to import the .tlb file and
instance a class in the assembly using early binding.  Basically it
looks like this:

#import "mscorlib.tlb" rename("ReportEvent", "dotNetReportEvent")
#import "C:\\ThePathToMyDebugDir\\MyAssembly.tlb" no_namespace
named_guids

int _tmain(int argc, _TCHAR* argv[])
{
   CoInitialize(NULL);

   IMyClass1Ptr myClassInstance(__uuidof(MyClass1));

   IMyClass2Ptr anotherInstance;
   try
   {
       anotherInstance= myClassInstance->CreateAnObject("aParam");
   }
   catch (_com_error e)
   {
       printf("Dang!");
   }
}

I compile this code, and run it in debug mode.  It works. All is well
with the world.

Now, I decide that I want to change the location of the assembly on my
system (or I want to change some interfaces, etc. There are a variety
of circumstances that cause this to fail).  So I do the following
things:

1.  I copy the assembly dll to a new location.
2. I run 'regasm /u MyAssembly.dll' from the Debug directory to
unregister the types in my Assembly.
3. I cd to the new location of my assembly.
4. I run 'regasm /codebase MyAssembly.dll' to register the dll in the
new location.

Note that I did NOT recompile the .Net assembly.  I just copied it to
a new location.  Now I try running my C++ COM code again.  This time,
it gets to the line with: 'anotherInstance=
myClassInstance->CreateAnObject("aParam");' and COM throws an
exception stating: '0x80070002 The system cannot find the file
specified.'

At this point, no matter what I do, I cannot get the assembly to work
with my C++ COM client at its new location.

However, if I unregister the dll at its new location, then register
the dll at its original location (the Debug directory of the .Net
Assembly's project) the C++ COM client will often (though not always)
work again.

This has me stumped.  I've looked throught the registry and everything
looks fine.  But I suspect that SOME entry is not getting properly
deleted or added during the process of registering and unregistering
the .Net assembly.

Any thoughts or similar experiences on this subject would be greatly
appreciated.

Taft
Mattias Sj?gren - 27 Jul 2003 12:46 GMT
Taft,

I just tried the same setup you describe, and it works alright with
the assembly in both locations. So there must be something more to it.
How does the implementation of CreateAnObject look? Does it depend on
any other assemblies?

Mattias

Signature

Mattias Sjögren [MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.

Phil Wilson - 27 Jul 2003 17:31 GMT
If you're using the 1.1 framework, regasm makes an extra key under
InprocServer32 that is the version of the interop assembly as well as the
usual InprocServer32 key. Both of these keys have codebase entries (it's all
about side by side) and the default is to use the highest version key. You
may find that you have multiple codebase entries and you're always using the
older original location for some reason.
Signature

Phil Wilson [MVP Windows Installer]

> I'm having a recurring problem which renders a .Net dll useless to the
> COM clients I am distributing the dll to.
[quoted text clipped - 84 lines]
>
> Taft

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.