Hi Peter,
Thanks for the reply. We are almost done with your trick. the only thing
still in pending is that we are trying to "access the system registry
through our .NET assembly dll and we got to know that this is not working
due to default security settings".
The following is the code snippet:
============================================================================
===========================
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Win32; //for RegistryKey class-0
using System.Runtime.InteropServices;
namespace testClassLib
{
public interface IclsRegistry
{
void GetRegistryValues(string ApplicationRegistryKey);
}
public class clsRegistry : IclsRegistry
{
private string dBDatabase;
private string dBServerName;
private string dBUserName;
private string dBPassword;
private string cCScheduling;
private string xceedLicense;
private static RegistryKey GetKey(string baseKey, string subKey)
{
RegistryKey key;
/* --- Resolve (create or open) Base Key --- */
try
{
key = Registry.LocalMachine.OpenSubKey(baseKey, true);
if (key == null)
{
key = Registry.LocalMachine.CreateSubKey(baseKey);
}
else
{
Console.WriteLine("Base key resolved");
}
}
catch (Exception e)
{
// Exception logging omitted for brevity
return null;
}
/* --- Resolve (create or open) Sub Key --- */
try
{
key = Registry.LocalMachine.CreateSubKey(baseKey + "\\" +
subKey);
if (key == null)
{
throw (new Exception("Error creating SubKey"));
}
else
{
Console.WriteLine("Subkey resolved");
}
}
catch (Exception e)
{
// Exception logging omitted for brevity
return null;
}
return key;
}
/* Get registry values and populate the database setting variables
*/
public void GetRegistryValues(string ApplicationRegistryKey)
{
dBDatabase = clsRegistry.GetKey("Software",
ApplicationRegistryKey).GetValue("DBDatabase").ToString();
dBServerName = clsRegistry.GetKey("Software",
ApplicationRegistryKey).GetValue("DBServerName").ToString();
dBUserName = clsRegistry.GetKey("Software",
ApplicationRegistryKey).GetValue("DBUserName").ToString();
dBPassword = clsRegistry.GetKey("Software",
ApplicationRegistryKey).GetValue("DBPassword").ToString();
cCScheduling = clsRegistry.GetKey("Software",
ApplicationRegistryKey).GetValue("CCScheduling").ToString();
xceedLicense = clsRegistry.GetKey("Software",
ApplicationRegistryKey).GetValue("XceedLicense").ToString();
}
}
}
============================================================================
=============================
the following is the method call
============================================================================
=============================
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace testClassLib
{
[ClassInterface(ClassInterfaceType.AutoDual), ComVisible(true)]
public class testClass
{
public void TestMethod()
{
clsRegistry a = new clsRegistry();
a.GetRegistryValues("IPTV95"); //????? Call having
problem
}
}
}
============================================================================
=============================
============================================================================
=============================
The following is the ASP page in which the .NET class assembly object is
created.
Dim o
set o = Server.CreateObject("testClassLib.testClass")
Response.write o.TestMethod
============================================================================
=============================
============================================================================
=============================
The following is the error message being displayed in Internet Explorer when
the ASP page is executed.
============================================================================
=============================
Error Type:
testClassLib (0x80004003)
Object reference not set to an instance of an object.
/Vir/Default.asp, line 11
============================================================================
=============================
We would be grateful if you can provide us the solution regarding the above
stated problem.
All we need is to access the windows registry through our .NET class
assembly which is accessed through ASP Client.
Thanks in advance.
Murtaza
Post by "Peter Huang" [MSFT]Hi Murtaza,
For your scenario I suggest you try to restart IIS,
iisreset
Yes, we can create a .NET Class library and expose it to COM by using
regasm.
To troubleshoot the error, I high recommend you test with a simple .NET
class to see if that works.
1. Write a .NET class as below.
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace TestClassLib
{
[ClassInterface(ClassInterfaceType.AutoDual),ComVisible(true)]
public class TestClass
{
public string TestMethod()
{
return "Hello";
}
}
}
2. Compile it as register it to COM
regasm TestClassLib.dll /codebase
For test purpost I did not put it in GAC for now.
3. Write a asp page to test it.
<%
Dim o
set o = Server.CreateObject("TestClassLib.TestClass")
Response.Write(o.TestMethod())
%>
4. Result the asp page will show Hello in IE.
a. please perform the test and let me know the result, so that we will know
if this problem is code specific or environment specific
b. I think you may try the suggestions in my previous post, this will help
us isolate the problem, e.g. if there is any error when call CreateObject
or certian method, what is the method do and so on.
So if you could post a simple reproduce sample or some key code line will
help to do further troubleshooting.
Best regards,
Peter Huang
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.