Unable to cast object of type 'System.Byte[]' to type 'System.IConvertible'.

Post here for help with installing or upgrading mojoPortal pre-compiled release packages. When posting in this forum, please provide all relevant details. You may also want to review the installation or upgrading documentation.

If you have questions about using the source code or working with mojoPortal in Visual Studio, please post in the Developer forum.

Post here for help with installation of mojoPortal pre-compiled release packages

When posting in this forum, please try to provide as many relevant details as possible. Particularly the following:

  • What operating system were you running when the bug appeared?
  • What database platform is your site using?
  • What version of mojoPortal are you running?
  • What version of .NET do you use?
  • What steps are necessary to reproduce the issue? Compare expected results vs actual results.

You may also want to review the installation or upgrading documentation.

If you have questions about using the source code or working with mojoPortal in Visual Studio, please post in the Developer forum.

This thread is closed to new posts. You must sign in to post in the forums.
4/20/2006 7:42:15 PM
Gravatar
Total Posts 6

Unable to cast object of type 'System.Byte[]' to type 'System.IConvertible'.

Hi there,

I'm trying to install the latest version of mojoPortal (2.0.1) with MySql at my Web hotel. (They are running ASP.NET 2.0 and MySql 4.1.14.)

Here is what I did:

1. Copied all of the release files to the root of my web site.
2. Copied the three dll's from the MySql Data Layer into bin.
3. Ran the 2CreateTables.sql script in the database created by the Web hotel.
4. Adjusted the connection string in Web.config and set customErrors to mode Off.

Whenever I access my site now, I get the following exception back:

Unable to cast object of type 'System.Byte[]' to type 'System.IConvertible'.

with the stack trace shown below:


[InvalidCastException: Unable to cast object of type 'System.Byte[]' to type 'System.IConvertible'.]
   System.Convert.ToInt64(Object value) +15
   MySql.Data.MySqlClient.NativeDriver.Configure(MySqlConnection connection) +49
   MySql.Data.MySqlClient.MySqlConnection.Open() +218
   MySql.Data.MySqlClient.MySqlHelper.ExecuteReader(String connectionString, String commandText, MySqlParameter[] commandParameters) +51
   mojoPortal.Data.dbPortal.FriendlyUrl_GetByUrl(String HostName, String FriendlyUrl) +237
   mojoPortal.Business.FriendlyUrl.GetFriendlyUrl(String hostName, String friendlyUrl) +15
   mojoPortal.Business.FriendlyUrl..ctor(String hostName, String friendlyUrl) +9
   mojoPortal.Web.SiteUtils.RewriteUrl(HttpApplication app) +174
   mojoPortal.Web.UrlRewriter.UrlRewriter_BeginRequest(Object sender, EventArgs e) +130
   System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +92
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +64

 
Does anyone have any idea what could be wrong and how I could fix it?

Regards,
Jens Christian Mikkelsen

4/21/2006 1:44:31 AM
Gravatar
Total Posts 18439

Re: Unable to cast object of type 'System.Byte[]' to type 'System.IConvertible'.

Hi Jens,

There are 2 possibilities that I can think of.

1 possibility is if there is any incompatibility between the particular version of MySQL Connector and MySQL. One good thing to know would be whether your host has the connector installed in the GAC, if so it will ignore the one in the bin and use the one in the GAC

the other possibility is if something went wrong and some other error happened when the app first started it may have prevented the initial site data from being created.

Did you get any other errors before that? Is there any data in the mp_Sites and mp_Pages tables? If not try modifying the web.config by entering a space in there and then save it and try your site.  modifying the web.config will recycle the app and cause Application_OnStart to fire which is where it would try and create the data if it finds no rows in mp_Sites

Joe
4/21/2006 8:27:07 PM
Gravatar
Total Posts 6

Re: Unable to cast object of type 'System.Byte[]' to type 'System.IConvertible'.

Hi Joe,

Both mp_Sites and mp_Pages are empty, so I don't think the initial data has been created. Touching the web.config file has no effect, so this IS the initial error message.

Regarding the GAC, I will have to ask the Web hotel provider. (Unless someone knows an easy way to find out via code?)

   /Jens

4/21/2006 8:41:02 PM
Gravatar
Total Posts 6

Re: Unable to cast object of type 'System.Byte[]' to type 'System.IConvertible'.

