A first chance exception of type 'System.InvalidCastException' occurred in scs.sr.dal.dll

K

karunakar

Hi All

Here iam getting this Error "Specified cast is not valid."
My Project has Onc solution diffrent class libarary In that solution DALfactory solution iam getting this error
I was calling this function in DALFactory class library(this library generate the DAL.dll)

Another class library has this function

public SecurityInfo Login(string username, string password)
{
IUserSetting us = SCS.SR.DALFactory.UserSetting.Create(); (When i was catch the Quick watch "SCS.SR.DALFactory.UserSetting.Create()" this that time iam getting this error "System.SystemException {"Specified cast is not valid."} System.SystemException ")

SecurityInfo getIsusreValid = us.IsUserValid(username,password);
return getIsusreValid;
}


public static SCS.SR.IDAL.IUserSetting Create()
{
string path = System.Configuration.ConfigurationSettings.AppSettings["WebDAL"];
string className = path + ".UserSetting";
return (SCS.SR.IDAL.IUserSetting) Assembly.Load(path).CreateInstance(className); (Here Iam getting this error) (this is going to return the securityInfo function)

}

A first chance exception of type 'System.InvalidCastException' occurred in scs.sr.dal.dll

Additional information: Specified cast is not valid.


Regards,
Karunakara Rao.
 
D

Dmitriy Lapshin [C# / .NET MVP]

Hi,

In this line:

return (SCS.SR.IDAL.IUserSetting) Assembly.Load(path).CreateInstance(className)

Use CreateInstanceAndUnwrap instead of CreateInstance.

--
Sincerely,
Dmitriy Lapshin [C# / .NET MVP]
Bring the power of unit testing to the VS .NET IDE today!
http://www.x-unity.net/teststudio.aspx
Hi All

Here iam getting this Error "Specified cast is not valid."
My Project has Onc solution diffrent class libarary In that solution DALfactory solution iam getting this error
I was calling this function in DALFactory class library(this library generate the DAL.dll)

Another class library has this function

public SecurityInfo Login(string username, string password)
{
IUserSetting us = SCS.SR.DALFactory.UserSetting.Create(); (When i was catch the Quick watch "SCS.SR.DALFactory.UserSetting.Create()" this that time iam getting this error "System.SystemException {"Specified cast is not valid."} System.SystemException ")

SecurityInfo getIsusreValid = us.IsUserValid(username,password);
return getIsusreValid;
}


public static SCS.SR.IDAL.IUserSetting Create()
{
string path = System.Configuration.ConfigurationSettings.AppSettings["WebDAL"];
string className = path + ".UserSetting";
return (SCS.SR.IDAL.IUserSetting) Assembly.Load(path).CreateInstance(className); (Here Iam getting this error) (this is going to return the securityInfo function)

}

A first chance exception of type 'System.InvalidCastException' occurred in scs.sr.dal.dll

Additional information: Specified cast is not valid.


Regards,
Karunakara Rao.
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

CreateInstanceAndUnwrap is a member of AppDomain , not of Assembly.


I would check the className to be a correct FQN of the class in question.

replace the line for this:

object tempO = Assembly.Load(path).CreateInstance(className);

and see in the watch window what tempO is.

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
Hi,

In this line:

return (SCS.SR.IDAL.IUserSetting) Assembly.Load(path).CreateInstance(className)

Use CreateInstanceAndUnwrap instead of CreateInstance.

--
Sincerely,
Dmitriy Lapshin [C# / .NET MVP]
Bring the power of unit testing to the VS .NET IDE today!
http://www.x-unity.net/teststudio.aspx
Hi All

Here iam getting this Error "Specified cast is not valid."
My Project has Onc solution diffrent class libarary In that solution DALfactory solution iam getting this error
I was calling this function in DALFactory class library(this library generate the DAL.dll)

Another class library has this function

public SecurityInfo Login(string username, string password)
{
IUserSetting us = SCS.SR.DALFactory.UserSetting.Create(); (When i was catch the Quick watch "SCS.SR.DALFactory.UserSetting.Create()" this that time iam getting this error "System.SystemException {"Specified cast is not valid."} System.SystemException ")

SecurityInfo getIsusreValid = us.IsUserValid(username,password);
return getIsusreValid;
}


public static SCS.SR.IDAL.IUserSetting Create()
{
string path = System.Configuration.ConfigurationSettings.AppSettings["WebDAL"];
string className = path + ".UserSetting";
return (SCS.SR.IDAL.IUserSetting) Assembly.Load(path).CreateInstance(className); (Here Iam getting this error) (this is going to return the securityInfo function)

}

A first chance exception of type 'System.InvalidCastException' occurred in scs.sr.dal.dll

Additional information: Specified cast is not valid.


Regards,
Karunakara Rao.
 
D

Dmitriy Lapshin [C# / .NET MVP]

I agree - this is most likely the cause. I should have checked the Assembly's method list - shame on me!

--
Sincerely,
Dmitriy Lapshin [C# / .NET MVP]
Bring the power of unit testing to the VS .NET IDE today!
http://www.x-unity.net/teststudio.aspx
"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us> wrote in message Hi,

CreateInstanceAndUnwrap is a member of AppDomain , not of Assembly.


I would check the className to be a correct FQN of the class in question.

replace the line for this:

object tempO = Assembly.Load(path).CreateInstance(className);

and see in the watch window what tempO is.

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
Hi,

In this line:

return (SCS.SR.IDAL.IUserSetting) Assembly.Load(path).CreateInstance(className)

Use CreateInstanceAndUnwrap instead of CreateInstance.

--
Sincerely,
Dmitriy Lapshin [C# / .NET MVP]
Bring the power of unit testing to the VS .NET IDE today!
http://www.x-unity.net/teststudio.aspx
Hi All

Here iam getting this Error "Specified cast is not valid."
My Project has Onc solution diffrent class libarary In that solution DALfactory solution iam getting this error
I was calling this function in DALFactory class library(this library generate the DAL.dll)

Another class library has this function

public SecurityInfo Login(string username, string password)
{
IUserSetting us = SCS.SR.DALFactory.UserSetting.Create(); (When i was catch the Quick watch "SCS.SR.DALFactory.UserSetting.Create()" this that time iam getting this error "System.SystemException {"Specified cast is not valid."} System.SystemException ")

SecurityInfo getIsusreValid = us.IsUserValid(username,password);
return getIsusreValid;
}


public static SCS.SR.IDAL.IUserSetting Create()
{
string path = System.Configuration.ConfigurationSettings.AppSettings["WebDAL"];
string className = path + ".UserSetting";
return (SCS.SR.IDAL.IUserSetting) Assembly.Load(path).CreateInstance(className); (Here Iam getting this error) (this is going to return the securityInfo function)

}

A first chance exception of type 'System.InvalidCastException' occurred in scs.sr.dal.dll

Additional information: Specified cast is not valid.


Regards,
Karunakara Rao.
 

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