Skip to content

Remove Marshal Exception/HRESULT proxies from SecurityHelper, simplify code#9977

Open
h3xds1nz wants to merge 7 commits into
dotnet:mainfrom
h3xds1nz:remove-securityhelper-exceptions
Open

Remove Marshal Exception/HRESULT proxies from SecurityHelper, simplify code#9977
h3xds1nz wants to merge 7 commits into
dotnet:mainfrom
h3xds1nz:remove-securityhelper-exceptions

Conversation

@h3xds1nz
Copy link
Copy Markdown
Member

@h3xds1nz h3xds1nz commented Oct 21, 2024

Description

Continues the work on removing CAS remnants, this time again method proxies and "helpers" from SecurityHelper.

In this PR we remove GetHRForException from StreamAsIStream along with obsolete warning suppresions and also GetExceptionForHR plus ThrowExceptionForHR proxies.

  • _lastException was just storing the latest exception in a private field that was never read.
  • Technically we could just return COR_E_OBJECTDISPOSED in some cases instead of setting up a frame, conditionally throwing ObjectDisposedException, catching it just to retrieve the HResult and then returning it but I think it is out of scope for this PR.

Customer Impact

Decreased size of assemblies, cleaner codebase for developers.

Regression

No.

Testing

Local build.

Risk

Low.

Microsoft Reviewers: Open in CodeFlow

himgoyalmicro
himgoyalmicro previously approved these changes Apr 14, 2025
@himgoyalmicro
Copy link
Copy Markdown
Contributor

@h3xds1nz this PR is good to be merged. Can you please resolve the merge conflicts?

@h3xds1nz
Copy link
Copy Markdown
Member Author

@himgoyalmicro Done :)

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 14, 2025

Codecov Report

❌ Patch coverage is 11.53846% with 23 lines in your changes missing coverage. Please review.
✅ Project coverage is 12.83462%. Comparing base (72af9a5) to head (0c13826).
⚠️ Report is 264 commits behind head on main.

Additional details and impacted files
@@                 Coverage Diff                 @@
##                main       #9977         +/-   ##
===================================================
+ Coverage   11.25778%   12.83462%   +1.57683%     
===================================================
  Files           3315        3316          +1     
  Lines         665229      665427        +198     
  Branches       74668       74667          -1     
===================================================
+ Hits           74890       85405      +10515     
+ Misses        589035      577806      -11229     
- Partials        1304        2216        +912     
Flag Coverage Δ
Debug 12.83462% <11.53846%> (+1.57683%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Runtime.InteropServices;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you sort the usings ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost none (or none?) of the files that I've touched has the usings sorted to begin with, don't think I should.

Plus then there's #10683 (comment) to tackle.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally a lot of the files I've seen were sorted, or mostly sorted. It's also pretty standard to sort usings in C#. This file was already sorted so why unsort it ?


#if PRESENTATION_CORE
using MS.Internal.AppModel;
using System.Security;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you sort the usings ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See the other comment. Also with tiny amount of luck this file won't exist in .NET 10 RTM anyways.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my other comment. This file was not fully sorted but I don't see why we should add unsorted usings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Community Contribution A label for all community Contributions Included in test pass PR metadata: Label to tag PRs, to facilitate with triage Status:Completed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants