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 3597274
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T20:05:49+00:00 2026-05-18T20:05:49+00:00

C#, Linq2Sql, .NET 2.0, SQL 2005 Express When I run the following code I

  • 0

C#, Linq2Sql, .NET 2.0, SQL 2005 Express

When I run the following code I get a
InvalidCastException unable to cast of type System.Byte[] to System.String

This does not occur on all rows in the table i.e. this code runs fine soemtimes.

I checked there are no columns in the table that linq declares as SYstem.Byte[]

The stack trace says the exception occurs on the linq statement and when I F11
into the code the GetProject is never called the exception occurs before this method
is called.

So I think it is Linq framework bug.

This has got me stumped? any ideas?

[code]

    public Project GetProject(int id)
    {
        var project = (from row in _dbctx.Projects
                       where row.ProjectID == id
                       select row).SingleOrDefault();

        Project proj = GetProject(project);

        return proj;
    }

    private Project GetProject(TBRServices.Domain.TBR.DataContext.Project sqlproject)
    {
        Project project = new Project();

        project.ProjectID = sqlproject.ProjectID;
        project.ProjectName = sqlproject.ProjectName;
        project.ProjectDescription = sqlproject.ProjectDescription;
        project.ClientID = sqlproject.ClientID;
        project.PurchaseOrderNumber = sqlproject.PurchaseOrderNumber;
        project.ProjectTotalBillingEstimate = sqlproject.ProjectTotalBillingEstimate;
        project.EmployeeID = sqlproject.EmployeeID;
        project.ProjectBeginDate = sqlproject.ProjectBeginDate.ToString();
        project.ProjectEndDate = sqlproject.ProjectEndDate.ToString();
        project.Active = sqlproject.Active;
        project.InclGST = sqlproject.InclGST;
        project.ContractRate = sqlproject.ContractRate;
        project.MarginRate = sqlproject.MarginRate;
        project.Notes = sqlproject.Notes;
        project.PayrollTax = sqlproject.PayrollTax;
        project.EmployeeReference = sqlproject.EmployeeReference;
        project.PayReference = sqlproject.PayReference;
        project.ProjectLocation = sqlproject.ProjectLocation;
        project.ContractTypeID = sqlproject.ContractTypeID;
        project.DoNotCalcMarginOrGST = sqlproject.DoNotCalcMarginOrGST;
        project.ConvertToInvoice = sqlproject.ConvertToInvoice;
        project.AuthFirstname = sqlproject.AuthFirstname;
        project.AuthLastname = sqlproject.AuthLastname;
        project.AuthEmail = sqlproject.AuthEmail;
        project.CapturedDocumentType = sqlproject.CapturedDocumentType;
        project.TimesheetProcessingType = sqlproject.TimesheetProcessingType;
        project.TimesheetFrequency = sqlproject.TimesheetFrequency;
        project.AggregateTimesheet = sqlproject.AggregateTimesheet;
        project.AggregateAutomatically = sqlproject.AggregateAutomatically;
        project.BusProcEmpCut = sqlproject.BusProcEmpCut;
        project.BusProcAgencyCut = sqlproject.BusProcAgencyCut;
        project.SendCopyTimesheet = sqlproject.SendCopyTimesheet;
        project.TimesheetRecipient1 = sqlproject.TimesheetRecipient1;
        project.TimesheetRecipient2 = sqlproject.TimesheetRecipient2;
        project.SendCopyInvoice = sqlproject.SendCopyInvoice;
        project.PublishedOn = sqlproject.PublishedOn.ToString();
        project.SendAggTimesheetsWhenReceived = sqlproject.SendAggTimesheetsWhenReceived;
        project.AuthoriseInvoice = sqlproject.AuthoriseInvoice;
        project.HourlyDailyMthly = sqlproject.HourlyDailyMthly;
        project.EmployeeCategory = sqlproject.EmployeeCategory;
        project.AgencyRate = sqlproject.AgencyRate;
        project.ConsultantID = sqlproject.ConsultantID;
        project.SendCopyInvoiceEmployee = sqlproject.SendCopyInvoiceEmployee;
        project.UseClientDetailsForTimesheet = sqlproject.UseClientDetailsForTimesheet;
        project.FaxedTimesheet = sqlproject.FaxedTimesheet;
        project.TimesheetEditable = sqlproject.TimesheetEditable;
        project.IncludeInReport = sqlproject.IncludeInReport;
        project.SendLogonEmail = sqlproject.SendLogonEmail;
        project.NoticePeriodID = sqlproject.NoticePeriodID;
        project.ManagerCanViewPaidUnpaid = sqlproject.ManagerCanViewPaidUnpaid;
        project.LesterSalesStaff = sqlproject.LesterSalesStaff;
        project.IncludeSalesReport = sqlproject.IncludeSalesReport;
        project.CurrencyAccount = sqlproject.CurrencyAccount;
        project.LeaveMustBeAuthorisedTimesheet = sqlproject.LeaveMustBeAuthorisedTimesheet;
        project.LeaveMustBeAuthorisedLeaveForm = sqlproject.LeaveMustBeAuthorisedLeaveForm;
        project.DefaultHoursWorkedWeek = sqlproject.DefaultHoursWorkedWeek;
        project.DefaultHoursWorkedDay = sqlproject.DefaultHoursWorkedDay;
        project.AccruedLeaveStartDate = sqlproject.AccruedLeaveStartDate.ToString();
        project.AllowLeaveMoreThanAccrued = sqlproject.AllowLeaveMoreThanAccrued;
        project.IsPaidASalary = sqlproject.IsPaidASalary;
        project.AgencyID = sqlproject.AgencyID;
        project.SendEmailToManagerToOKLeave = sqlproject.SendEmailToManagerToOKLeave;
        project.SpecialPayrollNotes = sqlproject.SpecialPayrollNotes;
        project.SpecialInvoicingNotes = sqlproject.SpecialInvoicingNotes;
        project.InvoiceTermsMessage = sqlproject.InvoiceTermsMessage;
        project.AuthManagerPhone = sqlproject.AuthManagerPhone;
        project.LMF = sqlproject.LMF;
        project.LMFPercent = sqlproject.LMFPercent;
        project.LMFInclInPayRate = sqlproject.LMFInclInPayRate;
        project.LMFOnTop = sqlproject.LMFOnTop;
        project.AgencyComm = sqlproject.AgencyComm;
        project.AgencyCommPercent = sqlproject.AgencyCommPercent;
        project.AgencyCommInclInPayRate = sqlproject.AgencyCommInclInPayRate;
        project.AgencyCommOnTop = sqlproject.AgencyCommOnTop;
        project.PayRateInclMargin = sqlproject.PayRateInclMargin;
        project.MarginRatePercent = sqlproject.MarginRatePercent;
        project.MarginRateGST = sqlproject.MarginRateGST;
        project.MarginRateInclInPayRate = sqlproject.MarginRateInclInPayRate;
        project.MarginRateOnTop = sqlproject.MarginRateOnTop;
        project.PayRateInclSuper = sqlproject.PayRateInclSuper;
        project.PayrollTaxAmount = sqlproject.PayrollTaxAmount;
        project.PayrollTaxPercent = sqlproject.PayrollTaxPercent;
        project.PayrollTaxInclInPayRate = sqlproject.PayrollTaxInclInPayRate;
        project.PayrollTaxOnTop = sqlproject.PayrollTaxOnTop;
        project.TypeOfArrangement = sqlproject.TypeOfArrangement;
        project.ParameterRequired = sqlproject.ParameterRequired;
        project.SpecialPayrollEnabled = sqlproject.SpecialPayrollEnabled;
        project.ClientContactUsedReceiptOfInvoiceID = sqlproject.ClientContactUsedReceiptOfInvoiceID;
        project.ExcludeEmpNameOnInvoice = sqlproject.ExcludeEmpNameOnInvoice;
        project.BPForReporting = sqlproject.BPForReporting;
        project.UseGemteqInvoiceFormat = sqlproject.UseGemteqInvoiceFormat;
        project.TreatPayrollDetailsSameAsBP = sqlproject.TreatPayrollDetailsSameAsBP;


        return project;
    }

[/code]

  • 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-05-18T20:05:50+00:00Added an answer on May 18, 2026 at 8:05 pm

    Check the answer to a similar SO question. It will not be the exact answer but may help you find the problem in your query –

    Problem with Linq to SQL

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

Sidebar

Related Questions

C#, Linq2Sql, .NET 2.0, SQL 2005 Express When I run the following code I
I'm using linq2sql and .net 3.5 with vs2010. I'm experiencing bad sql performance when
I'm using C# , .NET and SQL Server with Linq2SQL. What does this error
I have some legacy code with linq2sql classes. DataContext class has following definition for
I want to go with Linq2SQL first and get it to create sql db
Setting up ASP.net MVC with Linq2SQL or Entity Framework's context to have scaffolding work
I'm using Linq2Sql for my asp.net mvc project and so far it has worked
I'm using ASP.NET Preview 5 (will upgrade soon to Beta) with LINQ2SQL on my
Normally when you update an object in linq2sql you get the object from a
i've got the following linq2sql query, and i'm setting the result to a POCO.

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.