Does Graph SDK work along side VSTO, COM Add-Ins or MS Office COM Interop? - vsto

We have two projects; one's a VSTO Add-in and the other is a TypeLibrary which exposes Outlook COM Interop calls by registering the assembly as a set of COM interfaces.
This setup has allowed us to communicate with Office products (Excel, word, and Outlook) from our old C++ executable. This has been working fine for nearly 10 years.
We've tried adding some Graph API calls and we're getting the following exception:
Exception thrown: 'System.InvalidOperationException' in Microsoft.Identity.Client.Extensions.Msal.dll
The graph api sdk calls I'm making work perfectly fine when in their own projects (e.g. .NET Core) as a class Library. However, when I add that working class library project to my legacy projects, I get the problems above.
Code Being Executed
await graphClient.Me.Request().GetAsync();

Related

VBA Runtime error '-2147221164 (80040154)': class not Registered

I developed a class library in Visual Studio 2019 using the .NET framework. Before building the project, I registered the.dll file to interop COM, and this process gave me a .tlb file. This class library was developed in VB.NET, besides that, it has a simple code: one class with one function (class calcular, function Soma):
It was possible to include the .tlb file in the reference of VBA and I develop a code in this language that uses the class of VB.NET to build the action of the button:
On the other hand, when I execute the code in VBA Excel it shows this message:
If a press the button debug "Depurar" VBA mark the line of the instance of the class
I read other questions about this error but there isn't a way to solve it without change my machine?
ADODB.Connection in VB6 - Open Method fails with Runtime Error '2147221164 (80040154)'
VBA Selenium "class not registered"- 80040154
I already made a repair in my MS Office getting to uninstall to install again, can you help me to solve this error that prevents a run of my library in Excel VBA?
.NET COM visible dlls should be registered using regasm utility with /codebase option.
Assembly Registration Tool
You must register the DLL before it can be used. Every time you compile a new version you need to run:
regsvr32.exe "fullPathAndFileName.dll"
You can add a post-build event to the Release in Visual Studio so that it registers the DLL every time you make a new release. If you are distributing this for others then you will need an installer that puts the DLL in to a proper location and then registers it.
You can unregister it by adding the /u flag
Microsoft Topic

Referencing a COM object via dll in .Net Core 2.0

I am trying to upgrade an old asmx webservice to Web API. Idealy I would like to use .Net Core as that is what we have been developing in. The issue is that the API must communicate with a legacy system using a COM object.
I have copied over the dll (already not ideal, I know) and, the .Net Core API project is able to add it as a reference and the code all compiles. However, on running the code I get the following error when instantiating an object from the dll:
Retrieving the COM class factory for component with CLSID
{CCA0B90B-DFDE-4DD3-9C7B-9769A3F12201} failed due to the following error:
80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).
I've tried to do exactly the same thing using the full .Net framework and everything works as expected so I imagine it is an issue with Core - maybe the portability requirements.
It will not be possible to rewrite the integration to the legacy system at this point and I was just wondering if there was any way around this without using the full .Net framework.
Update
I don't know if this will help but I can created a .Net Framework console app which runs the code just fine. when I reference the project from my .Net Core API and call the exact same code the error above still occurs.

Unable to instantiate COM+ objects installed via exported application

I have a COM+ application that has been exported to an MSI using Component Services and then installed on a test server. The web application (ASP) is unable to instantiate any of the objects it uses from the COM+ application.
The COM+ application consists of three DLLs built in VB6. There is one DLL each for data, application and presentation layers. The web application only uses objects from the presentation layer. The COM+ DLLs call into a couple of .NET DLLs exposed via COM.
When the web application runs, an HTTP 500 - Internal Server Error is returned. No errors appear in the application or system log.
I've tried instantiating the objects from VBScript using WSH.CreateObject and it works only for objects in the data layer. When trying to create object in the application or presentation layer I get the following error:
Error: Could not create object named "My.ProgId"
Code: 800A801D
Source: WScript.CreateObject
Because it fails from VBScript, I suspect that the ASP app is fine and that it is the COM+ application that has issues.
Extra Info
If I uninstall the COM+ application and try to run my VBScript to test instantiation, I get a different error.
Error: Could not locate automation class named "My.ProgId"
Code: 80020009
Source: WScript.CreateObject
Since the errors are different, it seems that COM is at least finding the COM+ objects when they're installed, it's just not able to instantiate them.
I've also tried monitoring the script with ProcessMon. I can see WScript.exe (via COM) querying the registry for the ProgID, and then the CLSID. Eventually the path to the DLL is pulled back and then svchost.exe and dllhost.exe query the registry for the same information using the CLSID and also getting back the path to the DLL. Eventually the DLL has a Load Image operation against it followed by the same for msvbvm60.dll. I don't see anything that points to a failure accessing the COM+ DLL.
I've now tried installing the COM+ application to another Win2k3 server and a Windows XP desktop. I'm getting the same result with being able to instantiate objects from the data layer DLL, but not from the application and presentation layer DLLs. I've also tried getting an old copy of the application layer DLL and I am able to successfully instantiate objects from it. However, when I compare the project files for the two different versions, nothing stands out as being a possible cause of this problem.
The application layer DLL was referencing a struct defined in a .NET assembly. The error was caused by the type library containing the struct not being registered on the deployment machine.
When building the .NET assembly in Visual Studio, it would create a type library for the assembly and register it. When the app was deployed, the .NET assemblies were registered using regasm /codebase <assemblyname.dll>. That would register the classes so that they could be instantiated, but it did not register any structs.
The solution was to use regtlib.exe to register the type library on the test server.
The error messages were of no help at all when trying to discover the cause of the problem. Come on Microsoft!!

