Skip to content
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 embedded interop types #13813

Merged
merged 14 commits into from
Mar 15, 2023
Merged

Support embedded interop types #13813

merged 14 commits into from
Mar 15, 2023

Conversation

pinzart90
Copy link
Contributor

@pinzart90 pinzart90 commented Mar 10, 2023

Changes:
Interop types equivalence is checked when importing types from assemblies.

Embedded interop types will appear as distinct when you check type.Equals(other).
Dotnet provides a new API to check equivalence = IsEquivalentTo
https://learn.microsoft.com/en-us/dotnet/framework/interop/type-equivalence-and-embedded-interop-types

Potential issues:
Even though the main part of dynamo that deals with import of types is now updated, there is a risk that other parts of dynamo still have code that compare type.Equals(other). This sort of code will not work as expected for embedded interop types

throw new InvalidOperationException(string.Format("Can't import {0}, {1} is already imported as {2}, namespace support needed.", type.FullName, type.Name, otherType.FullName));
}

mTypes.Add(type, mtype);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if I add the other type in the type map (even though they are equivalent) Dynamo engine will complain and fail to compile the graph
If I skip the other type (and only keep the first equivalent type) then we get into stackoverflows (types are expected to get stored in ther type map)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so - does this mean that we cannot even the more general case where 2 packages depend on the same binary?
If I skip the other type (and only keep the first equivalent type) then we get into stackoverflows (types are expected to get stored in ther type map)

It seems it must be possible - consider the Revit API, many packages reference it, but none distribute it.

OR are you trying to solve a different problem with his PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is visible only when you embed types in the managed assembly.
"Normal" references will work just fine (like Revit API references)

@pinzart90 pinzart90 changed the title [TEST-Do not merge] update Support embedded interop types Mar 13, 2023
@pinzart90 pinzart90 requested a review from mjkkirschner March 13, 2023 19:34
@pinzart90 pinzart90 marked this pull request as ready for review March 13, 2023 19:34
@pinzart90 pinzart90 requested a review from sm6srw March 13, 2023 19:39
{
lock (mTypes)
{
if (!mTypes.TryGetValue(type, out mtype))
mtype = new CLRModuleType(type);
//Now check that a type with same name is not imported.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this comment entirely accurate anymore?

@@ -22,9 +22,16 @@
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="$(PkgMicrosoft_Office_Interop_Excel)\lib\net20\Microsoft.Office.Interop.Excel.dll">
<EmbedInteropTypes>True</EmbedInteropTypes>
<WrapperTool>tlbimp</WrapperTool>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is this?

@@ -22,9 +22,16 @@
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="$(PkgMicrosoft_Office_Interop_Excel)\lib\net20\Microsoft.Office.Interop.Excel.dll">
Copy link
Member

@mjkkirschner mjkkirschner Mar 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this reference be wrapped in a condition for now? (I mean the one below)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will this make it to the bin folder? I think we purposefully removed it at some point.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

totally forgot about test dlls. Will work on removing them

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

<PackageReference Include="Microsoft.Office.Interop.Excel" Version="15.0.4795.1000" GeneratePathProperty="true">
<ExcludeAssets>all</ExcludeAssets>
</PackageReference>
<Reference Include="$(PkgMicrosoft_Office_Interop_Excel)\lib\net20\Microsoft.Office.Interop.Excel.dll">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so is there anything in this binary except for the office types?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, just office types and a wrapping class

Copy link
Member

@mjkkirschner mjkkirschner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

provided the tests pass, I think it seems great except my question about the test binaries making their way to the bin folder.

I also am still not sure if the normal reference case works fine - but let's table that until we get a report from customers - maybe it was fixed a while ago and I missed it.

@pinzart90
Copy link
Contributor Author

provided the tests pass, I think it seems great except my question about the test binaries making their way to the bin folder.

I also am still not sure if the normal reference case works fine - but let's table that until we get a report from customers - maybe it was fixed a while ago and I missed it.

maybe we can discuss this tomorrow, maybe I am missing something

@pinzart90 pinzart90 requested a review from mjkkirschner March 14, 2023 19:12
@pinzart90 pinzart90 merged commit fdaf68f into master Mar 15, 2023
@pinzart90 pinzart90 deleted the test_embeded_iterop branch March 15, 2023 13:49
sm6srw pushed a commit to sm6srw/Dynamo that referenced this pull request Mar 29, 2023
* update

* Update CLRDLLModule.cs

* update

* Create EmbeddedInterop.dll

* update

* Update ProtoTest.csproj

* update

* update

* Update FFITarget.csproj

* update

* Update ClassFunctionality.cs

* update

* Update DynamoCore.csproj

* Revert "Update DynamoCore.csproj"

This reverts commit cab284e.

---------

Co-authored-by: pinzart <[email protected]>
sm6srw pushed a commit that referenced this pull request Apr 5, 2023
* update

* Update CLRDLLModule.cs

* update

* Create EmbeddedInterop.dll

* update

* Update ProtoTest.csproj

* update

* update

* Update FFITarget.csproj

* update

* Update ClassFunctionality.cs

* update

* Update DynamoCore.csproj

* Revert "Update DynamoCore.csproj"

This reverts commit cab284e.

---------

Co-authored-by: pinzart <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants