- Home /
InvalidCastException: Cannot cast from source type to destination type.
Code:
InvalidCastException: Cannot cast from source type to destination type.
Oracle.DataAccess.Client.CThreadPool..cctor ()
Rethrow as TypeInitializationException: An exception was thrown by the type initializer for Oracle.DataAccess.Client.CThreadPool
Oracle.DataAccess.Client.OracleInit.Initialize ()
Oracle.DataAccess.Client.OracleConnectionStringBuilder..cctor ()
Rethrow as TypeInitializationException: An exception was thrown by the type initializer for Oracle.DataAccess.Client.OracleConnectionStringBuilder
Code:
Plugins/Oracle.DataAccess.dll
Code:
using Oracle.DataAccess.Client;
Code:
OracleConnectionStringBuilder dcs = new OracleConnectionStringBuilder("myConnectionString");
OracleConnection dbcon = new OracleConnection(this.dcs.ConnectionString);
dbcon.Open();
Debug.Log(dbcon.Database);
Debug.Log(dbcon.State);
Debug.Log(dbcon.ServerVersion);
Plz Help
What line is it throwing the exception on, and what does the code in that line look like?
@driverz - did you figure this out? Hitting the same problem. Tks
I think most people don't use Oracle in Unity. This is a problem purely related to a thridparty library and is only indirectly related to Unity. As you can see the exception is thrown in the static constructor of the "CThreadPool" class. The code might have been written with newer framework. For example .NET 2.0 didn't have covariance / contravariance support for generic types. This has been introduced in C# >= 4.0.
You can use ILSpy to have a look at the code of the static constructor of that class and see if you can spot the problem. However the usual solution is to find a version of that assembly which is compatible with Unity's $$anonymous$$ono version. Anything that is .NET 3.5 or lower should work fine in Unity.
This SO question (and answer) should cover most problems. So make sure you have to .NET 2.0 version of that DLL.
Your answer
Follow this Question
Related Questions
InvalidCastException: Cannot cast from source type to destination type. 3 Answers
How to connect to Oracle? 1 Answer
InvalidCastException: Cannot cast from source type to destination type. ??? 2 Answers
InvalidCastException in Javascript 2 Answers
"Cannot cast from source type to destination type"- instantiating 4 Answers