COM Interop Problem

G

glenn

I have a COM Server that I've written based on information from the book
..NET and COM / the complete Interop Guide. I have gotten the project to
compile and I've located the regasm.exe program that I was suppose to run
against my dll in order to generate a TLB file for the purposes of importing
the COM object into other programming lanugages such as Delphi.

However, when I try to import the type library into Delphi which I have done
hundreds of times with other components, I get build errors in the
mscorlib_tlb file that states that the Type Byte is not completely defined
as well as Illegal type in OLE automation section for Byte.

Can anyone tell me what is happening here and how to fix it as the book says
nothing of the issue.

thanks,


glenn
 
W

Willy Denoyette [MVP]

glenn said:
I have a COM Server that I've written based on information from the book
.NET and COM / the complete Interop Guide. I have gotten the project to
compile and I've located the regasm.exe program that I was suppose to run
against my dll in order to generate a TLB file for the purposes of
importing
the COM object into other programming lanugages such as Delphi.

However, when I try to import the type library into Delphi which I have
done
hundreds of times with other components, I get build errors in the
mscorlib_tlb file that states that the Type Byte is not completely defined
as well as Illegal type in OLE automation section for Byte.

Can anyone tell me what is happening here and how to fix it as the book
says
nothing of the issue.

thanks,


glenn

Could you post your code (or part of), and the regasm.exe command line
arguments used?
Not sure where mscorlib_tlb comes from, is this a Delphi generated typelib?
Did you try to create an instance and call a method from a simple
vb/Jscript?

Willy.
 
G

glenn

I have not tried Java as I don't know java. Here is the code and its pretty
much straight out of the book.

the book told me to run regasm "Com Server.dll" /tlb where Com Server just
happens to be what I named my test app. The tlb is being generated and
registered in the type library. In Delphi for any other COM object I just
go choose the object from the list and it builds the wrappers and adds it to
my component pallet to use. In this case however, I can not get it to wrap
the object due to these errors.

Thanks,

glenn
using System;

using System.Text.RegularExpressions;

using System.Reflection;

//[assembly:AssemblyKeyFile("KeyFile.snk")]



namespace COM_Server

{

/// <summary>

/// Summary description for validation.

/// </summary>

public class validation

{

public validation()

{

//

// TODO: Add constructor logic here

//

}


public bool IsPhoneNumber( string s )

{

return Regex.IsMatch(s,

@"^(((\(\d{3}\)( )?)|(\d{3}( |\-)))\d{3}\-\d{4})$");

}


public bool IsZipCode( string s )

{

return Regex.IsMatch(s, @"^((\d{5})|(\d{5}\-\d{4}))$");

}


public bool IsSSN( string s )

{

return Regex.IsMatch(s, @"^\d{3}\-\d{2}\-\d{4}$");

}


}

}
 
W

Willy Denoyette [MVP]

glenn said:
I have not tried Java as I don't know java. Here is the code and its
pretty
much straight out of the book.

the book told me to run regasm "Com Server.dll" /tlb where Com Server
just
happens to be what I named my test app. The tlb is being generated and
registered in the type library. In Delphi for any other COM object I just
go choose the object from the list and it builds the wrappers and adds it
to
my component pallet to use. In this case however, I can not get it to
wrap
the object due to these errors.

I mean Javascript not Java. Anyway here is a VBScript snippet that you can
use to test your code.

Dim obj
set obj = CreateObject("COM_Server.validation")
if (obj.IsPhoneNumber("123-235-4365") = true) then
WScript.Echo "It's valid"
end if

Save it as a test.vbs file and run it from the command line.
run:
cscript test.vbs
or simply
test.vbs

Note that still I'm not clear on the mscorlib_tlb file, wonder where does
this comes from?

Willy.
 
G

glenn

Not really sure but I"m starting to think its something Delphi is doing
because of the fact that the COM object has to use the mscorlib stuff in
order to interface properly and delphi therefore is attempting to import it
as well. I'm looking into it from that perspective anyway...

Thanks,

glenn
 
G

glenn

Note that all variables in VBS are VARIANT types.

yes, but this is my point. #1, I'm not calling a C# COM Object. I'm
calling an already existing COM object that I imported that was writting in
unmanaged code in another language.

C# Does not support variant types and therefore you can not execute the code
you listed for VB. They guy in the book says you must cast as object, but
that does not work either. At the moment I'm totally stuck...

