question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unexpected Reverse Engineering for Bit Field

See original GitHub issue

Describe what is not working as expected.

Given the SQL Server table

USE [CuratedPhase1]

SET ANSI_NULLS ON

SET QUOTED_IDENTIFIER ON

CREATE TABLE [dbo].[FanProductPerformanceCorrections](
	[FanProductId] [uniqueidentifier] NOT NULL,
	[FanPerformanceCorrectionId] [uniqueidentifier] NOT NULL,
	[CorrectionOrder] [smallint] NOT NULL,
	[MustHave] [bit] NOT NULL,
	[ApplyCorrection] [bit] NOT NULL,
 CONSTRAINT [PK_FanProductPerformanceCorrections] PRIMARY KEY CLUSTERED 
(
	[FanProductId] ASC,
	[FanPerformanceCorrectionId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)
)


GO

Expect the following reverse engineering result

    public partial class FanProductPerformanceCorrection
    {
        public FanProductPerformanceCorrection()
        {
            FanProductPerformanceCorrectionVariables = new HashSet<FanProductPerformanceCorrectionVariable>();
        }

        public Guid FanProductId { get; set; }
        public Guid FanPerformanceCorrectionId { get; set; }
        public short CorrectionOrder { get; set; }
        public bool MustHave { get; set; }
        public bool ApplyCorrection { get; set; }

        public virtual FanPerformanceCorrection FanPerformanceCorrection { get; set; }
        public virtual FanProduct FanProduct { get; set; }
        public virtual ICollection<FanProductPerformanceCorrectionVariable> FanProductPerformanceCorrectionVariables { get; set; }
    }

but getting

 public partial class FanProductPerformanceCorrection
    {
        public FanProductPerformanceCorrection()
        {
            FanProductPerformanceCorrectionVariables = new HashSet<FanProductPerformanceCorrectionVariable>();
        }

        public Guid FanProductId { get; set; }
        public Guid FanPerformanceCorrectionId { get; set; }
        public short CorrectionOrder { get; set; }
        public bool MustHave { get; set; }
        public bool? ApplyCorrection { get; set; }

        public virtual FanPerformanceCorrection FanPerformanceCorrection { get; set; }
        public virtual FanProduct FanProduct { get; set; }
        public virtual ICollection<FanProductPerformanceCorrectionVariable> FanProductPerformanceCorrectionVariables { get; set; }
    }

Note that APPLYCORRECTION in the second C# example is marked as nullable (bool?).

This behavior has been present for at least the last six months, and is not specific to recent builds. (we’ve been fixing it by hand)

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:11 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
bricelamcommented, Aug 12, 2019

This is expected. EF Core uses the CLR default value to determine if it should use the SQL default. If it wasn’t nullable you could never save false:

With a bool property:

.NET SQL
false 1 (via DEFAULT)
true 1

With a bool? property:

.NET SQL
null 1 (via DEFAULT)
false 0
true 1
0reactions
jostapotcfcommented, Apr 3, 2021

A new advanced option is now available to work around this issue.

Hey Erik. Thanks for this!

We’re going to be making a refactoring pass on our database here in the next few weeks (major version increment). I’ve added a devops note to check this. If it’s helpful, I’ll respond here with confirmation.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Reverse Engineering: Binary Security
Any reverse engineer could pop open IDA pro, disassemble the program, spectate and understand how the program works through static and dynamic ...
Read more >
Protecting executable from reverse engineering?
And do consider that by far the best way to avoid people reverse-engineering your code is to make it useless so that they...
Read more >
Reverse-engineering IR check bits/CRC
Reverse-engineering IR check bits/CRC · 32 bit packet spanning multiple individual values/commands of varying length (plus 1 start bit/preamble, ...
Read more >
Is there a way to name a flag for a bit field in Ghidra?
select SCALAR in decompiler window right click ->Set Equate ("E" short cut) type or select if available. a sample EQUATE as below
Read more >
F(PGA) Tour : Evading reverse engineering
When reverse engineering an FPGA bitfile, the engineer must reverse engineer the entire bitfile. Each bit describes part of a circuit. Every bit...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found