error "429" AcitveX Component Can't create object (in vb6)

I have one problem in vb6. I created a .tlb file in VB.net 2005 by adding Com class to project. I built the project, I got .tlb file and .dll files while building project, i selected "Register for Com interop" from project properties and built. It registered autometically and I can use created .tlb file in that PC in Vb6 working fine. if I deploy application to another PC and run I am getting "Error 429 ActiveX Component Can't create object" run time error. What I need to do? Please help me as soon as possible. I can't deploy the application to client due to above error.
one possible solution is to install .net frame work on client pc i never want to install .net framework any other solution will be most appreciatable.
If you've created a DLL in a .NET language (such as VB.NET), the target computer must have the .NET Framework installed in order to use the DLL.
This a hard and fast requirement, irrelevant of how you're utilizing the DLL, whether from a VB 6 application through COM interop or otherwise. It is also a hurdle you'll have to jump over first, before you worry about things like registering COM components, as Uday's answer suggests.
If you don't want a dependency on .NET, you need to use another environment to create the ActiveX DLL; either C++ or VB 6 are possible choices.
One option may be that, while deployment, you need to register that .tlb file in System Registry using regsvr32 command in command-prompt. Generally static libraries does not work until they are registered with System Registry.
You might have seen many programs register components during installation like 'Registering Type Components' or 'Registering COM Components' (for those who do networking especially). Those components are nothing but native COM dlls and tlbs.
so when creating deployment project, add some scripting login to register thode dlls and tlb to System registry using:
regsvr32 <path to tlb/dll>
you have to recursivey call this command for every dll/tlb you want to register with system. For example, if you have 4 dlls and 2 tlbs then you have to call it 6 times providing the path of dll and tlb one at a time.

COM DLL registration failed with TFS 2010

I have a C++ DLL project which is created in VS 2010. It is exposed as COM(ATL). I used this dll to another .NET Project as reference. C++ Project linker settings are set as follows:
­"Register Output" = Yes
"Per-user Redirection = Yes
I created a build definition to build these two projects in tfs 2010. C++ Project builds fine, but .NET project fails because the output dll of C++ project is not registered. Setting to "Per-User redirection" = false does not work. I also tried using WF activity 'InvokeProecss' to register the c++ dll using Regsrv32/batch file/my own exe etc, but I get exit code of 5. My TFS 2010 is in Windows 2008 Server R2. And I think, it's not running the process as admin.
If I generate a interop dll using tlbimp, and then I refer that interop in my .NET proejct, it works fine(oviously in tfs build, I need to add InvokeProecss to call tlb). But this is not acceptable as our general practice is to refer a COM dll directly from .NET proejct.
Can anybody please help about this?
Is there a way to run the tfs automated build activity 'InvokeProcess' as Administrator without prompting for user name/password?
By default, the TFS Build Service runs as the "Network Service" account which is a relatively low-privilege account. Alternatively, you can configure it to run as any domain account you like. I wouldn't recommend that as a solution to the problem you described, however. I would agree with Hans that, in this case, it would be better to use the type library importer (TlbImp.exe) to "reference" your COM server from your managed assembly.
If the COM object isn't changing, you can just use the type library importer to generate an interop assembly, check that in and reference it from your .NET project. If it is changing, you can add a post-build step to generate the interop assembly rather than using the InvokeProcess activity. As Hans pointed out, you can't actually reference a COM object directly from a managed assembly. Your reference is actually causing an interop assembly to get generated at build time after resolving the reference to the registered COM server.