473,657 Members | 2,489 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to call custom config section from com interop

1 New Member
I have a huge complex app.config and one of the sections in the config is connection strings.
I have a dot net class that uses this app.config and a com interop is generated for this dot net class. I developed an unmanaged c++ app and it calls the com interop tlb. The problem I was getting was when I call from C++ the tlb I get an null reference exception at the following line in .NetClass:
Expand|Select|Wrap|Line Numbers
  1.                 MessageBox.Show(System.Configuration.ConfigurationManager.ConnectionStrings["TestConnString"].ConnectionString);
If I run in c# alone it has no problem identifying the connection string.
Does any one has any idea?.
I dont want to put the connection in app settings(which is visible for com interop) because this would involve a significant change in the application. Added to this there are numerous tags I need to read and retrieve
Thanks for any suggestions in advance



DotNet Class:
Expand|Select|Wrap|Line Numbers
  1. using System.ComponentModel;
  2. using System.Data;
  3. using System.Drawing;
  4. using System.Text;
  5. using System.Windows.Forms;
  6. using System.Runtime.InteropServices;
  7.  
  8. namespace NetClass
  9. {
  10.     [Guid("E4F73391-D64D-401a-B0B5-7C4559043313")]
  11.     public interface IForm
  12.     {
  13.         void LaunchTestForm();
  14.     }
  15.  
  16.     [Guid("2DF7C2CE-1068-4ff0-A053-0F641070568C")]
  17.     [ClassInterface(ClassInterfaceType.None)] 
  18.     public class TestClass : IForm
  19.     {
  20.         public TestClass()
  21.         {
  22.         }
  23.         public void LaunchTestForm()
  24.         {
  25.             try
  26.             {
  27.                 MessageBox.Show(System.Configuration.ConfigurationManager.ConnectionStrings["TestConnString"].ConnectionString);
  28.                 Form1 frm = new Form1();
  29.                 frm.ShowDialog();
  30.             }
  31.             catch (Exception ex)
  32.             {
  33.                 MessageBox.Show(ex.ToString());
  34.             }
  35.  
  36.         }
  37.     }
  38. }
  39.  
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="utf-8" ?>
  2. <configuration>
  3.     <connectionStrings>
  4.         <add name="TestConnString" connectionString="Data Source=someserver;Initial Catalog=somedb;User ID=someuserid;Password=somepassword"
  5.           providerName="System.Data.SqlClient" />
  6.     </connectionStrings>
  7. </configuration>
  8.  
C++ WIN32 CONSOLE Application:

Expand|Select|Wrap|Line Numbers
  1. CoInitialize(NULL);    
  2.  
  3. NetClass::IFormPtr ptr;    
  4. HRESULT hRes = ptr.CreateInstance(NetClass::CLSID_TestClass);
  5.  
  6. if (hRes == S_OK)
  7. {
  8. ptr->LaunchTestForm();
  9. }
Aug 27 '08 #1
0 963

Sign in to post your reply or Sign up for a free account.

Similar topics

0
1838
by: Søren Lund | last post by:
Hello, I have implemented a custom config section handler by implementing the IConfigurationSectionHandler interface. I have registered this handler in web.config and everything works fine ... for a while. At random points in time my section handler stops working and throws the exception: Configuration Error Description: An error occurred during the processing of a configuration
6
3795
by: Tabi | last post by:
Hi, I want to create a custom section in my web.config that can hold my custom values. I created a section in web.config as written below. <configSections> <section name="myCustomSection" type="ComIT.Applications.Common.ConfigurationSections.MyHandler" allowLocation="true" allowDefinition="Everywhere" /> </configSections>
0
1679
by: george_Martinho | last post by:
It seems that the ASP.NET Microsoft team didn't think about this!! The profilemanager class has the following methods: - DeleteInactiveProfiles. Enables you to delete all profiles older than a specified date. - DeleteProfile. Enables you to delete a profile associated with a specified username. - DeleteProfiles. Enables you to delete a set of profiles. - FindInactiveProfilesByUserName. Returns a collection of ProfileInfo
2
1531
by: Laurent Bugnion | last post by:
Hi, I like to develop custom controls for a number of webpages. These controls are often customizable, so that they can be reused in a number of situations. My question is: What is the best practice for configuring a custom control. As far as I can say, I have the following alternatives: - Defining properties for the control, and setting these in the ASPX
6
4800
by: Jeff Hegedus | last post by:
I have a dll that requires some configuration data. I put the configuration data in a custom configuration section in a config file that is loaded in the installation folder of the dll. If I install the dll to the same directory as the exe which uses it, everything works as expected but if I load the dll in any other directory, I get the following error... 2007-02-04 16:36:51,171 DEBUG CentrifugeBHO.CentrifugeBHO - dllPath =...
7
10823
by: =?Utf-8?B?RG91Z2llIEJyb3du?= | last post by:
Hi I've written custom configuration section (inherits from System.Configuration.ConfigurationSection) to simplify the contents of the config file and to make life easier when accessing them in code. The configuration section is contained within the exe (it's a simple test case!) and everything works well debugging within the IDE or if the application is deployed on a drive or share that has been granted full trust. For the share the...
2
5106
by: Smithers | last post by:
I have a Windows Forms application that implements a plug-in architecture whereby required assemblies are identified and loaded dynamically. Here are the relevant classes: A = application = Windows Forms class B = a singleton hosted within A. B is responsible for dynamically loading classes X, Y, and Z.
0
1619
by: =?Utf-8?B?UGhpbGlw?= | last post by:
I have a web.config custom configuration section using asp.net 2.0 configuration APIs. My custom configuration section inherits from System.Configuration.ConfigurationSection. I have a IIS root level web.config and an application level web.config, with the application web.config inheriting from the root level web.config. I am receiving the following message when compiling the web application... "....Section or group name...
0
1235
by: =?Utf-8?B?TWlrZQ==?= | last post by:
We have a legacy application that has to be integrated with new .net 2.0 our library. We marked our .net assemply as COM-visible and registered it. We are using a custom configuration manager that reads config file using location of the corresponding .net dll. Our requirement is that VB application should be in a separate folder from the .net class library. When we try to get our custom configuration section from .net that is being called...
0
8392
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8305
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8823
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
7320
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4151
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4301
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1944
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1604
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.