I tried remvoing the MySQL.Data.dll assembly from the bin folder, and then I get an exception like this instead:

Could not load file or assembly 'MySQL.Data, Version=1.0.4.20892, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.

So my guess is that it doesn't have MySQL.Data.dll in the GAC.

  /Jens

4/22/2006 1:36:25 AM
Gravatar
Total Posts 18439

Re: Unable to cast object of type 'System.Byte[]' to type 'System.IConvertible'.

Hi Jens,

If you have a way to invoke this code:

mojoSetup.CreateInitialData();

it will create the data.

It is designed to invoke that in Application_OnStart if no rows exist in mp_Sites
modifying the web.config should cause the application to restart and therefore invoke Application_OnStart so I'm not sure why that is not working for you

The error is happening in Begin_Request which would fire after Application_OnStart. It almost seems as if there are rows in mp_SiteHosts. If there are rows in mp_SiteHosts and no rows in mp_Sites, try deleting the rows from mp_SiteHosts

Hope it helps,

Joe
4/22/2006 1:52:44 AM
Gravatar
Total Posts 6

Re: Unable to cast object of type 'System.Byte[]' to type 'System.IConvertible'.

Thanks for your help, Joe.

After having looked at the source code for MySql.Data.dll, I found out that the exception occurs when reading the MySQL server property "max_allowed_packet" and converting it to an Int64. If I execute SHOW VARIABLES I get an output like the following excerpt:

Variable_name              Value 
max_allowed_packet     [BLOB - 9 Bytes]
max_binlog_cache_size  [BLOB - 10 Bytes]
max_binlog_size           [BLOB - 10 Bytes]
max_connect_errors     [BLOB - 4 Bytes]
max_connections         [BLOB - 4 Bytes]
max_delayed_threads    [BLOB - 2 Bytes]

So there is probably nothing at all wrong with mojoPortal. :-) Instead the problem is related to the MySQL database setup.

Again, many thanks for your helpful hints!

 /Jens

4/22/2006 11:14:23 AM
Gravatar
Total Posts 6

Re: Unable to cast object of type 'System.Byte[]' to type 'System.IConvertible'.

Hi again,

I did some further experimenting and was able to reproduce the problem locally in a small Windows test application on my own machine by using version 1.0.4 of MySql.Data.dll. By upgrading to the latest version (1.0.7) the problem disappeared.

Unfortunately, mojoPortal will only work with version 1.0.4 in the bin folder. The easiest (for me) would probably be if the future release versions of the MySQL data layer would include 1.0.7. :-)

In the meantime, I will experiment a little with binding redirection in the web.config file and/or re-compiling the data layer.

  /Jens

 

4/22/2006 11:47:22 AM
Gravatar
Total Posts 18439

Re: Unable to cast object of type 'System.Byte[]' to type 'System.IConvertible'.

Hi Jens,

I would have thought that a version in the GAC would be used rather than the one in the bin.
What if you just put a copy of the 1.0.7 dll in the bin folder?

I will try and update to the newer connector for the next release. I just have to make sure it works on mono. I think it will but there were several versions of the connector newer than what I've been using that were broken on mono so I've held off on updating but I think they have probably resolved those things by now.

Cheers,

Joe
4/22/2006 12:03:21 PM
Gravatar
Total Posts 6

Re: Unable to cast object of type 'System.Byte[]' to type 'System.IConvertible'.

There is/was nothing in the GAC. Putting a version 1.0.7 dll in the bin folder gave an exception like this:

Could not load file or assembly 'MySQL.Data, Version=1.0.4.20892, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

But I was able to get things to work by re-compiling the MySQL.Data.dll from the mojoPortal source and changing line 139 of Driver.cs from:

    serverProps[ reader.GetValue(0) ] = reader.GetValue(1);

to:

    serverProps[ reader.GetValue(0) ] = reader.GetString(1);

as this was the important change from version 1.0.4 to 1.0.7.

  /Jens

4/22/2006 12:23:56 PM
Gravatar
Total Posts 18439

Re: Unable to cast object of type 'System.Byte[]' to type 'System.IConvertible'.

Cool, I'll try to commit that same change to svn so it will be fixed in the next version even if I don't update the connector.

I guess it only affects particular versions and configuration of MySQL since I haven't seen this error before.
You must sign in to post in the forums. This thread is closed to new posts.