开发者

Class access problem

开发者 https://www.devze.com 2022-12-18 01:49 出处:网络
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 w

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 o开发者_开发问答f an object.". I dont understand anythig. how can i access class from different folders.

Thanks for your help.


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.


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.


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]

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号