Mikal613
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.
The type initializer for 'MyProject.modCons' threw an exception.
I eben tried a simple helloworld method and still i get the same error.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Ive seen that before. But i would like to know why I am getting the error.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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
Bob
ASKER
Visual Studio 2005
Framework 2.0
Framework 2.0
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
Bob
ASKER
regular string,int
ASKER
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
Bob
ASKER
Yes its a runtime exception
no i dont have the stack trace
no i dont have the stack trace
What happens if you Clean Solution?
Bob
Bob
Did this application start out as 2003 project?
Bob
Bob
ASKER
the clean succeds and still the same error
ASKER
Did this application start out as 2003 project?
No
No
Is this a 32-bit or 64-bit platform?
Bob
Bob
ASKER
32 bit
2005 SP1 or base version?
Bob
Bob
ASKER
Version 8.0.50727.762 (SP.050727-7600)
ASKER
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
What happens if you take that module, and put it into a temporary project by itself? Would that be possible?
Bob
ASKER
well i can do a sub main()
Ill let you know in a few
Ill let you know in a few
ASKER
Yep same error
ASKER
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?
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
Bob
ASKER
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
Bob
ASKER
so i found the answer.
Everybody: How should I split the points?
Everybody: How should I split the points?
What was the answer?
Bob
Bob
ASKER
"So you can never have a property with an initializable object?"
ASKER
Its the fact that i had a Private object that needs initialization
I think you answered your own question. For me--0 points.
Bob
Bob
ASKER
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 :)
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 :)
ASKER