.NET classes hindering .net assembly from being com?

I posted an earlier thread about instanciating a .net assembly from a com client, like an asp page. My problem was that no matter what I did, I could not get the class to instaciate, so I could not call any methods on that class.

After quite a bit of trial and error, as far as weak and strong named assemblies, GAC, etc, I came to the conclusion that the object WAS being referenced properly, therefore it was not a problem getting access to the object's class declaration. My problem was that everytime I called a method on the object, I got a "object not set to instance" error.
Then it occurred to me to not use my testObject. Perhaps there was something wrong in it. So I created a simple object, tester, with one method: test(), which returned "hello". Anyway, I compiled that in VS.NET (with project properties set to com/interop) and then modified the ASP page to create the object and call the "test" method.
Lo and behold it worked!
Looking back at my class:
using System;
using System.Text;
using System.Web;
using System.IO;
namespace ogwebComLibrary
/// <summary>
/// Summary description for testObject.
/// </summary>
public class testObject{
public testObject(){
public string getText(){
StringWriter tw= new StringWriter();
StringBuilder sb=tw.GetStringBuilder();
string test=sb.ToString();
int bodyindex=test.LastIndexOf("<body");
int endBrace=test.IndexOf(">",bodyindex);
int bodyslashindex;
bodyindex=test.LastIndexOf("<input type=\"hidden\" name=\"__VIEWSTATE\"");
string test1=test.Substring(0,bodyindex);
int len= test.Length;
string test2=test.Substring(bodyslashindex+1);
return test;

the constructor is very simple and the getText() method is very straightforward. I am wondering, though, if the problem is the classes I am importing:
Do these classes interfere with the .NET assembly behaving as a com object? I am using an instance of StringWriter. Perhaps the StringWriter class is not visible as a com object. Or the HttpContext object (or any of its children). I don't think they should be, but obviously, one class is working fine as a COM and one isn't. The only difference is the imports and the getText() method, which method I tested and works fine, from an ASP.NET page.
Does anyone know of conflicts when importing System namespaces in a .NET object to be used as a COM?
Ian Ohlander
4/15/2004 10:20:13 PM
asp.net.integration 1945 articles. 0 followers. Follow

6 Replies

Similar Articles

[PageSpeed] 41

I would suspect "HttpContext.Current". I'd check that was valid before trying to use it. Given the COM+ interception and DLLHost becoming the .net root Application, I'd be a bit worried about that.

4/16/2004 1:21:49 PM
So any ideas on how I can get access to the Server object from a com method? 

Briefly, this is the task:
We are an Oil & Gas company and our website (which I redesigned entirely in .net) allows customers to log in. Once logged in, they are transferred to a 3rd party designed ASP web app that provides well data and trending and so forth. It also has the capability of providing the sending of commands to the wells, to change flow rates, emergency shut down, etc. Obviously, while providing a useful functionality, this is not something that just anyone who logs in should be able to do. So I created a login system that also has roles assigned to users and those roles govern what commands can be sent over the web.
In order to add a layer of protection, in addition to the disallowing of sending commands based on roles, is to modify the page where commands are sent so that if the logged user does not have permission for a command, that command will not appear. I have looked but have not been able to find and ASP equivalent to a "Panel" whose visibility can be toggled. I'm sure it can be done, but am not quite sure how.
So I came up with a different method. Build the command screen (the page with the well commands) AS an ASP.NET page (using panels, etc) and then process that page, including (from ASP.NET) checking the visibility of certain commands based on role, and send the outputted HTML (stripped of viewstate and HTML and BODY tags) into the ASP page the does the communicating with the wells. In other words, make the "VIEW" of the page be the ASP.NET page, while using the logic that I can't really change of the 3rd part ASP page.
To sum up. I need to stream the PROCESSED ASP.NET into a cell of another ASP page. And the Server.Execute method is not good enough because the outputted HTML contains html and body tags that interfere with those on the "parent" page. I suppose I could write a javascript function and get rid of those, as it does in the getText() method, so that might not be an issue. But then how do I toggle visibility of certain commands based on role?
4/16/2004 2:00:12 PM
All sounds overly complicated and I'm prob' missing a point but...

Why not use a UserControl. As the page renders it looks to see if the control should be rendered - I currently use this technique. You could embed the logic into the control itself...I just felt that I didn't want to go through the various phases for the control before it had enough info to realise it shouldn't be rendering - but it is a nicer approach. I say UserControl cause they're dead easy to convert a normal page to a user control - there's even a step-by-step guide in the help files/msdn.
4/16/2004 3:28:30 PM
That's a possibility, if everything was in ASP.NET. It's just that the wellDiagram page (which will contain those well commands) is an ASP page that uses includes that are shared by other ASP pages. It's part of a legacy 3rd party web-app that we need to continue to use. I suppose I could try to convert that page to ASP.NET, but then I'd have to convert the includes as well, so there'd be two versions of the "global" includes: classic and asp.net. Plus, I'd have to change the ASP pages that redirect to this page so they point to the ASP.NET versions. Seems like more work than its worth, might break the 3rd party app, and voids any support they give us on the app. So my dilemma is that I have to use wellDiagram.asp. It cannot be an ASP page.

What I'd like to do is show specific command UIs (such as a textbox and a button that sends the value in the textbox to the well) on the wellDiagram.asp based on the role the user has. If they're not in the role, then don't even bother showing that particular command UI.

Two issues then crop up:
1) I've been looking but haven't found how, in ASP, to basically hide/show page elements based on some criteria. Basically, just like the ASP.NET panel whose visibility you can toggle, based on any criteria you like. Sort of like, if you logged into a page as Admin, then you would see additional options. However, if you logged in as Guest User, you wouldn't see those elements on the page. That is what I need to do.
2) To check whether the user (who has a cookie on their computer with their UserID#) is in different roles, I wrote a loginManager in .net (part of my overall ASP.NET web app that is using the same user validation system for a few other things) with a checkRole(userID, requiredRole) method. The method is simply supposed to see if the roles the userID is in matches requiredRole. This is a .NET class, the loginManager. In order to show/hide the screen elements mentioned in 1 I need to check to see if the user is in that role using the .NET method.
And all that needs to be done in Classic ASP. Since I haven't found yet how to implement the ASP.NET's panel.visible toggle functionality in classic ASP, I thought of doing it all in ASP.NET and then streaming the processed result into the classic ASP I am stuck using. Which is why I wanted the modified Server.Execute method.
Confusing, I know. Basically, the need for access to a modified Server.execute function (that strips out the extra HTML, BODY tags in the returning executed page) stems from my need (and desire) to use ASP.NET functionality in building the classic ASP page's elements.
I hope that wasn't too confusing.
Thanks for responding.
4/16/2004 4:05:35 PM
Oh errr.

So my assumption is that you only need the .net code to check their roles?
Ok how about this...
Panel visibility emulation. Again, maybe missing the point but why not just use a simple IF..THEN e.g.

If objNetWrapper.InRole(GetObjectContext()) then
.... do your page stuff
.... %> sorry you're not allowed....

Then slightly alter you're not code to examine the HTTP object of the classic asp page. I might be slightly off with the passing of the context, maybe even "me", or just the REQUEST object will work but you get the idea.
An alternative is to use a web service or the XML HTTPRequest API. The Request API is really a low down n' dirty version of a web service so its pretty much the same idea. Although I'm still not 100% about how well you can flow the original callers http context.
I admit they don't sound the most elegant solutions but maybe you can make them great ;)
4/16/2004 5:02:07 PM
That sounds like that would work. I had hoped to avoid in-line code like that since this was going to be a template with many commands. But you gotta do what you gotta do, right? Thinking about it more and more makes me see that it should work nicely.

Thank you,
4/16/2004 6:31:40 PM

Similar Artilces:

------_=_NextPart_001_01C6429F.D89AA417 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Hello, Net::LDAP Net::LDAPS Is there a possible to LDAP bind with an encrypted (SHA, SSHA, CRYPT, ....) password? I don't like to write the secret password to the perl file. Best regards Barbara Wilbert ------_=_NextPart_001_01C6429F.D89AA417-- Wilbert Barbara (CI/OSI) * wrote: > Hello, > > Net::LDAP > Net::LDAPS > > Is there a possible to LDAP bind with an encrypted (SHA, SSHA, CRYPT, > ......

COM .NET Interop
Hi, I need help here.. I have this problem.I have COM VB6 that call a .NET class library, and this class library use the .NET SAP Conector to extract the information from SAP. I receive the information from SAP in a DataTable, the problem here is that I dont how to return this DataTable to VB6 COM. I made a test, and I can return a String to COM and basic types, but I dont know how to do it with this DataTable.Thanks for your helpI really appreciate. One alternative might be to add the DataTable to a DataSet and then convert the DataSet to an XML string using WriteXml(). That said, quic...

.NET to COM question ( Dictionary in COM and .NET dictionary)
 I need to write a data access code to replace the method of GetPerson() in COM data access, since the existing method is too slow. .NET can reduce the database round trips by using the dataset. The existing COM data access will stay except the GetPerson() method. So I am going to call the .NET getPerson() mehtod from the COM,  The original GetPerson() method in COM just go to data base, pull data from 7 tables and write to dictionary.  If the .NET getPerson() can populate the COM Dictionary, that would be great! I know .NET object can be directly assign t...

net send in .net
Hi,  I am trying to execute net send comman in my vb.net code. But I am getting "win32 exception unhandled error". Please help me. My code is:Dim psi As New ProcessStartInfo() psi.UseShellExecute = False psi.FileName = "Net send" 'xxx.xxx.xx.xx  - IP address of a system in my network psi.Arguments = "xxx.xxx.xx.xx test" Process.Start(psi)  Thanks in advance! Shwetha Tryu changing   psi.FileName = "Net send" 'xxx.xxx.xx.xx  - IP address of a system in my network psi.Arguments = "xxx.xxx.xx.xx test&quo...

converting to vb.net from c#.net authorize.net
authorize.net offered me some sample code when I signed up with them the only problem is the sample code is in c#.net but my page that they type all of their credit card into is vb.net <code><%@ Import Namespace="System.Net" %> <%@ Import Namespace="System.IO" %> <script language="C#" runat="server"> void Page_Load(Object Src, EventArgs E) { myPage.Text = readHtmlPage("https://certification.authorize.net/gateway/transact.dll"); } private String readHtmlPage(string url) { ...

To .NET or not .NET, that is the question
I'm running WinXP pro 32-bit, meaning I've got the version 1-dot-something of .NET that XP came with. I've been looking for various softwares, and more and more often come across .NET version 2 being prerequisite. No urgency for me re. my questions to this group - so far I have just decided to hit the red X on those download pages - but the desire for this newer version of .NET seems to be growing for me. Firstly, according to my (limited) research, newer .NET versions are inclusive of the previous ones, and the current version seems to be 3.5. So if I go for i...

Net Farmers net
Has anyone been able to access any of the tests at http://suicide.netfarmers.net ? I can get the default page but none of the tests appear to be operating over the last several weeks. -- CK I just tested and works as usual!!!Every session TCP_error,because my Shields_guard is intact<<G>> -- Regard: Joh@nnes� 1216771 Ont.Inc. "Nothing is more damaging to a new truth than an old error" "CK" <ckphalon@lascenltd.com> wrote in message news:9i45gg$1qa9$1@news.grc.com... : Has anyone been able to access any of the tests at : http://suicide...

Sending SMS using vb.net or C#.net using vb.net or c#.net
Hi  My requirement is I hav one csv file with these fields id,mobilenum,messgae,status.intiallu staus is 0. once i read the all fileds and take that mobile number.using tat mobile number  i need to send sms .after sending sms i shuld change status as 1 How to send sms thru coding (please dont provide any links.if it is provide also please give working links becox i checked codeproject .i didnt get any nice link. and also provide the how to update the status field im csv file   Thank ssandhya   To send SMS, you need some third party SMS providers. if you consul...

Differences between .net 1, .net 1.1, .net 2.0 and .net 3.0
Hi, This seems to be a common question, but i havent got an answer yet:(Can, any one please explain me the differences between these versions.If you keep your feet firmly on the ground, you'll have trouble putting on your pants! Have a look into this links http://en.wikipedia.org/wiki/.NET_Framework http://blogs.msdn.com/mohammadakif/archive/2006/12/03/net-3-0-different-versions-of-the-net-framework.aspx http://www.codeproject.com/aspnet/ComparisonASP1xASP20.aspAshok Rajawww.iGold.inDon't forget to click "Mark as Answer" on the post that helped you. This credits that m...

Differences between .net 1, .net 1.1, .net 2.0 and .net 3.0 #2
Hi, This seems to be a common question, but i havent got an answer yet:(Can, any one please explain me the differences between these versions.If you keep your feet firmly on the ground, you'll have trouble putting on your pants! There are too many differences for one email - - from 1.0 to 1.1 (not a whole lot of real change, other than fixes, at least compared to 1.1 to 2.0) With 2.0, there were many new declarative controls, with many new ideas added in With 3.0, it's a superset of 2.0 - instead of replacing the installation completely, it just 'added on' new functionality - I would...

vb.net vs c#.net vs j#.net
just out of curiousity which looks, acts most like java? i'm still learning trying to used to vb.net but it seems that it was easier to do some stuff with java. C# is Java++ in my opinion. If you have done C or Jave you will prefer C#.Mike Schellenberger - MCAD If you are looking for language similar to java go for J#. However most code samples you find on the net will be in VB.NET and C#....

PB!2.net consume .net Class
I new to .net and pb12.net . I would like to use the Filesystemwatcher class from the System.IO namespace in PB to monitor a folder. Here's code in c# that I found on the WEB ########################################################### ' Create a new FileSystemWatcher and set its properties. Dim watcher As New FileSystemWatcher() watcher.Path = args(1) ' Watch for changes in LastAccess and LastWrite times, and ' the renaming of files or directories. watcher.NotifyFilter = (NotifyFilters.LastAccess Or NotifyFilters.Las...

Call to non .net COM not working after .NET
I have developed small samples of ASP.NET and one of them I tried to call a standard COM (non .NET). I took the code out for now, but a call to that COM from traditional ASP application now does not work. Does anyone have an idea how to correct this?...

Integrating the C#.net and VB.net application
Hello All,  I'm trying to integrate the C#.net application and VB.net application.  Can you give me any suggestions of how to merge them.  Thanks in Advance You are probably goign to have to convert one of the applications to the other language at one point.  There are online conversion tools to help http://www.carlosag.net/Tools/CodeTranslator/- WilliamPlease mark the most helpful reply/replies as "Answer".Give some of my PWSK modules a try.  Type of application?We All move to our original place.Don't forget.Imran Baloch @weighfield: I d...

Web resources about - .NET classes hindering .net assembly from being com? - asp.net.integration

MySpace is Only Hindering Its Own Platform by Not Providing Better Public Metrics to Developers
As social network application platforms mature, public application engagement data is vital for the overall health of the developer ecosystem ...

'Systematic failures' hindering regulation of pubs and clubs
The regulation of Queensland clubs and pubs has been "hindered" by "systematic failures" of the government office charged with investigating ...

iPads helping or hindering infants?
iPads helping or hindering infants?

Lack of skilled staff hindering growth
Lack of skilled staff hindering growth People's Daily Online "A business is nothing without its people . A great team with an average plan ...

How Is Your Social Style Helping Or Hindering You?
... helping you? Hurting you? Image credit: Social sharing courtesy oksun70 – Fotolia.com The post How Is Your Social Style Helping Or Hindering ...

Aging in Adland: The Gray-Hair Phobia That's Hindering Older Execs
Meet Dave Shea, one of an army of over-55 advertising professionals fighting to stay relevant in a digital-obsessed world.

Man accused of hindering search for Auburn shooting suspect
CBC.ca Man accused of hindering search for Auburn shooting suspect Atlanta Journal Constitution By Mike Morris and Marcus K. Garner AUBURN, ...

Zimbabwe: Bad Policies Hindering Investment
allAfrica: African news and information for a global audience

Romney campaign “hindering” and “impeding” Hurricane Sandy relief
By not checking with the Red Cross, the Romney campaign is sending the wrong message about disaster relief. .

Sony Z Ultra Google Play edition bugs hindering usage
Google quietly released some new Google Play edition devices last week. These included the first GPe tablet, the LG G Pad 8.3 and the Sony Z ...

Resources last updated: 12/2/2015 10:04:04 PM