Core: 'Type' does not contain a definition for 'Assembly' and no extension method 'Assembly' accepting a first argument of type 'Type' could be found (are you missing a using directive or an assembly reference?)

Created on 18 Apr 2017  路  2Comments  路  Source: dotnet/core

Hi there's a red squiggly line beneath Assembly. I get an error saying:

'Type' does not contain a definition for 'Assembly' and no extension method 'Assembly' accepting a first argument of type 'Type' could be found (are you missing a using directive or an assembly reference?) [Algorithms]

How do I fix this? Do need to import some library in .csproj?

dotnet --info
.NET Command Line Tools (1.0.1)

Product Information:
 Version:            1.0.1
 Commit SHA-1 hash:  005db40cd1

Runtime Environment:
 OS Name:     Mac OS X
 OS Version:  10.12
 OS Platform: Darwin
 RID:         osx.10.12-x64
 Base Path:   /usr/local/share/dotnet/sdk/1.0.1
using System;

namespace After037_NewVirtualOverride
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            var baseClass = new BaseClass();
            var derivedOverride = new DerivedOverride();
            var derivedNew = new DerivedNew();
            var derivedOverWrite = new DerivedOverwrite();

            baseClass.Name();
            derivedOverride.Name();
            derivedNew.Name();
            derivedOverWrite.Name();

            Console.ReadLine();
            baseClass.Name();
            derivedOverride.Name();
            ((BaseClass) derivedNew).Name();
            ((BaseClass) derivedOverWrite).Name();
            Console.ReadLine();

            var t1 = typeof (BaseClass);
            Console.WriteLine(t1.Name);
            Console.WriteLine(t1.Assembly);
        }
    }


    internal class BaseClass
    {
        internal virtual void Name()
        {
            Console.WriteLine("BaseClass");
        }
    }

    internal class DerivedOverride : BaseClass
    {
        internal override void Name()
        {
            Console.WriteLine("DerivedOverride");
        }
    }

    internal class DerivedNew : BaseClass
    {
        internal new void Name()
        {
            Console.WriteLine("New");
        }
    }

    internal class DerivedOverwrite : BaseClass
    {
        internal void Name()
        {
            Console.WriteLine("Overwrite");
        }
    }
}

Most helpful comment

you need to call .GetTypeInfo()

prior to .NET Standard:
type.Assembly

now:
type.GetTypeInfo().Assembly

the advantage is that System.Object has no direct dependency to reflection now

All 2 comments

you need to call .GetTypeInfo()

prior to .NET Standard:
type.Assembly

now:
type.GetTypeInfo().Assembly

the advantage is that System.Object has no direct dependency to reflection now

Your code compiles and runs with .NET Core 2.0 Preview 2.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

omerlh picture omerlh  路  4Comments

ugurcemozturk picture ugurcemozturk  路  3Comments

Rand-Random picture Rand-Random  路  4Comments

lesomnus picture lesomnus  路  3Comments

leo2d picture leo2d  路  3Comments