com+, what more are needed?

  • Thread starter Thread starter Lasse Edsvik
  • Start date Start date
L

Lasse Edsvik

Hello

I'm trying to build a simple COM+ app in vs.net using C# and i cant register
it in component manager.....

what more is needed than this:

using System;

using System.EnterpriseServices;

namespace COMTest

{

/// <summary>

/// Summary description for Class1.

/// </summary>

public class Class1

{

public Class1() {}

public string WriteShit()

{

return "shite";

}

}

}
 
Aravind,

i still get "One or more files do not contain components or type libraries.
These files cannot be installed" :(

I assume that assembly stuff is just for transactions?

cant find a simple hello world app om msdn, its a djungle......

/Lasse
 
You are missing a few steps, basically the assembly attributes so that "Lazy
registration" can occur in the COM+ catalog. Without that step you have to
do an explicit regsvcs.exe. Here are the steps from a blog post of mine:
1.. Create a DLL project
2.. Add a Reference to System.EnterpriseServices
3.. Add a using declaration: using System.EnterpriseServices;
4.. Inherit your classes from ServicedComponent (i.e. public Widget :
ServicedComponent)
5.. Stick an [assembly: ApplicationName("ComPlusApp")] at the top so that
"COMPlusApp" or whatever is the name of the application when it is
registered in the COM+ catalog.
6.. Stick a strong name attribute at the top of the file [assembly:
AssemblyKeyFile("ComPlus.snk")]
7.. Go to the command line and generate a Strong Name sn -k ComPlus.snk
8.. If you have some method that performs a transaction, put
[AutoComplete] on top of it
9.. Build - This will lazy register the COM+ app in the COM+ catalog (In
some circumstances I will go into detail in a future article, you may have
to do use regsvcs.exe ComPlusApp.dll)
10.. Create a client that references System.EnterpriseServices and calls
your COM+ method(s)
11.. Run it
See http://samgentile.com/blog/archive/2003/06/25/7844.aspx

