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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:09:18+00:00 2026-05-25T22:09:18+00:00

I just started using ReSharper and I’m trying to identify why it thinks this

  • 0

I just started using ReSharper and I’m trying to identify why it thinks this code is wrong.

var file = new FileInfo("foobar");
return file.Directory.FullName;

It highlights file.Directory as a “Possible System.NullReferenceException”. I’m not sure how this is possible because the file object can never be null and I can’t figure out how the DirectoryInfo object returned from the FileInfo object could ever be null.

  • 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-25T22:09:19+00:00Added an answer on May 25, 2026 at 10:09 pm

    The Directory property can indeed be null. The implementation of the property is roughly

    public DirectoryInfo Directory {
        get {
            string directoryName = this.DirectoryName;
            if (directoryName == null) {
                return null;
            }
            return new DirectoryInfo(directoryName);
        }
    }
    

    It can definitely return null. Here is a concrete example

    var x = new FileInfo(@"c:\");
    if (x.Directory == null) {
      Console.WriteLine("Directory is null");  // Will print
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just started using resharper and it barks at this generated assemblyinfo.cs file. Reason/Logic
I just started using resharper and I am trying to learn all the hotkeys
I just started using VS2008 and ReSharper. I have a line: Microsoft.Office.Server.Diagnostics.PortalLog.LogString(*** BOO Feature
I just started using Eclipse so go easy on me ;). But when trying
I just started using XStream Annotations, and I am trying to figure out how
I've just started using ReSharper with Visual Studio (after the many recommendations on SO).
Just started using log4net and trying to get my head around the config and
I just started using Resharper. One of its features is that it suggests changes
I'm just getting started using Resharper with VS-2008, and one of the 'errors' it
just started using JPA today, so i'm preety new to it. How would one

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.