5

I'm porting a .net 4.7 project to .net standard, which uses T4 to generate some code. I iterate over the classes, properties and methods. This use to work perfectly, but now the return types of DTE are of type 'System.__ComObject' and I cannot cast them.

Error: Unable to cast COM object of type 'System.__ComObject' to interface type 'EnvDTE.CodeClass'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{B1F42514-91CD-4D3A-8B25-A317D8032B24}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).

Any ideas how to fix this?

Example:

public static bool CheckBase(CodeClass codeClass, string baseName)
{
    var bases = codeClass.Bases;
    if (bases != null)
    {
        foreach (CodeClass baseClass in bases)
        {
            if(baseClass.Name == baseName) return true;
        }
    }
    return false;
}
hvk
  • 430
  • 4
  • 11
  • 2
    I kinda doubt this is possible. net standard projects are supposed to be cross-platform. EnvDTE aint. –  Oct 04 '17 at 20:48
  • 1
    T4 templates and generators should be supported (makes your project work in VS only though) but I guess this is a side effect of the project not using the legacy c# project system but the new project system developed at https://github.com/dotnet/project-system – Martin Ullrich Oct 05 '17 at 04:07
  • There should be something helping us with this issue. .NET Standard projects support every platform and each platform uses Visual Studio as the main environment, it's really needed. – Mo Sadeghipour Jan 28 '18 at 12:49
  • 2
    I know it's old, but for anyone searching in the future, [EnvDTE](https://www.nuget.org/packages/EnvDTE/16.7.30328.74) now supports .NETStandard 2.0. – RyuzakiH Oct 23 '20 at 23:34

0 Answers0