the instructions do not behave the same?

Andy75

Member
Joined
May 29, 2020
Messages
18
Programming Experience
1-3
Hi all,
something very strange happens to me and I don't know how to move forward.
I created a clickonce application in C#.
Development side works ok.
once installed on the machine, it seems that the instructions do not behave the same.

The instruction is this:
C#:
                var res = first
                                .Select(x => x.Code)
                                .Except(second.Select(y => y.Code))
                                .ToList();



I also tried changing Except by doing Where, but it doesn't change.
It basically checks me the difference on two lists of strings.

When I debug, it works fine (return 1).
Once installed, it doesn't make the correct diffs (return 4).
The sources are the same in both.

Mmh!
Suggestions?
thank you
A.
 
Solution
Add logging. See what first, and second contains.

If I have to guess, the data you are operating on in dev is different from what you are deploying.
Add logging. See what first, and second contains.

If I have to guess, the data you are operating on in dev is different from what you are deploying.
 
Solution
Moving out of WinForms since nothing in this question is WinForms specific.
 
By the way, to get the original objects out you can `first.ExceptBy(second.Select(s => s.Code), f => f.Code)`

Agree with skydiver; I want proof that C# is inconsistent, as I've not found it to be so in 20 years..
 
Add logging. See what first, and second contains.

If I have to guess, the data you are operating on in dev is different from what you are deploying.

You're great.
I had already understood what you were saying, but I hadn't followed through to the bottom of it and was relying on an unclear process.

You are a great help, as always!
 
When I first started writing code for a big company, and I asked about how to decide what to log and what not to log, my mentors advised: Imagine being woken up at 3AM by a call from your boss because there is a critical bug that can't wait until you get in the morning. You can't access the machine where the issue is happening, but the can send you logs. What information do you want available to you to help you narrow down the issue?
 
I have not much idea about it, can you try it by replacing your code with the below code.

C#:
var res = first
            .Select(x => x.Code)
            .Except(second.Select(y => y.Code), StringComparer.OrdinalIgnoreCase)
            .ToList();

Thanks
 
By adding that case insensitive ordinal comparer, you now change the logic of the code to be case insensitive. Not good if that is not the intent of the OP.
 

Latest posts

Back
Top Bottom