Possible false positive? -> [Possible 'null' assignment to an entity marked with 'Value cannot be null' attribute]

The Message pops up at line 21 at the typeof command. Since the result typeof cannot be null I thinkt it's an false positive.
Am I right or is there some "better" way to solve this.

using System;
using System.IO;
using System.Reflection;

namespace Typemock.TeamFoundation.Build.Workflow.Activities
{
     internal class TestClass
     {
          private Testclass2 InternalVersionResolver { get; set; }
          private AppDomain AppDomain { get; set; }

          public TestClass()
          {
               var executingAssemblyLocation = Assembly.GetExecutingAssembly().Location;
               var appDomainSetup = new AppDomainSetup
                                         {ApplicationBase = Path.GetDirectoryName(executingAssemblyLocation)};
               AppDomain domain = AppDomain.CreateDomain("TypemockVersionResolverAppDomain", AppDomain.CurrentDomain.Evidence, appDomainSetup);
               try
               {
                    AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
                    InternalVersionResolver = (Testclass2)domain.CreateInstanceAndUnwrap(AssemblyName.GetAssemblyName(executingAssemblyLocation).FullName, typeof(Testclass2).FullName);
               }
               finally
               {
                    AppDomain.CurrentDomain.AssemblyResolve -= CurrentDomain_AssemblyResolve;
               }
               AppDomain = domain;
          }

          Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
          {
               throw new NotImplementedException();
          }

          internal class Testclass2 : MarshalByRefObject
          {
          }
     }
}

1 comment
Comment actions Permalink

Hello Michael,

Here ReSharper complains not about the typeof(Testclass2) being null, but
rather about typeof(Testclass2).FullName. According to documentation, this
property can return null:

"The fully qualified name of the Type, including the namespace of the Type
but not the assembly; or null if the current instance represents a generic
type parameter, an array type, pointer type, or byref type based on a type
parameter, or a generic type that is not a generic type definition but contains
unresolved type parameters."

, so this is a correct warning from ReSharper.

Andrey Serebryansky
Senior Support Engineer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"

The Message pops up at line 21 at the typeof command. Since the result
typeof cannot be null I thinkt it's an false positive.

Am I right or is there some "better" way to solve this.

 using System.IO;
> using System.Reflection;
> namespace Typemock.TeamFoundation.Build.Workflow.Activities
> 
> {
> 
>      internal class TestClass
> 
>      {
> 
>           private
> Testclass2 InternalVersionResolver { get; set; }
> 
>           private
> AppDomain AppDomain { get; set; }
> 
>           public
> TestClass()
> 
>           {
> 
>            &nbs
> p;   var executingAssemblyLocation =
> Assembly.GetExecutingAssembly().Location;
> 
>            &nbs
> p;   var appDomainSetup = new AppDomainSetup
> 
>            &nbs
> p;   
>      {ApplicationBase =
> Path.GetDirectoryName(executingAssemblyLocation)};
> 
>            &nbs
> p;   AppDomain domain =
> AppDomain.CreateDomain("TypemockVersionResolverAppDomain",
> AppDomain.CurrentDomain.Evidence, appDomainSetup);
> 
>            &nbs
> p;   try
> 
>            &nbs
> p;   {
> 
>            &nbs
> p;        AppDomain.CurrentDom
> ain.AssemblyResolve += CurrentDomain_AssemblyResolve;
> 
>            &nbs
> p;        InternalVersionResol
> ver =
> (Testclass2)domain.CreateInstanceAndUnwrap(AssemblyName.GetAssemblyNam
> e(executingAssemblyLocation).FullName, typeof(Testclass2).FullName);
> 
>            &nbs
> p;   }
> 
>            &nbs
> p;   finally
> 
>            &nbs
> p;   {
> 
>            &nbs
> p;        AppDomain.CurrentDom
> ain.AssemblyResolve -= CurrentDomain_AssemblyResolve;
> 
>            &nbs
> p;   }
> 
>            &nbs
> p;   AppDomain = domain;
> 
>           }
> 
>           Assembly
> CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
> 
>           {
> 
>            &nbs
> p;   throw new NotImplementedException();
> 
>           }
> 
>           internal
> class Testclass2 : MarshalByRefObject
> 
>           {
> 
>           }
> 
>      }
> 
> }
> 
> ]]>


---
Original message URL:
http://devnet.jetbrains.net/message/5317907#5317907



0

Please sign in to leave a comment.