dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
15.26k stars 4.73k forks source link

''System.__ComObject' does not contain a definition for 'Visible'' #13274

Closed PcMaKeR closed 4 years ago

PcMaKeR commented 5 years ago

Hello everybody.

Getting an error on dotnet core 3 preview8:

my code:

` using System;

namespace ConsoleApp1 { class Program { static void Main(string[] args) { string progId = "InternetExplorer.Application"; Type type = Type.GetTypeFromProgID(progId); dynamic inst = Activator.CreateInstance(type);

        inst.Visible = true;
        inst.Navigate("https://msdn.com");

        bool result = inst.Visible;

        Console.WriteLine(result);
    }
}

} `

error line:

inst.Visible = true;

dlr activated?

jkotas commented 5 years ago

cc @AaronRobinsonMSFT

AaronRobinsonMSFT commented 5 years ago

@PcMaKeR Thanks for reporting this issue. Support for usage of the dynamic keyword with COM objects wasn't done for .NET Core 3.0. This issue is being track in https://github.com/dotnet/coreclr/issues/24246 for .Net 5. The work around is to cast the class to the corresponding interface.