473,398 Members | 2,088 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,398 software developers and data experts.

class library

Hi !

I created a class library and in it I have a class that call
"ConfigurationManager" to find out what type of database I work and the
connection string.When I call this class from a form, everithing is running
well, no errors.When I call this class from a custom control I receive the
message "Object reference not set to an instance of an object"
Does anyoane know what is happening ?

Thanks,
Mihai
Oct 10 '06 #1
3 2360
It does not have context to the configuration file. You will have to set up
the context, as you are one step removed from the actual application. If you
run the application in debug and see which object is null (Nothing in
VB.NET), you should instantly see what I am talking about and it should be
clear.

When you use a library like this, you can pass the context up the stack and
then access the config. NOTE, however, that this tightly couples the library
to a UI, so it is better to pull the configuration information and pass it
up the stack.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
http://gregorybeamer.spaces.live.com

*************************************************
Think outside of the box!
*************************************************
"Mihai Velicu" <bv*****@telus.netwrote in message
news:alCWg.6771$P7.128@edtnps89...
Hi !

I created a class library and in it I have a class that call
"ConfigurationManager" to find out what type of database I work and the
connection string.When I call this class from a form, everithing is
running well, no errors.When I call this class from a custom control I
receive the message "Object reference not set to an instance of an object"
Does anyoane know what is happening ?

Thanks,
Mihai

Oct 10 '06 #2
Thank you for answering to my problem. Do you know any example for something
like this because really I don't understand what you mean.
So if I call this class from a custom control that reside in a controls
library , this class cannot acces configuration file where my connection
string is ?

So how I can pass the context to the stack?.Do I have to build a constructor
with parameters?
I apologize I ask but what I've read from the books and what you told me is
a long way. Maybe you can recommand me a book for this .

Thank you anyway
Mihai
"Cowboy (Gregory A. Beamer)" <No************@comcast.netNoSpamMwrote in
message news:eI**************@TK2MSFTNGP03.phx.gbl...
It does not have context to the configuration file. You will have to set
up the context, as you are one step removed from the actual application.
If you run the application in debug and see which object is null (Nothing
in VB.NET), you should instantly see what I am talking about and it should
be clear.

When you use a library like this, you can pass the context up the stack
and then access the config. NOTE, however, that this tightly couples the
library to a UI, so it is better to pull the configuration information and
pass it up the stack.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
http://gregorybeamer.spaces.live.com

*************************************************
Think outside of the box!
*************************************************
"Mihai Velicu" <bv*****@telus.netwrote in message
news:alCWg.6771$P7.128@edtnps89...
>Hi !

I created a class library and in it I have a class that call
"ConfigurationManager" to find out what type of database I work and the
connection string.When I call this class from a form, everithing is
running well, no errors.When I call this class from a custom control I
receive the message "Object reference not set to an instance of an
object"
Does anyoane know what is happening ?

Thanks,
Mihai


Oct 10 '06 #3
I'm using Factory model to determine at runtime what kind of database I'm
using and to get the connection string from app.config.

I'm using the "ConfigurationManager " static class provided by .Net
framework 2.0.

I marked in the code where the error is. I repeat again, from a form
everithing is running properly only from a user control that reside in a
control library is the problem. It seems I have to declare somehow the
static method in the code .
because the ConfigurationManager is a static method I cannot use New....

If you want to help me
Create a control library and in it, a control and put this code and try to
execute and you can see the results I mean the error message.You have to add
reference to System.Configuration.
Bellow is the code and App.Config.

Thank you very much !
Mihai

The code is :

Imports System
Imports System.Data
Imports System.Data.Common
Imports System.Configuration
Public Class NrSystemForAccounts
'Private gts As GenericDb.GenericDbWrapper.GenericTableServices
Private dt As DataTable
Private mConnectionString As String
Private mFactoryName As String
Private mFactory As DbProviderFactory
Private mFactoryConnection As DbConnection
Private mFactoryCommand As DbCommand
Private mDataAdapter As DbDataAdapter

Private Sub SetFactory(ByVal DataBaseConnectionName As String)

