Disk FreeSpace problem.


D

Dan

I've written a short function to return the amount of free
disk space on a specified drive (for example c:) and it
works fine on my development platform. In production,
however, I am getting an exception that I can't figure
out. Any help would be appreciated.

Here's my code:

Public Function GetFreeSpace(ByVal strDiskDrive As String)
As Int64
Try
Dim disk As New ManagementObject
("win32_logicaldisk.deviceid=""" + strDiskDrive + """")
Return CLng(disk("FreeSpace").ToString)
Catch ex As Exception
Throw New Exception("Error In
GeneralRoutines.IO.GetFreeSpace: " + ex.ToString)
End Try
End Function

Here's the exception I'm getting on my production system:

Error In GeneralRoutines.IO.GetFreeSpace:
System.TypeInitializationException: The type initializer
for "System.Management.MTAHelper" threw an exception. --->
System.Runtime.InteropServices.COMException (0x80131701):
Unknown Error
at System.Management.MTAHelper..cctor()
--- End of inner exception stack trace ---
at System.Management.MTAHelper.CreateInMTA(Type type)
at System.Management.ManagementPath.CreateWbemPath
(String path)
at System.Management.ManagementPath..ctor(String path)
at System.Management.ManagementObject..ctor(String path)
at EnrollLink.GeneralRoutines.IO.GetFreeSpace(String
strDiskDrive)
at EnrollLink.GeneralRoutines.IO.GetFreeSpace(String
strDiskDrive)
at ELBatchService.Control.BatchControl(Boolean&
boolForceFilePurge, Boolean& boolForceRules)

-dan-
 
Ad

Advertisements

H

Herfried K. Wagner [MVP]

* "Dan said:
I've written a short function to return the amount of free
disk space on a specified drive (for example c:) and it
works fine on my development platform. In production,
however, I am getting an exception that I can't figure [...]
Error In GeneralRoutines.IO.GetFreeSpace:
System.TypeInitializationException: The type initializer
for "System.Management.MTAHelper" threw an exception. --->
System.Runtime.InteropServices.COMException (0x80131701):

Which Windows version do you use?
 
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