tags:

views:

49

answers:

3

Hi there,

I have a class library which is name ClassLib. And that lib has two folders (MedulaClasses and ParserClasses). MedulaClasses has a class which is name SGKDuyurulari.cs. And ParserClasses has a class which is name GeneralParser.cs. I write

SGKDuyurulari sd = new SGKDuyurulari()

in GeneralParser. but i have a runtime error. but error says just, The type initializer for 'ClassLib.MedulaClasses.SGKDuyurulari' threw an exception. and inner exception is "Object reference not set to an instance of an object.". I dont understand anythig. how can i access class from different folders.

Thanks for your help.

A: 

Hey,

To reference an object in another namespace, just add a using:

using ClassLib.MediaClasses;

But that isn't the error. The error is that code in the constructor is throwing an exception for some reason. Look in the constructor and see what is going on; if you post code, I can help you further.

Brian
public SGKDuyurulari() { }this is my cunstroctur. and i added using.
cagin
Yes, the error signals that some piece of code within SGKDuyurulari's constructor is the cause... Check out the code inside the constructor... To test, put a breakpoint there and see what's causing it... Sometimes constructors can hide the actual error.
Brian
A: 

check the constructor for SGKDuyurulari, is it using an uninitialized object?

[sometimes the folder structure affects the namespace, but if it compiles then that's not the problem]

Steven A. Lowe
+1  A: 

The exception you are getting ("type initializer") is associated with a static member. Do you have any static fields or a static constructor in SGKDuyurulari? Something like:

private static readonly string someString = CreateSomeString(); // whoops, throws exception at runtime.

or:

static SGKDuyurulari()
{
    // Do something in here that throws an exception at runtime.
}

These are both called the first time anything in your application accesses the type in any way.

Dave
It could be that the constructor expects static fields/properties to have been set prior to instantiation of the class..SGKDuyurulari.SetMe = "Cakes"SGKDuyurulari instance = new SGKDuyurulari()
Antony Koch