473,387 Members | 1,619 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

COM object in static field

Hi all

I has Component inside ASP.NET page that create CO
object and store reference to it in the Component's privat
static field. Then I cast this reference to desired interfac
and call interface method. All works fine.(No exception throwed

Then I push button and the same ASP.NET page initiated again
Components private static field has reference to previously create
COM object. But when I try to cast this reference to COM interfac
I get InvalidCastException 'Specified cast is not valid.
I can not understand why. May be RCW lose pointer to interfac
between requesting page. Intresting if I create COM objec
on each page loading instead of storing reference to it in th
static field all works fine. And last, all of this with static field
with reference to COM in Windows Forms app works very well

ASP.NET and COM use STA threading model
I use custom RCW to interoperate with COM
I use ASP.NET 1.

Thanks.
Nov 18 '05 #1
3 1477

"Alexander" <xs****@rambler.ru> wrote in message
news:E3**********************************@microsof t.com...
Hi all.

I has Component inside ASP.NET page that create COM
object and store reference to it in the Component's private
static field. Then I cast this reference to desired interface
and call interface method. All works fine.(No exception throwed)

Then I push button and the same ASP.NET page initiated again.
Components private static field has reference to previously created
COM object. But when I try to cast this reference to COM interface
I get InvalidCastException 'Specified cast is not valid.'
I can not understand why. May be RCW lose pointer to interface
between requesting page. Intresting if I create COM object
on each page loading instead of storing reference to it in the
static field all works fine. And last, all of this with static fields
with reference to COM in Windows Forms app works very well.

ASP.NET and COM use STA threading model.
I use custom RCW to interoperate with COM.
I use ASP.NET 1.1

Thanks.


In a Windows Forms app, the pages are objects that (can) remain in memory.
In the ASP.Net environment, these objects remain alive just long enough to
process the page. When the HTML is sent to the client, the page-object is
destroyed. If you want to keep values between page-calls, you could use
the Session object.
I don't know if it is a good idea to store COM objects (in Session or
elsewhere), though.

Hans Kesting
Nov 18 '05 #2
> I don't know if it is a good idea to store COM objects (in Session or
elsewhere), though.
Depends on the design of the COM object. If it is designed for being used
stateful it might be OK. General rule however should be to design COM
objects stateless and then its not a good idea at all.

--
Martin Knopp
fecher GmbH
http://www.fecher.at

"Hans Kesting" <ne***********@spamgourmet.com> schrieb im Newsbeitrag
news:%2****************@TK2MSFTNGP11.phx.gbl...
"Alexander" <xs****@rambler.ru> wrote in message
news:E3**********************************@microsof t.com...
Hi all.

I has Component inside ASP.NET page that create COM
object and store reference to it in the Component's private
static field. Then I cast this reference to desired interface
and call interface method. All works fine.(No exception throwed)

Then I push button and the same ASP.NET page initiated again.
Components private static field has reference to previously created
COM object. But when I try to cast this reference to COM interface
I get InvalidCastException 'Specified cast is not valid.'
I can not understand why. May be RCW lose pointer to interface
between requesting page. Intresting if I create COM object
on each page loading instead of storing reference to it in the
static field all works fine. And last, all of this with static fields
with reference to COM in Windows Forms app works very well.

ASP.NET and COM use STA threading model.
I use custom RCW to interoperate with COM.
I use ASP.NET 1.1

Thanks.


In a Windows Forms app, the pages are objects that (can) remain in memory.
In the ASP.Net environment, these objects remain alive just long enough to
process the page. When the HTML is sent to the client, the page-object is
destroyed. If you want to keep values between page-calls, you could use
the Session object.
I don't know if it is a good idea to store COM objects (in Session or
elsewhere), though.

Hans Kesting

Nov 18 '05 #3
>Depends on the design of the COM object. If it is designed for being used
stateful it might be OK.


It's not that it isn't a good idea, you need to be informed enough to know
when to use it optimally.

Here are some pointers:
ASP.NET 1.0 storing non-serializable objects in session fail silently with
horribly consequences later. This is repaired in 1.1 to throw an exception.