thanks,

glenn
 
W

Willy Denoyette [MVP]

glenn said:
yes, but this is my point. #1, I'm not calling a C# COM Object. I'm
calling an already existing COM object that I imported that was writting
in
unmanaged code in another language.

C# Does not support variant types and therefore you can not execute the
code
you listed for VB. They guy in the book says you must cast as object, but
that does not work either. At the moment I'm totally stuck...

Sure it does, otherwise it would be useless and could not be used to interop
with Office and other COM server types, VARIANT types are marshaled as
System.Object.
But a VARIANT is a container for another type, like a BSTR or some other
oleautomation compatible type.
What type does your VARIANT return contain, what error do you get?
Can you post a code snip (just a method or part of) of you COM server code?

Willy.
 
G

glenn

Here is the line of code from C#...

object user = secure.m_getloggedinuser();

When that executes I get :

Loaded 'c:\source\temp\c#-com tests\com tests\com
client\bin\debug\interop.ssisecure.dll', No symbols loaded.

The program '[3700] COM Client.exe' has exited with code 0 (0x0).

The COM server is responding with a variant type that is cast to a string in
all my other clients. Here it appears I'm missing a step but I've followed
the instructions in the book...

Thanks,

glenn
 
G

glenn

There also seems to be something missing from the assembly altogether as I
also can not use regsvr32 to register the assembly as a COM object. It says
its missing its entry points and can't be loaded. This normally happens to
me in Delphi if I do not provide a proper exports section for the dll
related to the COM objects.

Did I perhaps miss something in my COM Server in C# that is making it not
export correctly?

Thanks,

glenn
 
W

Willy Denoyette [MVP]

glenn said:
There also seems to be something missing from the assembly altogether as I
also can not use regsvr32 to register the assembly as a COM object. It
says
its missing its entry points and can't be loaded. This normally happens
to
me in Delphi if I do not provide a proper exports section for the dll
related to the COM objects.

Did I perhaps miss something in my COM Server in C# that is making it not
export correctly?

Thanks,

glenn

C# assemblies exposing COM interfaces do not get registered using regsvr32.
You have to run regasm.exe.

regasm /codebase /tlb yourcsharp.dll

Check the commandline syntax by typing regasm /?

Willy.
 
W

Willy Denoyette [MVP]

glenn said:
Here is the line of code from C#...

object user = secure.m_getloggedinuser();

When that executes I get :

Loaded 'c:\source\temp\c#-com tests\com tests\com
client\bin\debug\interop.ssisecure.dll', No symbols loaded.

The program '[3700] COM Client.exe' has exited with code 0 (0x0).

The COM server is responding with a variant type that is cast to a string
in
all my other clients. Here it appears I'm missing a step but I've
followed
the instructions in the book...

Thanks,

glenn

I was talking about the COM server code, not the client part.
Did you try to run ildasm on the interop library to check the method
signature?

Willy.
 
W

Willy Denoyette [MVP]

glenn said:
Here is the line of code from C#...

object user = secure.m_getloggedinuser();

When that executes I get :

Loaded 'c:\source\temp\c#-com tests\com tests\com
client\bin\debug\interop.ssisecure.dll', No symbols loaded.

The program '[3700] COM Client.exe' has exited with code 0 (0x0).

The COM server is responding with a variant type that is cast to a string
in
all my other clients. Here it appears I'm missing a step but I've
followed
the instructions in the book...

Thanks,

glenn

The "No symbols loaded" message indicates there are no symbols available for
the interop assembly, not to worry about this is normal.
The exit message indicates a normal exit....
you will have to post some more code as I'm not clear on what follows.

Willy.
 
G

glenn

I tried but don't know file to open in order to do this.
I have never used that program before so not really sure what its doing
yet...

Also here is the total source for the server:


using System;

using System.Text.RegularExpressions;

using System.Reflection;

//[assembly:AssemblyKeyFile("KeyFile.snk")] this is actually provided for
in the assemblyInfo.cs file so its been done but over there

namespace COM_Server

