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

  • Home
  • SEARCH
  • 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 6750905
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:51:48+00:00 2026-05-26T12:51:48+00:00

When I add .ToLowerInvariant() to Path.GetExtension(file.FileName) , ReSharper gives a warning for a possible

  • 0

When I add ".ToLowerInvariant()"
to Path.GetExtension(file.FileName), ReSharper gives a warning for a possible Nullreference exception.

I have tried to following, but warning is nog going away. What am i missing?

if (file != null && Path.GetExtension(file.FileName) != null)
            {
                switch (Path.GetExtension(file.FileName).ToLowerInvariant())
                {
                    case ".jpg":
                    case ".png":
                    case ".gif":
                    case ".jpeg":
                        break;
                    default:
                        break;

                }
}
  • 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-26T12:51:49+00:00Added an answer on May 26, 2026 at 12:51 pm

    Because ToLowerInvariant() is being called on the outcome of Path.GetExtension(). There is no guarantee that Path.GetExtension() will return anything meaningful (if file.Filename is null for example).

    Best to check that the outcome of Path.GetExtension isnt null, before you call anything else on it. (or call ToLower() on file.FileName before you put it into GetExtension, either way make sure you know exactly what you’re putting into GetExtension() or you cant make any guarantees that what you get out will be what you were after).

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

Sidebar

Related Questions

To add a REG_MULTI_SZ multi-line registry value, i can do reg.exe ADD HKLM\path\to\registry\key /v
I add an image file to to UIButton image property. But my image resized
I add the following code to main.xml to set an image as a background
Add a DateTimePicker, two TextBoxes and two Buttons to a Form Add the following
Add service reference to Amazon service fails, saying Could not load file or assembly
Goal: Add a new file to a remote git repository without checking the whole
I add a UILabel using objective c, have a white rectagle around them. How
Add multiple items to text-area with duplicate items. I have one text-area which store
I add for template (index.html.twig) simply: {{ dump(product) }} and i have error: The
add_to_builtins('gravatar.gravatar') is being used in my settings.py file, and it causes a crash on

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.