Link to home
Start Free TrialLog in
Avatar of Mikal613
Mikal613Flag for United States of America

asked on

Cannot access Module from Project. The type initializer for 'MyProject.modCons' threw an exception.

I have a simple project that contains a Module so i can hold my global connection (Thats how it was when i got it). When i access any method or property i get an exception.
The type initializer for 'MyProject.modCons' threw an exception.

I eben tried a simple helloworld method and still i get the same error.
SOLUTION
Avatar of iboutchkine
iboutchkine

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Mikal613

ASKER

only what i need in the module is Public. I have public properties and private variables.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Ive seen that before. But i would like to know why I am getting the error.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
So what should i do to fix it?
Yes, well how does the module get generated in IL?  What .NET version are you using?  

Bob
Visual Studio 2005
Framework 2.0
Avatar of multithreading
multithreading

The simplest way to find the cause is to run it in the debugger. Make the module the primary project, and then in debugger settings set the application that uses the module as the startup executable. You will find the cause in seconds.
or create another project with a module, check that this is working and then start adding methods from the first project module to the second
What kind of private variables do you have?  Do they require initialization (constructor)?

Bob
regular string,int
YEs i have 3 that need an initialization
I imagine that this is a run-time exception.  Do you have the complete stack trace?

Bob
Yes its a runtime exception

no i dont have the stack trace
What happens if you Clean Solution?

Bob
Did this application start out as 2003 project?

Bob
the clean succeds and still the same error
Did this application start out as 2003 project?
No
Is this a 32-bit or 64-bit platform?

Bob
32 bit
2005 SP1 or base version?

Bob
Version 8.0.50727.762 (SP.050727-7600)


Microsoft Visual Studio 2005 Premier Partner Edition - ENU Service Pack 1 (KB926601)  
This service pack is for Microsoft Visual Studio 2005 Premier Partner Edition - ENU.
If you later install a more recent service pack, this service pack will be uninstalled automatically.
For more information, visit http://support.microsoft.com/kb/926601

Whew!!!  Everything is looking good, so I still don't see any reason for that exception.  It is usually when you have a class with a static member, and a module is basically a class with nothing but static members.  

What happens if you take that module, and put it into a temporary project by itself?  Would that be possible?

Bob
well i can do a sub main()

Ill let you know in a few
Yep same error
Ok so i did some playing around and this is what i have

If its am object that needs initiliazation it must be public. If its private then you cant dim as new object.

does this make sense?
Yep, that makes sense in some weird way, which is why I NEVER use modules.

Bob
So you can never have a property with an initializable object?
No, I do that in a class, but I NEVER have VB.NET applications with modules.  They don't translate well when working with C#, so I just stick to classes.

Bob
so i found the answer.

Everybody: How should I split the points?
What was the answer?

Bob
"So you can never have a property with an initializable object?"
Its the fact that i had a Private object that needs initialization
I think you answered your own question.  For me--0 points.

Bob
Its actually more than that.

I had 5 objects

4 of them were dependant on ones Successful connection. So i had to initialize them after the success of the first object.

Thank You all For your guidance :)