T4MVC: System.InvalidCastException: Unable to cast COM object of type 'System.__ComObject' to interface type 'EnvDTE80.CodeClass2'. - t4mvc

When using T4MVC and attempting to 'Run Custom Tool' I get this:
Running transformation: System.InvalidCastException: Unable to cast COM object of type 'System.__ComObject' to interface type 'EnvDTE80.CodeClass2'.
This operation failed because the QueryInterface call on the COM component for the interface with IID '{295ADCD4-B052-49EE-934E-C6B36862A7C6}' failed due to the following error:
No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
This affects the whole machine, not an individual project.
I've tried:
Re-Installing
Uninstalling
Restarting VS
Restarting Machine

Figured it out.
Remove the project from the solution and re-add it.

Build-"Clear solution" solved this problem

Related

Having an issue importing a tlb file into my MFC Application

I'm trying to create a MFC Automation COM object using MFC Library DLL but I am having issues. I have created the DLL and the TLB file has been generated. When I want to import the TLB file into a MFC Application, Visual Studios tells me
Cannot open source file C:/Users/XXX/documents/visual studio 2015/projects/ComDlgInDll/TestApp/ComDlgInDll.tlh
This is the command I type:
#import "..\Debug\ComDlgInDll.tlb" no_namespace
And even if I just type
#import
It will just go right ahead to the path and say that it cannot find the TLH file.
I don't have a TLH file at all, so I am confused as to why I cannot import it.
I would appreciate a solution since I am new to MFC and COM.
I also wanted to mention when I create a C# Windows Forms application, I add the DLL as a COM reference and then I type:
ComDlgInDll.ComDialogFactory var = new ComDlgInDll.ComDialogFactory();
var.GetDialog();
I get this error:
Retrieving the COM class factory for component with CLSID {1B2F7173-E140-47F3-8921-860BD434B05E} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).
I even went into the registry to search for that uuid and I couldn't find it, which is odd. I am not sure why that uuid that is associated with a coclass is not being registered.
I would appreciate any help on it as I have been dealing with this for quite some time.

Trying to debug from C# into VB6 yields TYPE_E_CANTLOADLIBRARY?

I have a VB6 DLL being accessed from some C# code.
Using the compiled & registered VB6 DLL there is no problem. But when I load the VB6 source into the VB6 IDE and run the project, the next run of the C# code will fail with the error below.
Stopping the running DLL in the VB6 IDE will again allow the C# program to work from the compiled DLL.
The VB6 DLL is compiled with binary compatibility.
The error message I receive in C# is:
An unhandled exception of type 'System.InvalidCastException' occurred
in appname.exe
Additional information:
Unable to cast COM object of type 'dllname.classnameClass' to
interface type 'dllname._classname'.
This operation failed because the QueryInterface call on the COM
component for the interface with IID
'{D8AB6D65-F5E7-4B9C-A039-67DDC630E5F7}' failed due to the following
error:
Error loading type library/DLL. (Exception from HRESULT: 0x80029C4A
(TYPE_E_CANTLOADLIBRARY)).
Specifically this error occurs when the C# code tries to access any part of the interop object which actually comes from the underlying COM object. But accessing .NET Object-derived things like .ToString() work fine on that object.
Why am I getting this error?
Furthermore:
If I compile the C# code when the VB6 code is NOT running, it builds fine. But compiling when the VB6 code IS running, then I get an error:
BC30002 dllname.classname is not defined.
Thanks
Maybe someone else will have a deeper understanding, but this is what I eventually figured out:
Running either Visual Studio (.NET) or Visual Basic 6 as ADMIN while debugging in this scenario would cause the error. Running BOTH as WITHOUT ADMIN rights then it would work.
The quandary is that admin rights are needed for certain build operations (specifically, registering COM DLLs automatically). So that was the pitfall; ultimately I had to repeatedly switch between admin/non-admin settings for both tools in order to code-test-modify...
Note - when I've debugged in a different scenario where the program is a VB6 EXE debugging into C# code, this was never a problem. Everything could run in as admin no problem.

Problems referencing com dlls in vs 2010