{

/// <summary>

/// Summary description for validation.

/// </summary>

public class validation

{

public validation()

{

//

// TODO: Add constructor logic here

//

}


public bool IsPhoneNumber( string s )

{

return Regex.IsMatch(s,

@"^(((\(\d{3}\)( )?)|(\d{3}( |\-)))\d{3}\-\d{4})$");

}


public bool IsZipCode( string s )

{

return Regex.IsMatch(s, @"^((\d{5})|(\d{5}\-\d{4}))$");

}


public bool IsSSN( string s )

{

return Regex.IsMatch(s, @"^\d{3}\-\d{2}\-\d{4}$");

}


}

}


I then compiled and ran regasm mycom.dll /tlb and it did add it to the type
library list for COM objects because I can pick it to load into Delphi...
But I can't compile due to the other things I had listed earlier...
I also tried to import into delphi via the type library itself (tlb file)
but received the errors about it not being valid...

Thanks,

glenn

Willy Denoyette said:
glenn said:
Here is the line of code from C#...

object user = secure.m_getloggedinuser();

When that executes I get :

Loaded 'c:\source\temp\c#-com tests\com tests\com
client\bin\debug\interop.ssisecure.dll', No symbols loaded.

The program '[3700] COM Client.exe' has exited with code 0 (0x0).

The COM server is responding with a variant type that is cast to a string
in
all my other clients. Here it appears I'm missing a step but I've
followed
the instructions in the book...

Thanks,

glenn

I was talking about the COM server code, not the client part.
Did you try to run ildasm on the interop library to check the method
signature?

Willy.
 
G

glenn

one note: In the book he tells me to run:
csc /t:library Mycode.cs /r:System.dll and I did not do this step because I
do not have a csc.exe program anywhere on my hard drive that I can find. He
says its the c# command line compiler. Has it been renamed, is this step
what might be causing my problem?

Thanks,

glenn


glenn said:
I tried but don't know file to open in order to do this.
I have never used that program before so not really sure what its doing
yet...

Also here is the total source for the server:


using System;

using System.Text.RegularExpressions;

using System.Reflection;

//[assembly:AssemblyKeyFile("KeyFile.snk")] this is actually provided for
in the assemblyInfo.cs file so its been done but over there

namespace COM_Server

{

/// <summary>

/// Summary description for validation.

/// </summary>

public class validation

{

public validation()

{

//

// TODO: Add constructor logic here

//

}


public bool IsPhoneNumber( string s )

{

return Regex.IsMatch(s,

@"^(((\(\d{3}\)( )?)|(\d{3}( |\-)))\d{3}\-\d{4})$");

}


public bool IsZipCode( string s )

{

return Regex.IsMatch(s, @"^((\d{5})|(\d{5}\-\d{4}))$");

}


public bool IsSSN( string s )

{

return Regex.IsMatch(s, @"^\d{3}\-\d{2}\-\d{4}$");

}


}

}


I then compiled and ran regasm mycom.dll /tlb and it did add it to the type
library list for COM objects because I can pick it to load into Delphi...
But I can't compile due to the other things I had listed earlier...
I also tried to import into delphi via the type library itself (tlb file)
but received the errors about it not being valid...

Thanks,

glenn

Willy Denoyette said:
glenn said:
Here is the line of code from C#...

object user = secure.m_getloggedinuser();

When that executes I get :

Loaded 'c:\source\temp\c#-com tests\com tests\com
client\bin\debug\interop.ssisecure.dll', No symbols loaded.

The program '[3700] COM Client.exe' has exited with code 0 (0x0).

The COM server is responding with a variant type that is cast to a string
in
all my other clients. Here it appears I'm missing a step but I've
followed
the instructions in the book...

Thanks,

glenn

I was talking about the COM server code, not the client part.
Did you try to run ildasm on the interop library to check the method
signature?

Willy.
 
G

glenn

Actually I take that back. I finally found it and here is what I get when i
run the command he gave me.

error CS5001: Program 'c:\Source\Temp\C#-COM TESTS\COM Tests\COM
Server\validation.exe' does not have an entry point defined

Now, I have a project called "COM Server" and a unit called validation.cs
that is part of that program that actually contains all the code I sent you
earlier.

The above error is the result of running: csc validation.cs /r:System.dll

and I ran from the main source folder not the location where the dll exists
in debug.

Should VS 2003 already be doing these steps for me or is it required for me
to run this at the command line each time I want to compile a COM server
written in C#?

I still can not get this COM Server installed into Delphi...

P.S. Thanks for all your assistance and patience with me...

Thanks,

glenn


glenn said:
I tried but don't know file to open in order to do this.
I have never used that program before so not really sure what its doing
yet...