----
Sam Gentile [C#/.NET MVP]
..NET Blog http://samgentile.com/blog/
MSDN Column:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/html/bridge.asp
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Sam,

hmm, i fail at step 9 eventhough i've created COMTest.snk, should it be in
AssemblyInfo.cs?


looks like this now:

using System;

using System.EnterpriseServices;

[assembly: ApplicationName("COMTest")]

[assembly: AssemblyKeyFile("COMTest.snk")]

namespace COMTest

{

public class Class1 : ServicedComponent

{

public Class1() {}

public string WriteShit()

{

return "shite";

}







in Assemblyinfo.cs its:





[assembly: AssemblyDelaySign(false)]

[assembly: AssemblyKeyFile("")]

[assembly: AssemblyKeyName("")]





Sam Gentile said:
You are missing a few steps, basically the assembly attributes so that "Lazy
registration" can occur in the COM+ catalog. Without that step you have to
do an explicit regsvcs.exe. Here are the steps from a blog post of mine:
1.. Create a DLL project
2.. Add a Reference to System.EnterpriseServices
3.. Add a using declaration: using System.EnterpriseServices;
4.. Inherit your classes from ServicedComponent (i.e. public Widget :
ServicedComponent)
5.. Stick an [assembly: ApplicationName("ComPlusApp")] at the top so that
"COMPlusApp" or whatever is the name of the application when it is
registered in the COM+ catalog.
6.. Stick a strong name attribute at the top of the file [assembly:
AssemblyKeyFile("ComPlus.snk")]
7.. Go to the command line and generate a Strong Name sn -k ComPlus.snk
8.. If you have some method that performs a transaction, put
[AutoComplete] on top of it
9.. Build - This will lazy register the COM+ app in the COM+ catalog (In
some circumstances I will go into detail in a future article, you may have
to do use regsvcs.exe ComPlusApp.dll)
10.. Create a client that references System.EnterpriseServices and calls
your COM+ method(s)
11.. Run it
See http://samgentile.com/blog/archive/2003/06/25/7844.aspx

----
Sam Gentile [C#/.NET MVP]
.NET Blog http://samgentile.com/blog/
MSDN Column:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/html/bridge.asp
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
------


Lasse Edsvik said:
Aravind,

i still get "One or more files do not contain components or type libraries.
These files cannot be installed" :(

I assume that assembly stuff is just for transactions?

cant find a simple hello world app om msdn, its a djungle......

/Lasse
http://msdn.microsoft.com/library/en-us/dndotnet/html/entserv.asp?frame=true
 
Are you creating a COM+ server or library component? It makes a difference.
This is controlled by:
[assembly: ApplicationActivation(ActivationOption.Server)]

Or

[assembly: ApplicationActivation(ActivationOption.Library)]



While convenient, the lazy registration in step 9 does not work in many
scenarios as it requires Admin rights as well as other issues. So really the
right way. So the correct way that will work in all scenarios is replace
step 9 by:

9) gacutil.exe - i COMtest.dll (this puts it in the GAC)

10) regsvcs.exe COMtest.sll (this makes it a configured
coomponent in the COM+ catalog)


--
Sam Gentile [C#/.NET MVP]
..NET Blog http://samgentile.com/blog/
MSDN Column:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/html/bridge.asp
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
Lasse Edsvik said:
Sam,

hmm, i fail at step 9 eventhough i've created COMTest.snk, should it be in
AssemblyInfo.cs?


looks like this now:

using System;

using System.EnterpriseServices;

[assembly: ApplicationName("COMTest")]

[assembly: AssemblyKeyFile("COMTest.snk")]

namespace COMTest

{

public class Class1 : ServicedComponent

{

public Class1() {}

public string WriteShit()

{

return "shite";

}







in Assemblyinfo.cs its:





[assembly: AssemblyDelaySign(false)]

[assembly: AssemblyKeyFile("")]

[assembly: AssemblyKeyName("")]





Sam Gentile said:
You are missing a few steps, basically the assembly attributes so that "Lazy
registration" can occur in the COM+ catalog. Without that step you have to
do an explicit regsvcs.exe. Here are the steps from a blog post of mine:
1.. Create a DLL project
2.. Add a Reference to System.EnterpriseServices
3.. Add a using declaration: using System.EnterpriseServices;
4.. Inherit your classes from ServicedComponent (i.e. public Widget :
ServicedComponent)
5.. Stick an [assembly: ApplicationName("ComPlusApp")] at the top so that
"COMPlusApp" or whatever is the name of the application when it is
registered in the COM+ catalog.
6.. Stick a strong name attribute at the top of the file [assembly:
AssemblyKeyFile("ComPlus.snk")]
7.. Go to the command line and generate a Strong Name sn -k ComPlus.snk
8.. If you have some method that performs a transaction, put
[AutoComplete] on top of it
9.. Build - This will lazy register the COM+ app in the COM+ catalog (In
some circumstances I will go into detail in a future article, you may have
to do use regsvcs.exe ComPlusApp.dll)
10.. Create a client that references System.EnterpriseServices and calls
your COM+ method(s)
11.. Run it
See http://samgentile.com/blog/archive/2003/06/25/7844.aspx

----
Sam Gentile [C#/.NET MVP]
.NET Blog http://samgentile.com/blog/
MSDN Column:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/html/bridge.asp
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
http://msdn.microsoft.com/library/en-us/dndotnet/html/entserv.asp?frame=true
 
Sam,

trying to build a simple COM app that i'll use in regular ASP-pages

/Lasse


Sam Gentile said:
Are you creating a COM+ server or library component? It makes a difference.
This is controlled by:
[assembly: ApplicationActivation(ActivationOption.Server)]

Or

[assembly: ApplicationActivation(ActivationOption.Library)]



While convenient, the lazy registration in step 9 does not work in many
scenarios as it requires Admin rights as well as other issues. So really the
right way. So the correct way that will work in all scenarios is replace
step 9 by:

9) gacutil.exe - i COMtest.dll (this puts it in the GAC)

10) regsvcs.exe COMtest.sll (this makes it a configured
coomponent in the COM+ catalog)


--
Sam Gentile [C#/.NET MVP]
.NET Blog http://samgentile.com/blog/
MSDN Column:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/html/bridge.asp
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
Lasse Edsvik said:
Sam,

hmm, i fail at step 9 eventhough i've created COMTest.snk, should it be in
AssemblyInfo.cs?


looks like this now:

using System;

using System.EnterpriseServices;

[assembly: ApplicationName("COMTest")]

[assembly: AssemblyKeyFile("COMTest.snk")]

namespace COMTest

{

public class Class1 : ServicedComponent

{

public Class1() {}

public string WriteShit()

{

return "shite";

}







in Assemblyinfo.cs its:





[assembly: AssemblyDelaySign(false)]

[assembly: AssemblyKeyFile("")]

[assembly: AssemblyKeyName("")]





Sam Gentile said:
You are missing a few steps, basically the assembly attributes so that "Lazy
registration" can occur in the COM+ catalog. Without that step you
have
to
do an explicit regsvcs.exe. Here are the steps from a blog post of mine:
1.. Create a DLL project
2.. Add a Reference to System.EnterpriseServices
3.. Add a using declaration: using System.EnterpriseServices;
4.. Inherit your classes from ServicedComponent (i.e. public Widget :
ServicedComponent)
5.. Stick an [assembly: ApplicationName("ComPlusApp")] at the top so that
"COMPlusApp" or whatever is the name of the application when it is
registered in the COM+ catalog.
6.. Stick a strong name attribute at the top of the file [assembly:
AssemblyKeyFile("ComPlus.snk")]
7.. Go to the command line and generate a Strong Name sn -k ComPlus.snk
8.. If you have some method that performs a transaction, put
[AutoComplete] on top of it
9.. Build - This will lazy register the COM+ app in the COM+ catalog (In
some circumstances I will go into detail in a future article, you may have
to do use regsvcs.exe ComPlusApp.dll)
10.. Create a client that references System.EnterpriseServices and calls
your COM+ method(s)
11.. Run it
See http://samgentile.com/blog/archive/2003/06/25/7844.aspx

----
Sam Gentile [C#/.NET MVP]
.NET Blog http://samgentile.com/blog/
MSDN Column:
http://msdn.microsoft.com/library/d...ry/en-us/dndotnet/html/entserv.asp?frame=true
 
I've updated my blog topic.

--
Sam Gentile [C#/.NET MVP]
..NET Blog http://samgentile.com/blog/
MSDN Column:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/html/bridge.asp
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.

Sam Gentile said:
Are you creating a COM+ server or library component? It makes a difference.
This is controlled by:
[assembly: ApplicationActivation(ActivationOption.Server)]

Or

[assembly: ApplicationActivation(ActivationOption.Library)]



While convenient, the lazy registration in step 9 does not work in many
scenarios as it requires Admin rights as well as other issues. So really the
right way. So the correct way that will work in all scenarios is replace
step 9 by:

9) gacutil.exe - i COMtest.dll (this puts it in the GAC)

10) regsvcs.exe COMtest.sll (this makes it a configured
coomponent in the COM+ catalog)


--
Sam Gentile [C#/.NET MVP]
.NET Blog http://samgentile.com/blog/
MSDN Column:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/html/bridge.asp
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
Lasse Edsvik said:
Sam,

hmm, i fail at step 9 eventhough i've created COMTest.snk, should it be in
AssemblyInfo.cs?


looks like this now:

using System;

using System.EnterpriseServices;

[assembly: ApplicationName("COMTest")]

[assembly: AssemblyKeyFile("COMTest.snk")]

namespace COMTest

{

public class Class1 : ServicedComponent

{

public Class1() {}

public string WriteShit()

{

return "shite";

}







in Assemblyinfo.cs its:





[assembly: AssemblyDelaySign(false)]

[assembly: AssemblyKeyFile("")]

[assembly: AssemblyKeyName("")]





Sam Gentile said:
You are missing a few steps, basically the assembly attributes so that "Lazy
registration" can occur in the COM+ catalog. Without that step you
have
to
do an explicit regsvcs.exe. Here are the steps from a blog post of mine:
1.. Create a DLL project
2.. Add a Reference to System.EnterpriseServices
3.. Add a using declaration: using System.EnterpriseServices;
4.. Inherit your classes from ServicedComponent (i.e. public Widget :
ServicedComponent)
5.. Stick an [assembly: ApplicationName("ComPlusApp")] at the top so that
"COMPlusApp" or whatever is the name of the application when it is
registered in the COM+ catalog.
6.. Stick a strong name attribute at the top of the file [assembly:
AssemblyKeyFile("ComPlus.snk")]
7.. Go to the command line and generate a Strong Name sn -k ComPlus.snk
8.. If you have some method that performs a transaction, put
[AutoComplete] on top of it
9.. Build - This will lazy register the COM+ app in the COM+ catalog (In
some circumstances I will go into detail in a future article, you may have
to do use regsvcs.exe ComPlusApp.dll)
10.. Create a client that references System.EnterpriseServices and calls
your COM+ method(s)
11.. Run it
See http://samgentile.com/blog/archive/2003/06/25/7844.aspx

----
Sam Gentile [C#/.NET MVP]
.NET Blog http://samgentile.com/blog/
MSDN Column:
http://msdn.microsoft.com/library/d...ry/en-us/dndotnet/html/entserv.asp?frame=true
 
I got this error when building it:

Cryptographic failure while signing assembly 'C:\Documents and
Settings\Administrator\My Documents\Visual Studio
Projects\COMTest\obj\Release\COMTest.dll' -- 'The key container name
'COMPlus' does not exist'




Sam Gentile said:
I've updated my blog topic.

--
Sam Gentile [C#/.NET MVP]
.NET Blog http://samgentile.com/blog/
MSDN Column:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/html/bridge.asp
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.

Sam Gentile said:
Are you creating a COM+ server or library component? It makes a difference.
This is controlled by:
[assembly: ApplicationActivation(ActivationOption.Server)]

Or

[assembly: ApplicationActivation(ActivationOption.Library)]



While convenient, the lazy registration in step 9 does not work in many
scenarios as it requires Admin rights as well as other issues. So really the
right way. So the correct way that will work in all scenarios is replace
step 9 by:

9) gacutil.exe - i COMtest.dll (this puts it in the GAC)

10) regsvcs.exe COMtest.sll (this makes it a configured
coomponent in the COM+ catalog)


--
Sam Gentile [C#/.NET MVP]
.NET Blog http://samgentile.com/blog/
MSDN Column:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/html/bridge.asp
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
be
in
AssemblyInfo.cs?


looks like this now:

using System;

using System.EnterpriseServices;

[assembly: ApplicationName("COMTest")]

[assembly: AssemblyKeyFile("COMTest.snk")]

namespace COMTest

{

public class Class1 : ServicedComponent

{

public Class1() {}

public string WriteShit()

{

return "shite";

}







in Assemblyinfo.cs its:





[assembly: AssemblyDelaySign(false)]

[assembly: AssemblyKeyFile("")]

[assembly: AssemblyKeyName("")]





You are missing a few steps, basically the assembly attributes so that
"Lazy
registration" can occur in the COM+ catalog. Without that step you
have
to
do an explicit regsvcs.exe. Here are the steps from a blog post of mine:
1.. Create a DLL project
2.. Add a Reference to System.EnterpriseServices
3.. Add a using declaration: using System.EnterpriseServices;
4.. Inherit your classes from ServicedComponent (i.e. public
Widget
:
ServicedComponent)
5.. Stick an [assembly: ApplicationName("ComPlusApp")] at the top so
that
"COMPlusApp" or whatever is the name of the application when it is
registered in the COM+ catalog.
6.. Stick a strong name attribute at the top of the file [assembly:
AssemblyKeyFile("ComPlus.snk")]
7.. Go to the command line and generate a Strong Name sn -k ComPlus.snk
8.. If you have some method that performs a transaction, put
[AutoComplete] on top of it
9.. Build - This will lazy register the COM+ app in the COM+
catalog
(In
some circumstances I will go into detail in a future article, you
may
have
to do use regsvcs.exe ComPlusApp.dll)
10.. Create a client that references System.EnterpriseServices and calls
your COM+ method(s)
11.. Run it
See http://samgentile.com/blog/archive/2003/06/25/7844.aspx

----
Sam Gentile [C#/.NET MVP]
.NET Blog http://samgentile.com/blog/
MSDN Column:
http://msdn.microsoft.com/library/d...ry/en-us/dndotnet/html/entserv.asp?frame=true
 
C:\Documents and Settings\Administrator\My Documents\Visual Studio
Projects\COMTest\COMTest.cs(7): The type or namespace name 'AssemblyKeyFile'
could not be found (are you missing a using directive or an assembly
reference?)


and that one....... :(

/Lasse


Lasse Edsvik said:
I got this error when building it:

Cryptographic failure while signing assembly 'C:\Documents and
Settings\Administrator\My Documents\Visual Studio
Projects\COMTest\obj\Release\COMTest.dll' -- 'The key container name
'COMPlus' does not exist'




Sam Gentile said:
I've updated my blog topic.

--
Sam Gentile [C#/.NET MVP]
.NET Blog http://samgentile.com/blog/
MSDN Column:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/html/bridge.asp
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.

Sam Gentile said:
Are you creating a COM+ server or library component? It makes a difference.
This is controlled by:
[assembly: ApplicationActivation(ActivationOption.Server)]

Or

[assembly: ApplicationActivation(ActivationOption.Library)]



While convenient, the lazy registration in step 9 does not work in many
scenarios as it requires Admin rights as well as other issues. So
really
the
right way. So the correct way that will work in all scenarios is replace
step 9 by:

9) gacutil.exe - i COMtest.dll (this puts it in the GAC)

10) regsvcs.exe COMtest.sll (this makes it a configured
coomponent in the COM+ catalog)


--
Sam Gentile [C#/.NET MVP]
.NET Blog http://samgentile.com/blog/
MSDN Column:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/html/bridge.asp
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
Sam,

hmm, i fail at step 9 eventhough i've created COMTest.snk, should it
be
in
AssemblyInfo.cs?


looks like this now:

using System;

using System.EnterpriseServices;

[assembly: ApplicationName("COMTest")]

[assembly: AssemblyKeyFile("COMTest.snk")]

namespace COMTest

{

public class Class1 : ServicedComponent

{

public Class1() {}

public string WriteShit()

{

return "shite";

}







in Assemblyinfo.cs its:





[assembly: AssemblyDelaySign(false)]

[assembly: AssemblyKeyFile("")]

[assembly: AssemblyKeyName("")]





You are missing a few steps, basically the assembly attributes so that
"Lazy
registration" can occur in the COM+ catalog. Without that step you have
to
do an explicit regsvcs.exe. Here are the steps from a blog post of mine:
1.. Create a DLL project
2.. Add a Reference to System.EnterpriseServices
3.. Add a using declaration: using System.EnterpriseServices;
4.. Inherit your classes from ServicedComponent (i.e. public
Widget
:
ServicedComponent)
5.. Stick an [assembly: ApplicationName("ComPlusApp")] at the
top
so
that
"COMPlusApp" or whatever is the name of the application when it is
registered in the COM+ catalog.
6.. Stick a strong name attribute at the top of the file [assembly:
AssemblyKeyFile("ComPlus.snk")]
7.. Go to the command line and generate a Strong Name sn -k
ComPlus.snk
8.. If you have some method that performs a transaction, put
[AutoComplete] on top of it
9.. Build - This will lazy register the COM+ app in the COM+ catalog
(In
some circumstances I will go into detail in a future article, you may
have
to do use regsvcs.exe ComPlusApp.dll)
10.. Create a client that references System.EnterpriseServices and
calls
your COM+ method(s)
11.. Run it
See http://samgentile.com/blog/archive/2003/06/25/7844.aspx

----
Sam Gentile [C#/.NET MVP]
.NET Blog http://samgentile.com/blog/
MSDN Column:
http://msdn.microsoft.com/library/d...ry/en-us/dndotnet/html/entserv.asp?frame=true
 
Lasse Edsvik said:
Sam,

trying to build a simple COM app that i'll use in regular ASP-pages

/Lasse

Now I'm confused. So far it looked like you were trying to create a Serviced Component.
Now it sounds like you are trying to build a COM library for a scripted environment.

COM+ (and hence enterprise services) evolved from MTS, not COM (it simply uses COM).

Are you talking about ASP or ASP.NET? If you are talking about ASP.NET then a serviced component
can be used but so can any .NET "component". What features of the enterprise services
environment do you want to use?

Are you talking about old style ASP? Are trying to expose a .NET assembly to COM?

Then you may find the following interesting:

NET Framework Developer's Guide: Exposing .NET Framework Components to COM
http://msdn.microsoft.com/library/d.../cpconexposingnetframeworkcomponentstocom.asp

NET Framework Developer's Guide: Packaging an Assembly for COM
http://msdn.microsoft.com/library/d...cpguide/html/cpconpackagingassemblyforcom.asp


++ From: Alex K. Angelopoulos \(MVP\) ([email protected])
++ Subject: Building WSH-usable .NET components from the redistributables, revisited
++ Newsgroups: microsoft.public.dotnet.scripting, microsoft.public.scripting.vbscript,
++ microsoft.public.scripting.wsh, microsoft.public.windows.server.scripting, microsoft.public.scripting.jscript
++ Date: 2003-03-14 18:51:04 PST
++
++ [due to potential interest, cross-posted to microsoft.public.dotnet.scripting,
++ microsoft.public.scripting.vbscript, microsoft.public.scripting.wsh,
++ microsoft.public.windows.server.scripting, microsoft.public.scripting.jscript.
++ FOLLOWUP set to .wsh only]
++
++ Several days ago I made a couple of posts about building WSH (actually generic
++ COM) scriptable .NET components using the compilers built into the
++ redistributable. This is a followup detailing a somewhat cleaner method for
++ doing this. It will work with the C#, VB.NET, and JScript.NET compilers
++ currently.
++
++ The process involves compilation of a simple class file, then registering its
++ codebase. This means there is minimal name protection, so be certain to use a
++ long, unique class name!! The lack of strong naming means this is best targeted
++ at on-the-fly creation of "anonymous" COM classes which will be removed after
++ use; in fact, as I try to generalize the technique, it will be best to include
++ strong naming as a feature.
++
++ In any case, below is a generic batch file for creating the DLLs, followed by
++ brief demos in each of the 3 compilers mentioned. Comments welcome; followups
++ are set to microsoft.public.scripting.wsh.
++
++ ======================================================
++
++ 1. Compilation into a COM-Callable Library
++
++ There are two simple steps: compile to a library, and then register the
++ codebase. The batch file shown below will do this given a source file name as
++ an argument; it determines which compiler to call based on the source file's
++ extension. The compiled DLL will have the same base name as the source file.
++
++ @echo off
++ :: generic .NET library compiler script
++ :: get the extension into %ext%
++ set srcfile=%1
++ set ext=%srcfile:~-2%
++
++ :: get the basename into %basename%
++ CALL SET basename=%srcfile:~0,-3%%
++ echo basename is %basename%
++
++ :: set the correct compiler
++ set exc=%ext%c
++
++ %exc% /nologo /t:library %basename%.%ext%
++ regasm /nologo /codebase %basename%.dll
++
++ 2. Run A Script Calling The Library.
++
++ If the class is named "thisismyclass" and it exposes a public function
++ "testfunction", you can run it from VBScript like this:
++
++ set cls = CreateObject("thisismyclass")
++ rtn = cls.testfunction
++
++
++ Demo classfile sources and VBScript demos are included below for the
++ Jscript.NET, C#, and VB.NET.
++
++
++ %---------- Test Jscript.NET Class File ----------
++ class testcompiledjscriptnet
++ {
++ public function testreturn()
++ {
++ // display the number of commandline items
++ return("this is a string returned from a Jscript.Net library.");
++ }
++ }
++ %---------- VBScript to test Jscript.NET Library ----------
++ set js = CreateObject("testcompiledjscriptnet")
++ wscript.echo js.testreturn
++
++
++
++ %---------- Test C# Class File ----------
++ public class testcompiledcsharpnet
++ {
++ public string testreturn()
++ {
++ return("this is a string returned from a C# library.");
++ }
++ }
++
++
++ %---------- VBScript to test C# Library ----------
++ set cs = CreateObject("testcompiledcsharpnet")
++ wscript.echo cs.testreturn
++
++ %---------- Test VB.NET Class File ----------
++ ' Test
++ public class testcompiledvbnet
++ public function testreturn() as string
++ return("this is a string returned from a VB.Net library.")
++ end function
++ end class
++ %---------- VBScript to test VB.NET Library ----------
++ set vb = CreateObject("testcompiledvbnet")
++ wscript.echo vb.testreturn
++
++
++
++
++
++
++
++ --
++ Please respond in the newsgroup so everyone may benefit.
++ http://dev.remotenetworktechnology.com
++ (email requests for support contract information welcomed)
++ ----------
++ Subscribe to Microsoft's Security Bulletins:
++ http://www.microsoft.com/technet/security/bulletin/notify.asp
 
Cryptographic failure while signing assembly 'C:\Documents and
Settings\Administrator\My Documents\Visual Studio
Projects\COMTest\obj\Release\COMTest.dll' -- 'The key container name
'COMPlus' does not exist'

If you are building with VS.NET it builds in the obj directory. If you have
the strong key-pair file in the main directory the directive must be
[assembly: AssemblyKeyFile("..\..\COMTest.snk")]

Adjust for your use

--
Sam Gentile [C#/.NET MVP]
..NET Blog http://samgentile.com/blog/
MSDN Column:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/html/bridge.asp
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.


Lasse Edsvik said:
I got this error when building it:

Cryptographic failure while signing assembly 'C:\Documents and
Settings\Administrator\My Documents\Visual Studio
Projects\COMTest\obj\Release\COMTest.dll' -- 'The key container name
'COMPlus' does not exist'




Sam Gentile said:
I've updated my blog topic.

--
Sam Gentile [C#/.NET MVP]
.NET Blog http://samgentile.com/blog/
MSDN Column:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/html/bridge.asp
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.

Sam Gentile said:
Are you creating a COM+ server or library component? It makes a difference.
This is controlled by:
[assembly: ApplicationActivation(ActivationOption.Server)]

Or

[assembly: ApplicationActivation(ActivationOption.Library)]



While convenient, the lazy registration in step 9 does not work in many
scenarios as it requires Admin rights as well as other issues. So
really
the
right way. So the correct way that will work in all scenarios is replace
step 9 by:

9) gacutil.exe - i COMtest.dll (this puts it in the GAC)

10) regsvcs.exe COMtest.sll (this makes it a configured
coomponent in the COM+ catalog)


--
Sam Gentile [C#/.NET MVP]
.NET Blog http://samgentile.com/blog/
MSDN Column:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/html/bridge.asp
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
Sam,

hmm, i fail at step 9 eventhough i've created COMTest.snk, should it
be
in
AssemblyInfo.cs?


looks like this now:

using System;

using System.EnterpriseServices;

[assembly: ApplicationName("COMTest")]

[assembly: AssemblyKeyFile("COMTest.snk")]

namespace COMTest

{

public class Class1 : ServicedComponent

{

public Class1() {}

public string WriteShit()

{

return "shite";

}







in Assemblyinfo.cs its:





[assembly: AssemblyDelaySign(false)]

[assembly: AssemblyKeyFile("")]

[assembly: AssemblyKeyName("")]





You are missing a few steps, basically the assembly attributes so that
"Lazy
registration" can occur in the COM+ catalog. Without that step you have
to
do an explicit regsvcs.exe. Here are the steps from a blog post of mine:
1.. Create a DLL project
2.. Add a Reference to System.EnterpriseServices
3.. Add a using declaration: using System.EnterpriseServices;
4.. Inherit your classes from ServicedComponent (i.e. public
Widget
:
ServicedComponent)
5.. Stick an [assembly: ApplicationName("ComPlusApp")] at the
top
so
that
"COMPlusApp" or whatever is the name of the application when it is
registered in the COM+ catalog.
6.. Stick a strong name attribute at the top of the file [assembly:
AssemblyKeyFile("ComPlus.snk")]
7.. Go to the command line and generate a Strong Name sn -k
ComPlus.snk
8.. If you have some method that performs a transaction, put
[AutoComplete] on top of it
9.. Build - This will lazy register the COM+ app in the COM+ catalog
(In
some circumstances I will go into detail in a future article, you may
have
to do use regsvcs.exe ComPlusApp.dll)
10.. Create a client that references System.EnterpriseServices and
calls
your COM+ method(s)
11.. Run it
See http://samgentile.com/blog/archive/2003/06/25/7844.aspx

----
Sam Gentile [C#/.NET MVP]
.NET Blog http://samgentile.com/blog/
MSDN Column:
http://msdn.microsoft.com/library/d...ry/en-us/dndotnet/html/entserv.asp?frame=true
 
Didn't the compilation error tell you something like "Are you missing a
reference..."

If you look up AssemblyKeyFile attribute it is in System.Reflection.

So add:
using System.Reflection;

at the top

--
Sam Gentile [C#/.NET MVP]
..NET Blog http://samgentile.com/blog/
MSDN Column:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/html/bridge.asp
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
Lasse Edsvik said:
C:\Documents and Settings\Administrator\My Documents\Visual Studio
Projects\COMTest\COMTest.cs(7): The type or namespace name 'AssemblyKeyFile'
could not be found (are you missing a using directive or an assembly
reference?)


and that one....... :(

/Lasse


Lasse Edsvik said:
I got this error when building it:

Cryptographic failure while signing assembly 'C:\Documents and
Settings\Administrator\My Documents\Visual Studio
Projects\COMTest\obj\Release\COMTest.dll' -- 'The key container name
'COMPlus' does not exist'




Sam Gentile said:
I've updated my blog topic.

--
Sam Gentile [C#/.NET MVP]
.NET Blog http://samgentile.com/blog/
MSDN Column:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/html/bridge.asp
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.

Are you creating a COM+ server or library component? It makes a
difference.
This is controlled by:
[assembly: ApplicationActivation(ActivationOption.Server)]

Or

[assembly: ApplicationActivation(ActivationOption.Library)]



While convenient, the lazy registration in step 9 does not work in many
scenarios as it requires Admin rights as well as other issues. So really
the
right way. So the correct way that will work in all scenarios is replace
step 9 by:

9) gacutil.exe - i COMtest.dll (this puts it in the GAC)

10) regsvcs.exe COMtest.sll (this makes it a configured
coomponent in the COM+ catalog)


--
Sam Gentile [C#/.NET MVP]
.NET Blog http://samgentile.com/blog/
MSDN Column:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/html/bridge.asp
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no
rights.
Sam,

hmm, i fail at step 9 eventhough i've created COMTest.snk, should
it
be
in
AssemblyInfo.cs?


looks like this now:

using System;

using System.EnterpriseServices;

[assembly: ApplicationName("COMTest")]

[assembly: AssemblyKeyFile("COMTest.snk")]

namespace COMTest

{

public class Class1 : ServicedComponent

{

public Class1() {}

public string WriteShit()

{

return "shite";

}







in Assemblyinfo.cs its:





[assembly: AssemblyDelaySign(false)]

[assembly: AssemblyKeyFile("")]

[assembly: AssemblyKeyName("")]





You are missing a few steps, basically the assembly attributes
so
that
"Lazy
registration" can occur in the COM+ catalog. Without that step you
have
to
do an explicit regsvcs.exe. Here are the steps from a blog post of
mine:
1.. Create a DLL project
2.. Add a Reference to System.EnterpriseServices
3.. Add a using declaration: using System.EnterpriseServices;
4.. Inherit your classes from ServicedComponent (i.e. public Widget
:
ServicedComponent)
5.. Stick an [assembly: ApplicationName("ComPlusApp")] at the
top
so
that
"COMPlusApp" or whatever is the name of the application when it is
registered in the COM+ catalog.
6.. Stick a strong name attribute at the top of the file [assembly:
AssemblyKeyFile("ComPlus.snk")]
7.. Go to the command line and generate a Strong Name sn -k
ComPlus.snk
8.. If you have some method that performs a transaction, put
[AutoComplete] on top of it
9.. Build - This will lazy register the COM+ app in the COM+ catalog
(In
some circumstances I will go into detail in a future article,
you
may
have
to do use regsvcs.exe ComPlusApp.dll)
10.. Create a client that references System.EnterpriseServices and
calls
your COM+ method(s)
11.. Run it
See http://samgentile.com/blog/archive/2003/06/25/7844.aspx

----
Sam Gentile [C#/.NET MVP]
.NET Blog http://samgentile.com/blog/
MSDN Column:
http://msdn.microsoft.com/library/d...ry/en-us/dndotnet/html/entserv.asp?frame=true and
 
trying to build a simple COM app that i'll use in regular ASP-pages
Why are using ES/COM+ then? Do you have distributed transactions or other
needs that require COM+/ES services? If not, all you need is COM Interop

--
Sam Gentile [C#/.NET MVP]
..NET Blog http://samgentile.com/blog/
MSDN Column:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/html/bridge.asp
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
Lasse Edsvik said:
Sam,

trying to build a simple COM app that i'll use in regular ASP-pages

/Lasse


Sam Gentile said:
Are you creating a COM+ server or library component? It makes a difference.
This is controlled by:
[assembly: ApplicationActivation(ActivationOption.Server)]

Or

[assembly: ApplicationActivation(ActivationOption.Library)]



While convenient, the lazy registration in step 9 does not work in many
scenarios as it requires Admin rights as well as other issues. So really the
right way. So the correct way that will work in all scenarios is replace
step 9 by:

9) gacutil.exe - i COMtest.dll (this puts it in the GAC)

10) regsvcs.exe COMtest.sll (this makes it a configured
coomponent in the COM+ catalog)


--
Sam Gentile [C#/.NET MVP]
.NET Blog http://samgentile.com/blog/
MSDN Column:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/html/bridge.asp
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
be
in
AssemblyInfo.cs?


looks like this now:

using System;

using System.EnterpriseServices;

[assembly: ApplicationName("COMTest")]

[assembly: AssemblyKeyFile("COMTest.snk")]

namespace COMTest

{

public class Class1 : ServicedComponent

{

public Class1() {}

public string WriteShit()

{

return "shite";

}







in Assemblyinfo.cs its:





[assembly: AssemblyDelaySign(false)]

[assembly: AssemblyKeyFile("")]

[assembly: AssemblyKeyName("")]





You are missing a few steps, basically the assembly attributes so that
"Lazy
registration" can occur in the COM+ catalog. Without that step you
have
to
do an explicit regsvcs.exe. Here are the steps from a blog post of mine:
1.. Create a DLL project
2.. Add a Reference to System.EnterpriseServices
3.. Add a using declaration: using System.EnterpriseServices;
4.. Inherit your classes from ServicedComponent (i.e. public
Widget
:
ServicedComponent)
5.. Stick an [assembly: ApplicationName("ComPlusApp")] at the top so
that
"COMPlusApp" or whatever is the name of the application when it is
registered in the COM+ catalog.
6.. Stick a strong name attribute at the top of the file [assembly:
AssemblyKeyFile("ComPlus.snk")]
7.. Go to the command line and generate a Strong Name sn -k ComPlus.snk
8.. If you have some method that performs a transaction, put
[AutoComplete] on top of it
9.. Build - This will lazy register the COM+ app in the COM+
catalog
(In
some circumstances I will go into detail in a future article, you
may
have
to do use regsvcs.exe ComPlusApp.dll)
10.. Create a client that references System.EnterpriseServices and calls
your COM+ method(s)
11.. Run it
See http://samgentile.com/blog/archive/2003/06/25/7844.aspx

----
Sam Gentile [C#/.NET MVP]
.NET Blog http://samgentile.com/blog/
MSDN Column:
http://msdn.microsoft.com/library/d...ry/en-us/dndotnet/html/entserv.asp?frame=true
 
As am I,. You said COM+ in your original post. There is a huge difference
between COM and COM+.

--
Sam Gentile [C#/.NET MVP]
..NET Blog http://samgentile.com/blog/
MSDN Column:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/html/bridge.asp
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
UAError said:
Lasse Edsvik said:
Sam,

trying to build a simple COM app that i'll use in regular ASP-pages

/Lasse

Now I'm confused. So far it looked like you were trying to create a Serviced Component.
Now it sounds like you are trying to build a COM library for a scripted environment.

COM+ (and hence enterprise services) evolved from MTS, not COM (it simply uses COM).

Are you talking about ASP or ASP.NET? If you are talking about ASP.NET then a serviced component
can be used but so can any .NET "component". What features of the enterprise services
environment do you want to use?

Are you talking about old style ASP? Are trying to expose a .NET assembly to COM?

Then you may find the following interesting:

NET Framework Developer's Guide: Exposing .NET Framework Components to COM
http://msdn.microsoft.com/library/d.../cpconexposingnetframeworkcomponentstocom.asp

NET Framework Developer's Guide: Packaging an Assembly for COM
http://msdn.microsoft.com/library/d...cpguide/html/cpconpackagingassemblyforcom.asp


++ From: Alex K. Angelopoulos \(MVP\) ([email protected])
++ Subject: Building WSH-usable .NET components from the redistributables, revisited
++ Newsgroups: microsoft.public.dotnet.scripting, microsoft.public.scripting.vbscript,
++ microsoft.public.scripting.wsh, microsoft.public.windows.server.scripting,
microsoft.public.scripting.jscript
++ Date: 2003-03-14 18:51:04 PST
++
++ [due to potential interest, cross-posted to microsoft.public.dotnet.scripting,
++ microsoft.public.scripting.vbscript, microsoft.public.scripting.wsh,
++ microsoft.public.windows.server.scripting, microsoft.public.scripting.jscript.
++ FOLLOWUP set to .wsh only]
++
++ Several days ago I made a couple of posts about building WSH (actually generic
++ COM) scriptable .NET components using the compilers built into the
++ redistributable. This is a followup detailing a somewhat cleaner method for
++ doing this. It will work with the C#, VB.NET, and JScript.NET compilers
++ currently.
++
++ The process involves compilation of a simple class file, then registering its
++ codebase. This means there is minimal name protection, so be certain to use a
++ long, unique class name!! The lack of strong naming means this is best targeted
++ at on-the-fly creation of "anonymous" COM classes which will be removed after
++ use; in fact, as I try to generalize the technique, it will be best to include
++ strong naming as a feature.
++
++ In any case, below is a generic batch file for creating the DLLs, followed by
++ brief demos in each of the 3 compilers mentioned. Comments welcome; followups
++ are set to microsoft.public.scripting.wsh.
++
++ ======================================================
++
++ 1. Compilation into a COM-Callable Library
++
++ There are two simple steps: compile to a library, and then register the
++ codebase. The batch file shown below will do this given a source file name as
++ an argument; it determines which compiler to call based on the source file's
++ extension. The compiled DLL will have the same base name as the source file.
++
++ @echo off
++ :: generic .NET library compiler script
++ :: get the extension into %ext%
++ set srcfile=%1
++ set ext=%srcfile:~-2%
++
++ :: get the basename into %basename%
++ CALL SET basename=%srcfile:~0,-3%%
++ echo basename is %basename%
++
++ :: set the correct compiler
++ set exc=%ext%c
++
++ %exc% /nologo /t:library %basename%.%ext%
++ regasm /nologo /codebase %basename%.dll
++
++ 2. Run A Script Calling The Library.
++
++ If the class is named "thisismyclass" and it exposes a public function
++ "testfunction", you can run it from VBScript like this:
++
++ set cls = CreateObject("thisismyclass")
++ rtn = cls.testfunction
++
++
++ Demo classfile sources and VBScript demos are included below for the
++ Jscript.NET, C#, and VB.NET.
++
++
++ %---------- Test Jscript.NET Class File ----------
++ class testcompiledjscriptnet
++ {
++ public function testreturn()
++ {
++ // display the number of commandline items
++ return("this is a string returned from a Jscript.Net library.");
++ }
++ }
++ %---------- VBScript to test Jscript.NET Library ----------
++ set js = CreateObject("testcompiledjscriptnet")
++ wscript.echo js.testreturn
++
++
++
++ %---------- Test C# Class File ----------
++ public class testcompiledcsharpnet
++ {
++ public string testreturn()
++ {
++ return("this is a string returned from a C# library.");
++ }
++ }
++
++
++ %---------- VBScript to test C# Library ----------
++ set cs = CreateObject("testcompiledcsharpnet")
++ wscript.echo cs.testreturn
++
++ %---------- Test VB.NET Class File ----------
++ ' Test
++ public class testcompiledvbnet
++ public function testreturn() as string
++ return("this is a string returned from a VB.Net library.")
++ end function
++ end class
++ %---------- VBScript to test VB.NET Library ----------
++ set vb = CreateObject("testcompiledvbnet")
++ wscript.echo vb.testreturn
++
++
++
++
++
++
++
++ --
++ Please respond in the newsgroup so everyone may benefit.
++ http://dev.remotenetworktechnology.com
++ (email requests for support contract information welcomed)
++ ----------
++ Subscribe to Microsoft's Security Bulletins:
++ http://www.microsoft.com/technet/security/bulletin/notify.asp
 
Sam,

in this example i dont have to use transactions..... so i'll skip that and
learn that some other time then...

how i make this a "regular" COM app?


using System;

using System.EnterpriseServices;

[assembly: ApplicationName("COMTest")]

[assembly: AssemblyKeyFile("COMTest.snk")]

namespace COMTest

{

public class Class1 : ServicedComponent

{

public Class1() {}

public string WriteShit()

{

return "shite";

}

}

}



Sam Gentile said:
trying to build a simple COM app that i'll use in regular ASP-pages
Why are using ES/COM+ then? Do you have distributed transactions or other
needs that require COM+/ES services? If not, all you need is COM Interop

--
Sam Gentile [C#/.NET MVP]
.NET Blog http://samgentile.com/blog/
MSDN Column:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/html/bridge.asp
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
Lasse Edsvik said:
Sam,

trying to build a simple COM app that i'll use in regular ASP-pages

/Lasse


Sam Gentile said:
Are you creating a COM+ server or library component? It makes a difference.
This is controlled by:
[assembly: ApplicationActivation(ActivationOption.Server)]

Or

[assembly: ApplicationActivation(ActivationOption.Library)]



While convenient, the lazy registration in step 9 does not work in many
scenarios as it requires Admin rights as well as other issues. So
really
the
right way. So the correct way that will work in all scenarios is replace
step 9 by:

9) gacutil.exe - i COMtest.dll (this puts it in the GAC)

10) regsvcs.exe COMtest.sll (this makes it a configured
coomponent in the COM+ catalog)


--
Sam Gentile [C#/.NET MVP]
.NET Blog http://samgentile.com/blog/
MSDN Column:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/html/bridge.asp
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
Sam,

hmm, i fail at step 9 eventhough i've created COMTest.snk, should it
be
in
AssemblyInfo.cs?


looks like this now:

using System;

using System.EnterpriseServices;

[assembly: ApplicationName("COMTest")]

[assembly: AssemblyKeyFile("COMTest.snk")]

namespace COMTest

{

public class Class1 : ServicedComponent

{

public Class1() {}

public string WriteShit()

{

return "shite";

}







in Assemblyinfo.cs its:





[assembly: AssemblyDelaySign(false)]

[assembly: AssemblyKeyFile("")]

[assembly: AssemblyKeyName("")]





You are missing a few steps, basically the assembly attributes so that
"Lazy
registration" can occur in the COM+ catalog. Without that step you have
to
do an explicit regsvcs.exe. Here are the steps from a blog post of mine:
1.. Create a DLL project
2.. Add a Reference to System.EnterpriseServices
3.. Add a using declaration: using System.EnterpriseServices;
4.. Inherit your classes from ServicedComponent (i.e. public
Widget
:
ServicedComponent)
5.. Stick an [assembly: ApplicationName("ComPlusApp")] at the
top
so
that
"COMPlusApp" or whatever is the name of the application when it is
registered in the COM+ catalog.
6.. Stick a strong name attribute at the top of the file [assembly:
AssemblyKeyFile("ComPlus.snk")]
7.. Go to the command line and generate a Strong Name sn -k
ComPlus.snk
8.. If you have some method that performs a transaction, put
[AutoComplete] on top of it
9.. Build - This will lazy register the COM+ app in the COM+ catalog
(In
some circumstances I will go into detail in a future article, you may
have
to do use regsvcs.exe ComPlusApp.dll)
10.. Create a client that references System.EnterpriseServices and
calls
your COM+ method(s)
11.. Run it
See http://samgentile.com/blog/archive/2003/06/25/7844.aspx

----
Sam Gentile [C#/.NET MVP]
.NET Blog http://samgentile.com/blog/
MSDN Column:
http://msdn.microsoft.com/library/d...ry/en-us/dndotnet/html/entserv.asp?frame=true
 
Lasse Edsvik said:
Sam,

in this example i dont have to use transactions..... so i'll skip that and
learn that some other time then...

how i make this a "regular" COM app?

Serviced Components are totally different beasts !!!

But here is the process for creating a .NET component and
exporting it to COM:


1.) Create a Visual C# Project: Class Library

Name the project COMApp

Rename Class1.cs to CSharpClass.cs

2.) Create StrongName key

Open a "Visual Studio .NET command Prompt window"
Navigate to the project directory (e.g. COMApp)
then on the commandline

sn -k COMApp.key

3.) Im VS.NET go into the AssemblyInfo.cs and modify the following line:

[assembly: AssemblyKeyFile(@"..\..\COMApp.key")]

4.) In CSharp.cs enter the following code:


using System;
using System.Runtime.InteropServices;

namespace COMApp {
public class CSharpClass {

[ComVisible(true)]
public string MyMethod(){
return "This string comes from CSharpClass";
}
}
}


Build the Class Library

5) Go Back to the "Visual Studio .NET command Prompt window"
Navigate to the project's output directory (e.g. ..COMApp\bin\Debug)
then on the commandline

regasm /nologo /codebase COMApp.dll

6.) Test the component. Here I'm using windows script host. Create the test file COMTestApp.vbs:


' COMAppTest.vbs
set cls = CreateObject( "COMApp.CSharpClass" )
MsgBox cls.MyMethod()


Then run it in your command line window with:


wscript COMAppTest.vbs



You should see a "VBScript" message box with "This string comes from CSharpClass".
 
works in a .vbs file, but why cant i use it in a .asp page?

<%
set cls = CreateObject("shit.shitclass")
a=cls.WriteShit()
response.write(a)
%>


i get error on the createobject line........ and it doesnt matter if its
server.createobject......

/Lasse

UAError said:
Lasse Edsvik said:
Sam,

in this example i dont have to use transactions..... so i'll skip that and
learn that some other time then...

how i make this a "regular" COM app?

Serviced Components are totally different beasts !!!

But here is the process for creating a .NET component and
exporting it to COM:


1.) Create a Visual C# Project: Class Library

Name the project COMApp

Rename Class1.cs to CSharpClass.cs

2.) Create StrongName key

Open a "Visual Studio .NET command Prompt window"
Navigate to the project directory (e.g. COMApp)
then on the commandline

sn -k COMApp.key

3.) Im VS.NET go into the AssemblyInfo.cs and modify the following line:

[assembly: AssemblyKeyFile(@"..\..\COMApp.key")]

4.) In CSharp.cs enter the following code:


using System;
using System.Runtime.InteropServices;

namespace COMApp {
public class CSharpClass {

[ComVisible(true)]
public string MyMethod(){
return "This string comes from CSharpClass";
}
}
}


Build the Class Library

5) Go Back to the "Visual Studio .NET command Prompt window"
Navigate to the project's output directory (e.g. ..COMApp\bin\Debug)
then on the commandline

regasm /nologo /codebase COMApp.dll

6.) Test the component. Here I'm using windows script host. Create the test file COMTestApp.vbs:


' COMAppTest.vbs
set cls = CreateObject( "COMApp.CSharpClass" )
MsgBox cls.MyMethod()


Then run it in your command line window with:


wscript COMAppTest.vbs



You should see a "VBScript" message box with "This string comes from CSharpClass".
 
and when i register it in component manager the method wont show
anywhere......

/Lasse


Lasse Edsvik said:
works in a .vbs file, but why cant i use it in a .asp page?

<%
set cls = CreateObject("shit.shitclass")
a=cls.WriteShit()
response.write(a)
%>


i get error on the createobject line........ and it doesnt matter if its
server.createobject......

/Lasse

UAError said:
Lasse Edsvik said:
Sam,

in this example i dont have to use transactions..... so i'll skip that and
learn that some other time then...

how i make this a "regular" COM app?

Serviced Components are totally different beasts !!!

But here is the process for creating a .NET component and
exporting it to COM:


1.) Create a Visual C# Project: Class Library

Name the project COMApp

Rename Class1.cs to CSharpClass.cs

2.) Create StrongName key

Open a "Visual Studio .NET command Prompt window"
Navigate to the project directory (e.g. COMApp)
then on the commandline

sn -k COMApp.key

3.) Im VS.NET go into the AssemblyInfo.cs and modify the following line:

[assembly: AssemblyKeyFile(@"..\..\COMApp.key")]

4.) In CSharp.cs enter the following code:


using System;
using System.Runtime.InteropServices;

namespace COMApp {
public class CSharpClass {

[ComVisible(true)]
public string MyMethod(){
return "This string comes from CSharpClass";
}
}
}


Build the Class Library

5) Go Back to the "Visual Studio .NET command Prompt window"
Navigate to the project's output directory (e.g. ..COMApp\bin\Debug)
then on the commandline

regasm /nologo /codebase COMApp.dll

6.) Test the component. Here I'm using windows script host. Create the test file COMTestApp.vbs:


' COMAppTest.vbs
set cls = CreateObject( "COMApp.CSharpClass" )
MsgBox cls.MyMethod()


Then run it in your command line window with:


wscript COMAppTest.vbs



You should see a "VBScript" message box with "This string comes from CSharpClass".
 
To have a full understanding of how to do "regular" COM Interop, please read
my MSDN piece
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/html/bridge.asp

I am told that many people have found it very useful to understand all the
questions you are asking. Please read and then I'll be happy to answer any
remaining questions.
--------------------------------------------------------------
Sam Gentile [C#/.NET MVP]
..NET Blog http://samgentile.com/blog/
MSDN Column:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/html/bridge.asp
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
---------------------------------------------------------------
Lasse Edsvik said:
Sam,

in this example i dont have to use transactions..... so i'll skip that and
learn that some other time then...

how i make this a "regular" COM app?


using System;

using System.EnterpriseServices;

[assembly: ApplicationName("COMTest")]

[assembly: AssemblyKeyFile("COMTest.snk")]

namespace COMTest

{

public class Class1 : ServicedComponent

{

public Class1() {}

public string WriteShit()

{

return "shite";

}

}

}



Sam Gentile said:
trying to build a simple COM app that i'll use in regular ASP-pages
Why are using ES/COM+ then? Do you have distributed transactions or other
needs that require COM+/ES services? If not, all you need is COM Interop

--
Sam Gentile [C#/.NET MVP]
.NET Blog http://samgentile.com/blog/
MSDN Column:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/html/bridge.asp
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
Lasse Edsvik said:
Sam,

trying to build a simple COM app that i'll use in regular ASP-pages

/Lasse


Are you creating a COM+ server or library component? It makes a
difference.
This is controlled by:
[assembly: ApplicationActivation(ActivationOption.Server)]

Or

[assembly: ApplicationActivation(ActivationOption.Library)]



While convenient, the lazy registration in step 9 does not work in many
scenarios as it requires Admin rights as well as other issues. So really
the
right way. So the correct way that will work in all scenarios is replace
step 9 by:

9) gacutil.exe - i COMtest.dll (this puts it in the GAC)

10) regsvcs.exe COMtest.sll (this makes it a configured
coomponent in the COM+ catalog)


--
Sam Gentile [C#/.NET MVP]
.NET Blog http://samgentile.com/blog/
MSDN Column:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/html/bridge.asp
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no
rights.
Sam,

hmm, i fail at step 9 eventhough i've created COMTest.snk, should
it
be
in
AssemblyInfo.cs?


looks like this now:

using System;

using System.EnterpriseServices;

[assembly: ApplicationName("COMTest")]

[assembly: AssemblyKeyFile("COMTest.snk")]

namespace COMTest

{

public class Class1 : ServicedComponent

{

public Class1() {}

public string WriteShit()

{

return "shite";

}







in Assemblyinfo.cs its:





[assembly: AssemblyDelaySign(false)]

[assembly: AssemblyKeyFile("")]

[assembly: AssemblyKeyName("")]





You are missing a few steps, basically the assembly attributes
so
that
"Lazy
registration" can occur in the COM+ catalog. Without that step you
have
to
do an explicit regsvcs.exe. Here are the steps from a blog post of
mine:
1.. Create a DLL project
2.. Add a Reference to System.EnterpriseServices
3.. Add a using declaration: using System.EnterpriseServices;
4.. Inherit your classes from ServicedComponent (i.e. public Widget
:
ServicedComponent)
5.. Stick an [assembly: ApplicationName("ComPlusApp")] at the
top
so
that
"COMPlusApp" or whatever is the name of the application when it is
registered in the COM+ catalog.
6.. Stick a strong name attribute at the top of the file [assembly:
AssemblyKeyFile("ComPlus.snk")]
7.. Go to the command line and generate a Strong Name sn -k
ComPlus.snk
8.. If you have some method that performs a transaction, put
[AutoComplete] on top of it
9.. Build - This will lazy register the COM+ app in the COM+ catalog
(In
some circumstances I will go into detail in a future article,
you
may
have
to do use regsvcs.exe ComPlusApp.dll)
10.. Create a client that references System.EnterpriseServices and
calls
your COM+ method(s)
11.. Run it
See http://samgentile.com/blog/archive/2003/06/25/7844.aspx

----
Sam Gentile [C#/.NET MVP]
.NET Blog http://samgentile.com/blog/
MSDN Column:
http://msdn.microsoft.com/library/d...ry/en-us/dndotnet/html/entserv.asp?frame=true and
 
Back
Top