I'm running a 32 bit ver of win7 in a vm. I am trying to reference 5 com dlls (VB6) in my .net project. These dlls (and their dependencies) are registered ok since I can use them natively as they form a part of another app and that app is working fine.
I try to set a reference to any of them directly in vs and I get the error message - Library not registered (Exception from HRESULT: 0x8002801D (TYPE_E_LIBNOTREGISTERED)).
However, if I set a reference to another com component (which I don't want to reference but which in turn does reference these libs) I find that the references to these com dlls (which I do want to reference) gets set correctly in vs. I then just need to remove the ref to the unwanted dll and everything seems to be good to go.
If I look at the GUID and version details of one of the successfully referenced component, they appear to be the same as the GUID and version that appears in the caption of the error form, when I unsuccessfully try and set a reference to the same component directly.
BTW I have tried repairing the VS installation to no avail
I was wondering if someone could explain what I am doing wrong.
EDIT: Follow-up following Hans suggestion
So I ran
tlbimp mylib.dll
and it returned a TI1006 error - Output would overwrite the input file. So following suggestions found, I then issued
tlbimp mylib.dll /OUT:interop.mylib.dll
and this then returned the error
TlbImp : warning TI3011 : Type library importer has encountered an interface not derived from IUnknown: '_HiddenInterface'. The interface is skipped.
TlbImp : error TI1033 : Cannot find type 'ADODB._Recordset_Deprecated' in 'ADODB, Version=7.0.3300.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. There could be a mismatch between the referenced assembly and the type library.
But I'm not sure if this is a red herring since this lib could be referenced when successfully referencing the different higher level dll. I have tried with a dll which doesn't reference ADODB and that seems to work using tlbimp. So, e.g.
tlbimp myNONADODBlib.dll /OUT:interop.myNONADODBlib.dll
works from the commandline. However
tlbimp myNONADODBlib.dll
still generates the error TI1006 - output file will overwrite input file, and I cannot reference this into my .net project
EDIT:
There seems to be a problem with ADO and Win7 SP1. http://support.microsoft.com/kb/2517589 which would account for the deprecated error message (TI1033) I was getting, but not why VS was failing to create a CCW for the dll I can manually create a CCW via tlbimp.
EDIT (12/03/28 10:40):
So I have rebuilt the com dll with the suggested tlb. I can now successfully run
tlbimp mylib.dll
without getting any error messages and it appears to complete successfully. However, when I try and add a reference to that dll in VS, I still get the same original error message ( Library not registered (Exception from HRESULT: 0x8002801D (TYPE_E_LIBNOTREGISTERED))). I have checked the registry and the registration looks ok i.e. it is pointing to the correct path - I'm wondering if it is a permissions-type issue - but I am running vs as admin.
EDIT (12/03/28 10:15):
So I ended up creating a new completely new vm with the same environment - and it worked ok. So I've no idea what is going on other than some registry corruption perhaps!
Many thx
Simon.
You need to use REGTLIB.exe to register the type library of the DLLs.
Type library registration is separate from component registration - the type library supports the introspection/type explorer functionality, and isn't usually required for running a precompiled application, though it may be required for compilation.

MiniProfilerEF.Initialize() could not be initialized properly

I just started trying out the mvc-mini-profiler in my MVC3 project with EF4.1 and after changing MiniProfilerEF.Initialize(); to MiniProfilerEF.Initialize_EF42(); I'm getting :
A null was returned after calling the 'GetService' method on a store
provider instance of type
'MvcMiniProfiler.Data.EFProfiledOdbcProviderFactory'. The store
provider might not be functioning correctly.
This method MiniProfilerEF.Initialize(); - was giving me
The given assembly name or codebase was invalid. (Exception from
HRESULT: 0x80131047)
So I've replaced dll's with ones I've manually built from the source.
What could be the problem in here ?
If it helps, the EF team have release a beta preview with a fix for the error
The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047)
See http://blogs.msdn.com/b/adonet/archive/2011/09/28/ef-4-2-release-candidate-available.aspx
You can get it from Nuget using
PM> Install-Package EntityFramework.Preview
I just tested it on my build and it fixes the issue meaning you can just call MiniProfilerEF.Initialize(); as before instead of the new method.
Please analyze what version of Entity Framework your application is using
PM> Get-Package
and then install
MiniProfiler.EF accordingly
Like in my case I installed
Install-Package MiniProfiler.EF5

Failed to generate factory object - 80040154 error

I inherited maintainance of a complex managed/unmanaged project and I hope I can ask this question in a concise way.....
I have an unmanaged class (C++) that I am trying to access through managed code (C#). This is achieved in the following way:
The unmanaged class (Prop) is compiled into an unmanaged dll (PropUnmanaged.dll)
PropUnmanaged.dll is registered with regsvr32
regsvr32 /s PropDLL
The classes and types in PropDLL are exposed to managed code using tlbimp
This creates a managed DLL (PropTypesManaged.dll)
This dll is not registered with regasm nor gacutil
The managed class (MClass) trying to access Prop is implemented in a project that has PropTypesManaged.dll as one of its dependencies
The project that implements MClass fails with the error message
Retrieving the COM class factory for component with CLSID {1EAD9D36-495C-44B2-8559-A6570E1ECE34} failed due to the following error: 80040154
The GUID 1EAD... refers to the GUID of the exposed managed type of the Prop class generated by tlbimp. It is in the registry
Web searches on the error code vaguely suggests that something has gone wrong with the regsvr32 step, but my system reports this step succeeded OK
Where do I start debugging this?
If you're running 64-bit Windows, make sure to change the Platform Target of your C# project to x86:
Open project properties, select the Build tab, under the "General" section, select "x86" from the Platform target drop-down.

Resources