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 / December 2004

Tip: Looking for answers? Try searching our database.

Why does COM not find the file?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Andrew S. Giles - 09 Dec 2004 15:51 GMT
I have written a C# executable, which I run regasm on to register it as a COM
class for use in some unmanaged C++ code.

Im the C++ code, I import the mscorlib.tlb and my .tlb file, declare some
interface variables, and start COM just fine... but when I try to get an
IUnknown interface pointer, or my custom interface pointer for the class I
exposed, I get the following error: "Class not registered" -OR- something
like could not find file.  

It does not list what file.

What am I doing wrong in the exporting of this C# class?

Thanks in advance

Andrew S. Giles
Andrew S. Giles - 09 Dec 2004 16:17 GMT
The actual other message is: "The system cannot find the file specified"

I am fairly sure that something is not being registered properly... but I do
not know how to fix this.

Andrew

> I have written a C# executable, which I run regasm on to register it as a COM
> class for use in some unmanaged C++ code.
[quoted text clipped - 12 lines]
>
> Andrew S. Giles
Eric Carlson - 09 Dec 2004 16:53 GMT
I think your c# executable needs to be in the same directory as your c++
program...

or

You should use the /Codebase option on the Regasm,

or

you should be using gacutil.exe to register your c# exe into the global
assembly cache.  (you need to strong name it for this)

> The actual other message is: "The system cannot find the file specified"
>
[quoted text clipped - 19 lines]
> >
> > Andrew S. Giles
Andrew S. Giles - 09 Dec 2004 17:27 GMT
OK, two of the 3 suggestions you made require me to give this
class/assembly/whatever it is now a "strong name"

I only have one example of doing this froma book, and that code gives me
compilation errors.

How does one give a class a strong name?

Andrew

> I think your c# executable needs to be in the same directory as your c++
> program...
[quoted text clipped - 31 lines]
> > >
> > > Andrew S. Giles
Eric Carlson - 09 Dec 2004 17:39 GMT
Sorry, forgot the codebase option requires strong name too.

It's easy.  Do you have .Net SDK docs?  Lookup "sn.exe"

This utility creates and key pair and outputs it to a file that you specify
such as mykey.snk, which you include in your project directory, and then add
the following line into your AssemblyInfo.cs file at the bottom (should
already be a line listed)

[assembly: AssemblyKeyFile("..\\..\\myKey.snk")]

You have to use the backslashes because it is referencing from the debug or
release directory where the assembly outputs to.

Does that help?
Andrew S. Giles - 09 Dec 2004 17:57 GMT
OK, Ive found it in the assemblyinfo.cs file now.

Will add my own name, and then run the sn.exe on it
sn -k filename.snk

Then I should be able to use /codebase or gacutil on the dll, right?

Andrew

> Sorry, forgot the codebase option requires strong name too.
>
[quoted text clipped - 11 lines]
>
> Does that help?
Eric Carlson - 09 Dec 2004 19:16 GMT
Correct.

If you use the gacutil, the assembly will be loaded in the Global Assembly
Cache (c:\windows\assembly) so that it can be used by all programs.

If you use the codebase option on Regasm.exe, the location of your exe will
be written into the registry, so that programs can find it.

Rate this thread:







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.