Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8657371
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T15:30:16+00:00 2026-06-12T15:30:16+00:00

This error looks like it was caused by installing framework 4.5 on the server

  • 0

This error looks like it was caused by installing framework 4.5 on the server even though the project is still targeted to 4.0.

4.5 replaces the CLR and it looks like it has changes in unboxing an object of type tinyint to a int. This was working in 4.0 but not after installing 4.5.

============================================

Please read the whole question before answering, most current answers do not answer the question I am asking.

We today got an error in a cast from a tinyint in sql to an int using

Daterow datarow = GetOneDatarow(connection,
                         "SELECT tinyintcolumn FROM table1 WHERE id = 4");
int i = (int)datarow["tinyintcolumn"];

This is old code that has been in the product for several years without any changes and it has been working up until yesterday. (And it is not the exact code, just enough to show the context)

=== UPDATE

The exact error message was: “The specified cast is not valid!” and the last line

int i = (int)datarow["tinyintcolumn"];

is the exact row from our code casting the error with only variable names and column name changed.

And the database column was tinyint with default value 0, no indexes or other constraints.

=== End update

=== UPDATE 2

Henk Holterman in his response informed me that FW 4.5 replaces the CLR of 4.0 even for projects compiled specifically for 4.0 and this could remotely change existing 4.0 behaviour just like this.

I will keep this open a while more but his answer is the most promising so far 😀
=== End

We changed from framework 3.5 to 4.0 a few weeks ago but it was only yesterday afternoon after a recompile that this happened, yesterday morning the same code (even after recompile) worked like clockwork.

Do anyone have any idea on why this was working before and is not working now?

Has Microsoft made any under the hood changes that removed an implicit conversion or has it worked by pure magic before?

We solved it by changing the database column to int, but I am still curious on what might have caused it to fail right now.

=== UPDATE 3

Just to complete this.

I found the change between frameworks. In an update Microsoft changed how boxing and unboxing is done. This caused the implicit cast from byte to int that older FW did to fail when the byte was boxed, as it is in a datatable.

An unboxed byte will will in 4.5 be implicitly cast to an int, but a boxed byte is an generic object which cannot be implicitly cast.

Not, this was changed in 3.5 SP1 so our FW 4.0 should also have failed, unless the update to SP1 was not in the 4.0 update. This has yet to be answered 🙂

Here is the ticket from MS on this 😉
https://connect.microsoft.com/VisualStudio/feedback/details/766887/casting-tinyint-from-sql-datarow-to-int-no-longer-possible

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T15:30:18+00:00Added an answer on June 12, 2026 at 3:30 pm

    It should never have worked. Which makes it likely that something was fixed in the framework.

    The problem in C#:

    byte b = 3;       // TinyInt is a Byte
    object o = b;     // DataRow[i] is an object
    int i = (int)o;   // invalid cast
    

    The fix:

    int i = (byte)datarow["tinyintcolumn"];
    

    And from the comment trail below:

    We have installed it, but this project is not compiled towards 4.5, only to 4.0, … could that be the case?

    Yes, framework 4.5 replaces parts of 4.0.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I get this error when compiling a C# application. Looks like a trivial error,
Getting Expected ',' or '{' but found '#44559' error. My code looks like this:
Let's say that I have a method that looks like this: def raise_if_client_status_error(xml_resp) #
I have a line of php code that looks like this: echo <script>$('#edit_errors').html('<h3><em>Please Correct
This function gives me the following error: SyntaxError: Invalid character '\u8203' All looks good
on the cursor line this error occurs. Error: Caused by: android.database.sqlite.SQLiteException: near ): syntax
My view model looks like this: public class HomePageViewModel { private List<AlertViewModel> alertViewModels; public
I have a hash being posted to my Rails app that looks like this:
The JSON file looks like this: { strings: [ { key_one: value_one! }, {
I'm trying to compile Objective-C code on Ubuntu 12 Linux. main.m looks like this:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.