COM objects stored in session must be serializable for out of proc mode. No
real serialization takes place for in-proc.

Serialization is expensive for COM objects because they aren't basic types
which requires the use of the binary serializer instead of a highly
optimized internal serializer for out of proc mode and state server.

There's also the age old problem of circular references and COM clean-up
issues with in-proc/out-of proc scenarios to be mindful of. But the
situation is much improved from classic ASP.

--
Regards,
Alvin Bruney [ASP.NET MVP]
Got tidbits? Get it here...
http://tinyurl.com/3he3b
"Martin Knopp" <ma**********@fecher.at> wrote in message
news:vr********************@news.chello.at...
I don't know if it is a good idea to store COM objects (in Session or
elsewhere), though.


Depends on the design of the COM object. If it is designed for being used
stateful it might be OK. General rule however should be to design COM
objects stateless and then its not a good idea at all.

--
Martin Knopp
fecher GmbH
http://www.fecher.at

"Hans Kesting" <ne***********@spamgourmet.com> schrieb im Newsbeitrag
news:%2****************@TK2MSFTNGP11.phx.gbl...

"Alexander" <xs****@rambler.ru> wrote in message
news:E3**********************************@microsof t.com...
Hi all.

I has Component inside ASP.NET page that create COM
object and store reference to it in the Component's private
static field. Then I cast this reference to desired interface
and call interface method. All works fine.(No exception throwed)

Then I push button and the same ASP.NET page initiated again.
Components private static field has reference to previously created
COM object. But when I try to cast this reference to COM interface
I get InvalidCastException 'Specified cast is not valid.'
I can not understand why. May be RCW lose pointer to interface
between requesting page. Intresting if I create COM object
on each page loading instead of storing reference to it in the
static field all works fine. And last, all of this with static fields
with reference to COM in Windows Forms app works very well.

ASP.NET and COM use STA threading model.
I use custom RCW to interoperate with COM.
I use ASP.NET 1.1

Thanks.


In a Windows Forms app, the pages are objects that (can) remain in memory. In the ASP.Net environment, these objects remain alive just long enough to process the page. When the HTML is sent to the client, the page-object is destroyed. If you want to keep values between page-calls, you could use
the Session object.
I don't know if it is a good idea to store COM objects (in Session or
elsewhere), though.

Hans Kesting


Nov 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Bijay Kumar | last post by:
Hi Guys, I was going through the source code of Object.cs in rotor. What I found is Equals() implemented as follows: public extern virtual bool Equals(Object obj); What I don't...
0
by: Bijay Kumar | last post by:
Hi Guys, I was going through the source code of Object class (Object.cs in rotor). What I found is Equals() implemented as follows: public extern virtual bool Equals(Object obj); What...
7
by: Chris Clement | last post by:
I have been handed a project that someone else started and most of it was developed in the VS.NET design mode. For whatever reasons, when I try to make changes to the controls in VS.NET design...
5
by: lion | last post by:
in .net, if you set annstance-A of a class equal to another instance-B, a pointer will add to B, but if i want to create a copy of B instead of pointer, how to operate? Note:serialization...
15
by: randyr | last post by:
I am developing an asp.net app based on a previous asp application. in the asp applications global.asa file I had several <object id="id" runat="server" scope="scope" class="comclass"> tags for...
2
by: Beffmans | last post by:
Hi When I run this code: using System; namespace DelegateProject { public delegate void MyDelegate(string s);
5
by: Rich | last post by:
The following code produced a singleton object with application scope when it should have had page scope: public class Singleton { private static Singleton uniqueInstance = null; private...
6
by: tshad | last post by:
I am getting the following error for: C:\VSProjects\ClassLibrary4\NewHire.cs(72): An object reference is required for the nonstatic field, method, or property 'MyFunctions.NewHire.firstName' ...
6
by: Shailen Sukul | last post by:
Observed a weird behaviour with object references. See code listing below: using System; using System.Collections.Generic; using System.Text; namespace PointerExceptionTest { /*
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.