projectja
asked on
Garbagecollect funciton error with excel
Hi,
I am preparing a script to work with excel sheet. The thing is when I try to use Garbagecollect I get an error.
This is the error message:
Exception calling "ReleaseComObject" with "1" argument(s): "Object reference not set to an instance of an object."
At E:\Preparacion\scripts\CAS INO-CGM-pr uebas.ps1: 522 char:64
+ ([System.Runtime.Interopse rvices.Mar shal]::Rel easeComObj ect <<<< ([System.__ComObject]$ref) -gt 0)
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
An extact of the script code:
you can see the code below. Line 522 is:
... ReleaseComObject([System._ _ComObject ]$ref) -gt 0)..
-------------------------- ---------- ---------- ---------- ---------- ---
Function GarbageCollect ([object]$ref){
([System.Runtime.Interopse rvices.Mar shal]::Rel easeComObj ect([Syste m.__ComObj ect]$ref) -gt 0)
[System.GC]::Collect()
[System.GC]::WaitForPendin gFinalizer s()
}
$a = GarbageCollect($c)
$a = GarbageCollect($Wb)
$a = GarbageCollect($xl)
-------------------------- ---------- ---------- ---------- ---------- --
Please, I would thank your help. I am absolutelly lost with this issue. I have used that function before, however, I dont sure what is happening in this case
I am preparing a script to work with excel sheet. The thing is when I try to use Garbagecollect I get an error.
This is the error message:
Exception calling "ReleaseComObject" with "1" argument(s): "Object reference not set to an instance of an object."
At E:\Preparacion\scripts\CAS
+ ([System.Runtime.Interopse
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
An extact of the script code:
you can see the code below. Line 522 is:
... ReleaseComObject([System._
--------------------------
Function GarbageCollect ([object]$ref){
([System.Runtime.Interopse
[System.GC]::Collect()
[System.GC]::WaitForPendin
}
$a = GarbageCollect($c)
$a = GarbageCollect($Wb)
$a = GarbageCollect($xl)
--------------------------
Please, I would thank your help. I am absolutelly lost with this issue. I have used that function before, however, I dont sure what is happening in this case
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
did i solve your problem or not?