!!!!!!!! The error is in the line bellow :"Object reference not set to an
instance of an object"

mConnectionString =
ConfigurationManager.ConnectionStrings(DataBaseCon nectionName).ConnectionStr
ing.ToString()
mFactoryName =
ConfigurationManager.ConnectionStrings(DataBaseCon nectionName).ProviderName.
ToString()
mFactory = DbProviderFactories.GetFactory(mFactoryName)
End Sub

Private Sub NrSystemForAccounts_Load(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles MyBase.Load
Me.SetFactory("DatabaseConnection1")
End sub
End class
The App.config code is :

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<!-- This section defines the connections and database providers -->
<connectionStrings>

<add name="DatabaseConnection1"
connectionString="Persist Security Info=False;Integrated
Security=SSPI;database=Conta;server=(local);"
providerName="System.Data.SqlClient" />
<add name="DatabaseConnection2"
connectionString="" providerName="Oracle" />
</connectionStrings>

<system.diagnostics>
<sources>
<!-- This section defines the logging configuration for
My.Application.Log -->
<source name="DefaultSource" switchName="DefaultSwitch">
<listeners>
<add name="FileLog"/>
<!-- Uncomment the below section to write to the Application Event Log -->
<!--<add name="EventLog"/>-->
</listeners>
</source>
</sources>
<switches>
<add name="DefaultSwitch" value="Information" />
</switches>
<sharedListeners>
<add name="FileLog"
type="Microsoft.VisualBasic.Logging.FileLogTraceLi stener,
Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"
initializeData="FileLogWriter"/>
<!-- Uncomment the below section and replace APPLICATION_NAME with the name
of your application to write to the Application Event Log -->
<!--<add name="EventLog" type="System.Diagnostics.EventLogTraceListener"
initializeData="APPLICATION_NAME"/-->
</sharedListeners>
</system.diagnostics>
</configuration>

"Mihai Velicu" <bv*****@telus.netwrote in message
news:alCWg.6771$P7.128@edtnps89...
Hi !

I created a class library and in it I have a class that call
"ConfigurationManager" to find out what type of database I work and the
connection string.When I call this class from a form, everithing is
running well, no errors.When I call this class from a custom control I
receive the message "Object reference not set to an instance of an object"
Does anyoane know what is happening ?

Thanks,
Mihai

Oct 11 '06 #4

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

Similar topics

20
by: syd | last post by:
In my project, I've got dozens of similar classes with hundreds of description variables in each. In my illustrative example below, I have a Library class that contains a list of Nation classes. ...
6
by: Patrick | last post by:
Following earlier discussions about invoking a .NET class library via ..NET-COM Interop (using regasm /tlb) at...
4
by: Brian Shannon | last post by:
I am playing around with class libraries trying to understand how they work. I created a class library, library.vb. I placed the library.dll into the bin directory and set my reference. If I...
3
by: eBob.com | last post by:
I have several applications which mine web sites for personal information which they publish. They publish the info in one form, I transform the info into Excel spreadsheets. So all these...
5
by: Tony Johansson | last post by:
Hello! I have one solution file that consist of three project. One project that build the exe file called A One project that build a user control dll. Here we have a class called B One project...
0
by: tony | last post by:
Hello! I have one solution file that consist of three project. One project that build the exe file called A One project that build a user control dll. In this user control we have a class...
5
by: tony | last post by:
Hello! This is a rather long mail but it's a very interesting one. I hope you read it. I have tried several times to get an answer to this mail but I have not get any answer saying something...
5
by: Rainer Queck | last post by:
Hello NG, Is it possible to share the settings of an application with a class libreary? In my case I have a application and a set of different reports (home made) put into a class library. The...
0
by: drawing in aspnet | last post by:
Question about putting the data layer in a separate class library. I keep reading that the data layer should be separated from the presentation layer and put in its own class library. I am...
4
by: Steve Baer | last post by:
I've already tested this with C# and it works, but I'm being paranoid and I wanted to also check here. Our application has a large class library written in C++/CLI for plug-in projects. The...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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,...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...

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.