Also here is the total source for the server:


using System;

using System.Text.RegularExpressions;

using System.Reflection;

//[assembly:AssemblyKeyFile("KeyFile.snk")] this is actually provided for
in the assemblyInfo.cs file so its been done but over there

namespace COM_Server

{

/// <summary>

/// Summary description for validation.

/// </summary>

public class validation

{

public validation()

{

//

// TODO: Add constructor logic here

//

}


public bool IsPhoneNumber( string s )

{

return Regex.IsMatch(s,

@"^(((\(\d{3}\)( )?)|(\d{3}( |\-)))\d{3}\-\d{4})$");

}


public bool IsZipCode( string s )

{

return Regex.IsMatch(s, @"^((\d{5})|(\d{5}\-\d{4}))$");

}


public bool IsSSN( string s )

{

return Regex.IsMatch(s, @"^\d{3}\-\d{2}\-\d{4}$");

}


}

}


I then compiled and ran regasm mycom.dll /tlb and it did add it to the type
library list for COM objects because I can pick it to load into Delphi...
But I can't compile due to the other things I had listed earlier...
I also tried to import into delphi via the type library itself (tlb file)
but received the errors about it not being valid...

Thanks,

glenn

Willy Denoyette said:
glenn said:
Here is the line of code from C#...

object user = secure.m_getloggedinuser();

When that executes I get :

Loaded 'c:\source\temp\c#-com tests\com tests\com
client\bin\debug\interop.ssisecure.dll', No symbols loaded.

The program '[3700] COM Client.exe' has exited with code 0 (0x0).

The COM server is responding with a variant type that is cast to a string
in
all my other clients. Here it appears I'm missing a step but I've
followed
the instructions in the book...

Thanks,

glenn

I was talking about the COM server code, not the client part.
Did you try to run ildasm on the interop library to check the method
signature?

Willy.
 
W

Willy Denoyette [MVP]

glenn said:
I tried but don't know file to open in order to do this.
I have never used that program before so not really sure what its doing
yet...

Also here is the total source for the server:


using System;

using System.Text.RegularExpressions;

using System.Reflection;

//[assembly:AssemblyKeyFile("KeyFile.snk")] this is actually provided
for
in the assemblyInfo.cs file so its been done but over there

namespace COM_Server

{

/// <summary>

/// Summary description for validation.

/// </summary>

public class validation

{

public validation()

{

//

// TODO: Add constructor logic here

//

}


public bool IsPhoneNumber( string s )

{

return Regex.IsMatch(s,

@"^(((\(\d{3}\)( )?)|(\d{3}( |\-)))\d{3}\-\d{4})$");

}


public bool IsZipCode( string s )

{

return Regex.IsMatch(s, @"^((\d{5})|(\d{5}\-\d{4}))$");

}


public bool IsSSN( string s )

{

return Regex.IsMatch(s, @"^\d{3}\-\d{2}\-\d{4}$");

}


}

}


I then compiled and ran regasm mycom.dll /tlb and it did add it to the
type
library list for COM objects because I can pick it to load into Delphi...
But I can't compile due to the other things I had listed earlier...
I also tried to import into delphi via the type library itself (tlb file)
but received the errors about it not being valid...

Thanks,

glenn

Seems like we are running in circles, this is the same code you posted
before, and it's the sample in Nathan's book ch8.

I showed you how you could call it from a simple COM client (VBScript is a
COM client), just to prove nothing is wrong with the sample in the book.
So please do yourself a favor, save this in a file say test.vbs and run it
from the command line using:
cscript test.vbs
or simply
test

Dim obj
set obj = CreateObject("COM_Server.validation")
if (obj.IsPhoneNumber("123-235-4365") = true) then
WScript.Echo "It's valid"
end if

Make sure your C# assembly is registered with regasm /codebase yourdll /tlb

This should work with any COM oleautomation compliant client (including
Delphi), using VBScript is just for convenience.

Willy.
 
W

Willy Denoyette [MVP]

glenn said:
Actually I take that back. I finally found it and here is what I get when
i
run the command he gave me.

error CS5001: Program 'c:\Source\Temp\C#-COM TESTS\COM Tests\COM
Server\validation.exe' does not have an entry point defined

Now, I have a project called "COM Server" and a unit called validation.cs
that is part of that program that actually contains all the code I sent
you
earlier.

