Cannot fifure out how to fix this exception.


G

Guest

I am unable to execute the following statement in my current project. The
class PosExplorer is in a dll file (created by Microsoft).

PosExplorer explorer = new PosExplorer()

but now I get this dreaded exception below. What I cannot understand, is
that, if I create another small project with a single form and execute the
line above, then it works. But it does not work in my current project.
The innerexception.Message is : "Attempt to access the method failed".

Here is the exception.

System.TypeInitializationException was unhandled
Message="The type initializer for
'Microsoft.PointOfService.Management.Explorer' threw an exception."
Source="Microsoft.PointOfService"
TypeName="Microsoft.PointOfService.Management.Explorer"
StackTrace:
at Microsoft.PointOfService.Management.Explorer.CreateExplorer()
at Microsoft.PointOfService.PosExplorer.LoadExplorer()
at Microsoft.PointOfService.PosExplorer.Initialize()
at Microsoft.PointOfService.PosExplorer..ctor()
at Retail.frmPrinterSetUp.frmPrinterSetUp_Load(Object sender,
EventArgs e) in C:\Documents and Settings\HP_Owner\My Documents\Visual Studio
2005\Projects\Retail\Retail\frmPrinterSetUp.cs:line 21
at System.Windows.Forms.Form.OnLoad(EventArgs e)
at System.Windows.Forms.Form.OnCreateControl()
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl()
at System.Windows.Forms.Control.WmShowWindow(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.ContainerControl.WndProc(Message& m)
at System.Windows.Forms.Form.WmShowWindow(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at
System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd,
Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.SafeNativeMethods.ShowWindow(HandleRef hWnd,
Int32 nCmdShow)
at System.Windows.Forms.Control.SetVisibleCore(Boolean value)
at System.Windows.Forms.Form.SetVisibleCore(Boolean value)
at System.Windows.Forms.Control.set_Visible(Boolean value)
at
System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32
reason, ApplicationContext context)
at
System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason,
ApplicationContext context)
at System.Windows.Forms.Form.ShowDialog(IWin32Window owner)
at System.Windows.Forms.Form.ShowDialog()
at Retail.frmMain.frmMain_Load(Object sender, EventArgs e) in
C:\Documents and Settings\HP_Owner\My Documents\Visual Studio
2005\Projects\Retail\Retail\frmMain.cs:line 24
at System.Windows.Forms.Form.OnLoad(EventArgs e)
at System.Windows.Forms.Form.OnCreateControl()
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl()
at System.Windows.Forms.Control.WmShowWindow(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.ContainerControl.WndProc(Message& m)
at System.Windows.Forms.Form.WmShowWindow(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at
System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd,
Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.SendMessage(HandleRef
hWnd, Int32 msg, Int32 wParam, Int32 lParam)
at System.Windows.Forms.Form.SetVisibleCore(Boolean value)
at System.Windows.Forms.Control.set_Visible(Boolean value)
at
System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32
reason, ApplicationContext context)
at
System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason,
ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at Retail.Program.Main() in C:\Documents and Settings\HP_Owner\My
Documents\Visual Studio 2005\Projects\Retail\Retail\Program.cs:line 20
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
at System.Runtime.Hosting.ManifestRunner.Run(Boolean checkAptModel)
at System.Runtime.Hosting.ManifestRunner.ExecuteAsAssembly()
at
System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext
activationContext, String[] activationCustomData)
at
System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext
activationContext)
at
Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssemblyDebugInZone()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext
executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
 
Ad

Advertisements

P

Patrick Steele

I am unable to execute the following statement in my current project. The
class PosExplorer is in a dll file (created by Microsoft).

PosExplorer explorer = new PosExplorer()

but now I get this dreaded exception below. What I cannot understand, is
that, if I create another small project with a single form and execute the
line above, then it works. But it does not work in my current project.
The innerexception.Message is : "Attempt to access the method failed".

Here is the exception.

System.TypeInitializationException was unhandled
Message="The type initializer for
'Microsoft.PointOfService.Management.Explorer' threw an exception."
Source="Microsoft.PointOfService"

Whenever you see a TypeInitializationException, you really need to look
at it's InnerException to see why the type couldn't be initialized.
 
S

sherifffruitfly

Whenever you see a TypeInitializationException, you really need to look
at it's InnerException to see why the type couldn't be initialized.

If you don't "just know" that a given exception *has* an
InnerException, do you basically just have to put an if
(ex.InnerException != null) clause in all of your exception handlers?
 
P

Patrick Steele

If you don't "just know" that a given exception *has* an
InnerException, do you basically just have to put an if
(ex.InnerException != null) clause in all of your exception handlers?

I'm not sure what you're asking. The InnerException property helps you
determine why the TypeLoadInitializationException occurred.

The base Exception class contains an InnerException property so any
exception in .NET has the potential to have an InnerException.
 
S

sherifffruitfly

I'm not sure what you're asking. The InnerException property helps you
determine why the TypeLoadInitializationException occurred.

The base Exception class contains an InnerException property so any
exception in .NET has the potential to have an InnerException.

Ah - gotcha. I had the cockamamie idea that there were some types of
exceptions that were guaranteed to have inners, and other types of
exceptions there were guaranteed NOT to have inners. If I understand
you correctly, having an inner exception (or not) isn't decided at the
type level, rather it's decided at the instance level.

So basically, if you care about them in the first place, you would
always have an inner-exception-checker in your exception handler - for
any exception you don't know the instantiation/property-setting
details of ahead of time.
 
Ad

Advertisements

S

sherifffruitfly

I'm not sure what you're asking. The InnerException property helps you
determine why the TypeLoadInitializationException occurred.

The base Exception class contains an InnerException property so any
exception in .NET has the potential to have an InnerException.

Ah - gotcha. I had the cockamamie idea that there were some types of
exceptions that were guaranteed to have inners, and other types of
exceptions there were guaranteed NOT to have inners. If I understand
you correctly, having an inner exception (or not) isn't decided at the
type level, rather it's decided at the instance level.

So basically, if you care about them in the first place, you would
always have an inner-exception-checker in your exception handler - for
any exception you don't know the instantiation/property-setting
details of ahead of time.
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top