R# 4.0 729 Possible Null incorrectly marked

I have the following code:

01 | System.Configuration.Configuration config =
02 | HttpContext.Current == null
03 | ? ConfigurationManager.OpenExeConfiguration(
04 | ConfigurationUserLevel.None )
05 | : WebConfigurationManager.OpenWebConfiguration
06 | (HttpContext.Current.Request.ApplicationPath );

R# is marking HttpContext.Current on line 06 as possible NullReference, which is incorrect.

David

3 comments
Comment actions Permalink

Hi,

I'm getting the same thing with:

protected override void InitializeCulture()
{
if (HttpContext.Current != null && HttpContext.Current.Profile !=
null)
{
var profile = HttpContext.Current.Profile as ProfileCommon;
string language = "pt-BR";
var ci = new CultureInfo(language);
Thread.CurrentThread.CurrentCulture = ci;
Thread.CurrentThread.CurrentUICulture = ci;
}
base.InitializeCulture();
}

Possible NullReferenceException is being flagged for all the references to
HttpContext.Current except for the very first one.

Thanks
Jeremy


"David Williams" <no_replay@jetbrains.com> wrote in message
news:33371041.1203434178585.JavaMail.itn@is.intellij.net...
>I have the following code:
>

01 | System.Configuration.Configuration config =
02 | HttpContext.Current == null
03 | ? ConfigurationManager.OpenExeConfiguration(
04 | ConfigurationUserLevel.None )
05 | : WebConfigurationManager.OpenWebConfiguration
06 | (HttpContext.Current.Request.ApplicationPath );

>

R

  1. is marking HttpContext.Current on line 06 as possible NullReference,

which is incorrect.

>

David


0
Comment actions Permalink

Hello Jeremy,

It is known issue with value analysis regarding fields and properties. We
are going to fix this soon, for now just ignore those.
If you want you can clean folder ExternalAnnotations in the ReSharper installation
folder and restart VS.

Sincerely,
Ilya Ryzhenkov

JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"


IR> Hi,
IR>
IR> I'm getting the same thing with:
IR>
IR> protected override void InitializeCulture()
IR> {
IR> if (HttpContext.Current != null &&
IR> HttpContext.Current.Profile !=
IR> null)
IR> {
IR> var profile = HttpContext.Current.Profile as
IR> ProfileCommon;
IR> string language = "pt-BR";
IR> var ci = new CultureInfo(language);
IR> Thread.CurrentThread.CurrentCulture = ci;
IR> Thread.CurrentThread.CurrentUICulture = ci;
IR> }
IR> base.InitializeCulture();
IR> }
IR> Possible NullReferenceException is being flagged for all the
IR> references to HttpContext.Current except for the very first one.
IR>
IR> Thanks
IR> Jeremy
IR> "David Williams" <no_replay@jetbrains.com> wrote in message
IR> news:33371041.1203434178585.JavaMail.itn@is.intellij.net...
IR>
>> I have the following code:
>>
>> 01 | System.Configuration.Configuration config =
>> 02 | HttpContext.Current == null
>> 03 | ? ConfigurationManager.OpenExeConfiguration(
>> 04 | ConfigurationUserLevel.None )
>> 05 | : WebConfigurationManager.OpenWebConfiguration
>> 06 | (HttpContext.Current.Request.ApplicationPath );
>> R# is marking HttpContext.Current on line 06 as possible
>> NullReference, which is incorrect.
>>
>> David
>>


0
Comment actions Permalink

Hi Ilya,

Sorry - do you mean delete the contents of ExternalAnnotations?

I'm just changing over from VB to C# and so am very new to R# (and C#). I'm
finding R# absolutely invaluable, and find it hard to believe that its EAP
code.

I'll be purchasing the full version in the next few days.

Regards
Jeremy



"Ilya Ryzhenkov" <orangy@jetbrains.com> wrote in message
news:76a2bd0b1513da8ca45ff0489e85f@news.intellij.net...

Hello Jeremy,

>

It is known issue with value analysis regarding fields and properties. We
are going to fix this soon, for now just ignore those.
If you want you can clean folder ExternalAnnotations in the ReSharper
installation folder and restart VS.

>

Sincerely,
Ilya Ryzhenkov

>

JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"

>
>

IR> Hi,
IR> IR> I'm getting the same thing with:
IR> IR> protected override void InitializeCulture()
IR> {
IR> if (HttpContext.Current != null &&
IR> HttpContext.Current.Profile !=
IR> null)
IR> {
IR> var profile = HttpContext.Current.Profile as
IR> ProfileCommon;
IR> string language = "pt-BR";
IR> var ci = new CultureInfo(language);
IR> Thread.CurrentThread.CurrentCulture = ci;
IR> Thread.CurrentThread.CurrentUICulture = ci;
IR> }
IR> base.InitializeCulture();
IR> }
IR> Possible NullReferenceException is being flagged for all the
IR> references to HttpContext.Current except for the very first one.
IR> IR> Thanks
IR> Jeremy
IR> "David Williams" <no_replay@jetbrains.com> wrote in message
IR> news:33371041.1203434178585.JavaMail.itn@is.intellij.net...
IR>

>>> I have the following code:
>>>
>>> 01 | System.Configuration.Configuration config =
>>> 02 | HttpContext.Current == null
>>> 03 | ? ConfigurationManager.OpenExeConfiguration(
>>> 04 | ConfigurationUserLevel.None )
>>> 05 | : WebConfigurationManager.OpenWebConfiguration
>>> 06 | (HttpContext.Current.Request.ApplicationPath );
>>> R# is marking HttpContext.Current on line 06 as possible
>>> NullReference, which is incorrect.
>>>
>>> David
>>>
>


0

Please sign in to leave a comment.