The above error is the result of running: csc validation.cs /r:System.dll

and I ran from the main source folder not the location where the dll
exists
in debug.

Should VS 2003 already be doing these steps for me or is it required for
me
to run this at the command line each time I want to compile a COM server
written in C#?

I still can not get this COM Server installed into Delphi...

P.S. Thanks for all your assistance and patience with me...

Thanks,

glenn

csc/t:library ....
this builds a library ( DLL).
What you are trying is to build an exe, the default when running csc without
/t:xxxxx

Your VS project should be set to build library and have the settings to
export it as a COM server.
Note that for small tests like this you better use the command line tools
like csc, regasm etc.
You'll be suprised how much you'll learn, things that are hidden by the
IDE....

Willy.
 
G

glenn

Ok, I'll stop bothering you with it then. The problem is, that it does not
work in Delphi and I do not know why. I"ve been programming for 12 years,
10 of them in Delphi and have worked with literally hundreds of COM servers
in my life and have never one time had a problem importing the type library
into Delphi. This happens to be the first C# COM server I've tried to
import and it will not import.

I'm only trying to figure out why.

Thanks for all the help and trouble,

glenn


Willy Denoyette said:
glenn said:
I tried but don't know file to open in order to do this.
I have never used that program before so not really sure what its doing
yet...

Also here is the total source for the server:


using System;

using System.Text.RegularExpressions;

using System.Reflection;

//[assembly:AssemblyKeyFile("KeyFile.snk")] this is actually provided
for
in the assemblyInfo.cs file so its been done but over there

namespace COM_Server

{

/// <summary>

/// Summary description for validation.

/// </summary>

public class validation

{

public validation()

{

//

// TODO: Add constructor logic here

//

}


public bool IsPhoneNumber( string s )

{

return Regex.IsMatch(s,

@"^(((\(\d{3}\)( )?)|(\d{3}( |\-)))\d{3}\-\d{4})$");

}


public bool IsZipCode( string s )

{

return Regex.IsMatch(s, @"^((\d{5})|(\d{5}\-\d{4}))$");

}


public bool IsSSN( string s )

{

return Regex.IsMatch(s, @"^\d{3}\-\d{2}\-\d{4}$");

}


}

}


I then compiled and ran regasm mycom.dll /tlb and it did add it to the
type
library list for COM objects because I can pick it to load into Delphi...
But I can't compile due to the other things I had listed earlier...
I also tried to import into delphi via the type library itself (tlb file)
but received the errors about it not being valid...

Thanks,

glenn

Seems like we are running in circles, this is the same code you posted
before, and it's the sample in Nathan's book ch8.

I showed you how you could call it from a simple COM client (VBScript is a
COM client), just to prove nothing is wrong with the sample in the book.
So please do yourself a favor, save this in a file say test.vbs and run it
from the command line using:
cscript test.vbs
or simply
test

Dim obj
set obj = CreateObject("COM_Server.validation")
if (obj.IsPhoneNumber("123-235-4365") = true) then
WScript.Echo "It's valid"
end if

Make sure your C# assembly is registered with regasm /codebase yourdll /tlb

This should work with any COM oleautomation compliant client (including
Delphi), using VBScript is just for convenience.

Willy.
 
G

glenn

But what do you mean about the proper settings made for the COM server? I
have done nothing here but write a C# dll library. I have done nothing to
tell this I'm working on a COM server except for running the regasm program
against it. Is there anything else in the program itself that must be told
that this is a COM server?

Thanks,

glenn
 
W

Willy Denoyette [MVP]

glenn said:
Ok, I'll stop bothering you with it then. The problem is, that it does
not
work in Delphi and I do not know why. I"ve been programming for 12 years,
10 of them in Delphi and have worked with literally hundreds of COM
servers
in my life and have never one time had a problem importing the type
library
into Delphi. This happens to be the first C# COM server I've tried to
import and it will not import.

I'm only trying to figure out why.

Thanks for all the help and trouble,

glenn

Not a problem, I'm just trying to help you out, therefore please try it with
the script first, if this works you can repost with "Subject: COM interop
fails with Delphi client", I'm sure of lot of posters are using Delphi and
C# in interop scenarios.
If it doesn't work with the script there must be something wrong elsewere.
Anyway it must work with the script as client else it won't work with Delphi
as client either.

Willy.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top