Cast is invalid on object

0

I have this problem, when I try to cast the "batch" object, I am raised exception "Invalid cast". Can you help me out with why? The vault5 object exists and is correct.

public void batch(IEdmVault5 vault5)
{
    edmVault11 = (IEdmVault11)vault5;
    IEdmBatchRefVars batch = default(IEdmBatchRefVars);
    batch = (IEdmBatchRefVars)edmVault11.CreateUtility(EdmUtility.EdmUtil_BatchRefVars);

    //some code
}

Edit 1: Error message:

System.InvalidCastException HResult=0x80004002 Messaggio=Cast specificato non valido

c#
object
c#-7.0
asked on Stack Overflow Feb 16, 2020 by koss • edited Feb 16, 2020 by Twenty

1 Answer

-1

I would suggest you try out this change , also

 public void batch(IEdmVault5 vault5)
{
    IEdmVault7 edmValult11 = null;
    if (vault5 == null)
    {
           vault5 = new EdmVault5();
    }
    edmVault11 = (IEdmVault11)vault5;
    IEdmBatchRefVars batch = default(IEdmBatchRefVars);
    batch = (IEdmBatchRefVars)edmVault11.CreateUtility(EdmUtility.EdmUtil_BatchRefVars);

    //some code
}

Besides given the nature of Solidworks API make sure that the installation and license are valid .

answered on Stack Overflow Feb 16, 2020 by goodbye_for_now • edited Feb 16, 2020 by goodbye_for_now

User contributions licensed under CC BY-SA 3.0