-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for TypeLibs needed for assembly consumption as VBA references #3740
Comments
@robert-io I will try to reproduce this issue locally, but I think the issue here is the missing ProgID support we recently added - dotnet/core-setup#7573. I will verify the above scenario works though. |
@AaronRobinsonMSFT hi, have you been able to reproduce this and is there any update regarding addressing the issue? |
@robert-io Sorry for the late reply. I verified the ProgIDs are being respected and I am able to activate them as desired with the official .NET Core 3.0 release. Have you been able to try the latest as well? |
@AaronRobinsonMSFT i have tested it with 3.1 Preview 2 and it works in VB Script but i can't add a reference to the DLL in VBA. I used Excel (32bit) VBA with and compiled the dotnet Core Assembly with the platform target set to x86. When i use the Tools -> References dialog to add a reference its not listed and when i browse to the DLL i get the following error: |
@AaronRobinsonMSFT could you please take a second look? |
@vitek-karas I am doubtful we can do anything in the 3.1 time frame for this issue. The underlying issue here is that VBA wants a TypeLib generated for the .NET types and since CoreCLR no longer generates TypeLibs, the VBA editor fails to add the reference. This is unfortunate, but unless we bring back TypeLib generation I don't see how we can make work automatically. @robert-io In this case, the only solution here will be to create a TypeLib for the types and register that. I will need to think more about this because I don't fully know the best way to address the scenario. The issue as stated above is that the COM host DLL is being loaded via |
@AaronRobinsonMSFT i have tested your recommendation of creating a TypeLib and registering it and it works. To generate the tlb file (not ideal but functional)
I'm going to be thinking about how i can make this process simpler for me. i would still be interested in the CoreCLR generating the TypeLibs but understand that there is not enough time to get that into the 3.1 release. |
Thanks @AaronRobinsonMSFT - moved it to 5 for now. |
@robert-io Thank you for the confirmation.
Absolutely agree. I will admit ignorance and didn't realize the TypeLib generation was a VBA requirement, this is unfortunate. Adding transparent TypeLib support in .NET Core that is similar to .NET Framework is probably going to be a hard sell for various reasons. Some options exists though and I encourage you and the rest of the community to help us define what would address the needs in these scenarios. A possible solution here would be to "port" the Please keep filing suggestions and/or proposals for addressing this as it is how we prioritize work and demonstrate community need. |
Unfortunately I don't think we're going to get to this for 5.0 either. Moving to 6.0. |
Would it be easier if you were given a IDL file and generate .NET types derived from the IDL which can be then implemented as interfaces? I'd rather be able to directly consume an IDL file which also would help guarantee ABI compatibility without getting lost in the marshalling quagmire. |
@bclothier Going the IDL -> TLB -> .NET interfaces is already supported, albeit with the .NET Framework tool - |
@AaronRobinsonMSFT Is there any way to circumvent the missing typelib generation in .Net 5 right now? We are trying to migrate a huge legacy VB application to dotnet and will have the need for COM Server interop for at least a few years. As the API surface on the Dotnet side grows, strong typing is going to be absolutely crucial. Right now we are solving it with late binding but the lack of intellisense and type checking makes this not really a viable option for the future. |
@BickelLukas The solution for the missing TypeLib generation is to define all interfaces in IDL and then produce a TLB using the MIDL compiler. This TLB can then be registered on the machine instead of being provided in an ad-hoc manner which was the previous manner for .NET Framework. The workaround was described above in #3740 (comment). However, it seems that I could be mistaken as to what you are asking. It sounds like you are attempting to convert a VB application to .NET - yay by the way. So is the issue not being able to project the VB types in .NET? This could be achieved using |
@AaronRobinsonMSFT yes you did understand correctly. The question was about consumung .Net types in VB. This is needed since the core of the app is (and probably will stay for a while) in VB but new functionality is developed in .Net. If you are interested in hearing more about the application and our migration approach you can email me at lukas.bickel@consolidate.at I did stumble upon the manual IDL approach before. However I was struggling with writing the IDL files by hand. If you could point me at some resources where a plain old C# dev can aquire the needed skills it would be greatly appreciated. Maybe there is even an automatic conversation tool? |
@BickelLukas Yep, IDL is a rather esoteric language and exposes a lot of RPC concepts that clutter what most .NET developers want from it. In order to get at the IDL I would go about this as follows.
That will give you a good starting point. I would compile it locally using the MIDL compiler and then iterate as you define the contract you would like to expose from .NET 5. The MIDL language reference is helpful here. |
Just to follow up on the request. One problem with the manual IDL generation workaround is that there is no good way to import the definition, or at least I couldn't work it out.
The point here is that this requires 2 parallel processes -- we continue to decorate our classes with various interop attributes but we also have to maintain the IDL file externally. Both must be kept in the sync. That's going to be a lot of work and inherently error-prone. I also am not sure I understand the difficulty of enabling type lib generation. If we can use an abstract type lib created out of thin air from a MIDL compiler and have it work well with .NET core objects, what's stopping the .NET Core from automatically generating a type library? |
For those interested, there's now a project to implement type library generation using pure .NET Core 3.1 to not have to depend on non-dotnet build tools. |
There are two parts to this problem unfortunately. The first part is that the original Regarding "not sure I understand the difficulty of enabling type lib generation" and "what's stopping the .NET Core from automatically generating a type library?". I see the project mentioned in #3740 (comment) and we wanted to do this but it will become difficult rather quickly - at least if one wants to make the results close or identical to the existing All that aside, your and the community efforts here are much appreciated and something we would be more than willing to help encourage. Please keeps us posted on the project's progress and if help is needed here please let us know. |
Thank you for the background. I did notice that the existing implementation of the It's good to know that it may be challenging to get identical results as the |
They are marked as such merely because of the original .NET Core release where these COM types were really obsolete. Filing an issue about these types can help us to identify the ones that really are obsolete and those that will remain as long as .NET Core/.NET 5+ supports the Windows platform - so forever. I think I provided feedback in #13264 about filing issues in dotnet/corefx, those issues should now be filed in dotnet/runtime. |
@AaronRobinsonMSFT Is there any option to directly embed the tlb as a win32 resource inside the comhost dll? |
@BickelLukas The answer is no, but that is a good suggestion. I think the SxS manifest can reference non-embedded TLBs right? That might be an option for now. The idea of enabling this though is appealing and would help to further champion our RegFree approach. Can you file an issue with this suggestion? The relevant code links are below. SDK that requests ComHost creation: |
The current path remains creating an IDL and generating a TLB. Embedding a type library is supported as of .NET 6 and the out-of-process COM server sample shows how it can be used. We don't have plans to bring For C#, we will be investing in source generation for COM. One of the future goals of that is to enable a tlbexp replacement. |
Steps to reproduce
Create a .Net Core Class Library and set the Target Framework to .NET Core 3.0 and add the following code (setting you own GUIDs) in the PersonRegistration class:
Desired behavior
Using VBA or VBScript create and use the object. For example the following VBS should create the object and show the persons age in a message box:
Actual behavior
A Windows Script Host error box with the following error is displayed:
~ ActiveX component can't create object
Environment data
Windows 10
VS 2019 with the .NET Core 3.0 Preview 8 SDK
Additional
I can see from the warnings in my code that
ComInterfaceType.InterfaceIsDual
& ComSourceInterfaces are marked obsolete.~ Will Microsoft be adding support for
ComInterfaceType.InterfaceIsDual
& ComSourceInterfaces?~ Or is there another way to implement a scriptable (IDispatch) COM object?
The text was updated successfully, but these errors were encountered: