Book a Demo

Author Topic: Problems with casting  (Read 7574 times)

Viking

  • EA User
  • **
  • Posts: 478
  • Karma: +2/-2
    • View Profile
Problems with casting
« on: August 12, 2020, 04:10:41 am »
Hi,

I tried to build my Addin-code, written in C#, with Embed.Interop.Types = False and Copy.Local = True. It was Embed.Interop.Types = True before.

Now I get a lot of errors. The compiler tells me that I have to cast many return objects.

For example: Sparx.Repository.GetDiagramByGuid(GUID) normally gives back a Diagram (and did before). Now it gives back an Object and I have to cast it to Diagram.

Why does this happen? It looks like anther version of Interop.EA? Or is the reason that the interop-functionality of COM is turned off when using Embed.Interop.Types = False ? But the setting (Embed.Interop.Types = False) is very common.

Many thanks, V.
« Last Edit: August 12, 2020, 04:07:27 pm by Viking »

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Problems with casting
« Reply #1 on: August 12, 2020, 02:06:44 pm »
Yes, Embed Interop Types should be false.

Not sure what's happening there.

Geert

Viking

  • EA User
  • **
  • Posts: 478
  • Karma: +2/-2
    • View Profile
Re: Problems with casting
« Reply #2 on: August 12, 2020, 04:14:50 pm »
Yes, Embed Interop Types should be false.
Not sure what's happening there.
Geert

Why should it be false?

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Problems with casting
« Reply #3 on: August 12, 2020, 06:21:20 pm »
I'm not sure. I remember getting some errors when embed interop types was true.
Too long ago to remember the exact details, I just know it works when it is set to false :)

Geert

Uffe

  • EA Practitioner
  • ***
  • Posts: 1859
  • Karma: +133/-14
  • Flutes: 1; Clarinets: 1; Saxes: 5 and counting
    • View Profile
Re: Problems with casting
« Reply #4 on: August 12, 2020, 07:14:41 pm »
Yes, Embed Interop Types should be false.
Not sure what's happening there.
Geert

Why should it be false?

Yes, why should it?

Microsoft recommends empbedding interop types if you're targeting .NET 4.0 or higher, which everyone does these days. All the types that you use in the API are interfaces. So why not embed them?

For example: Sparx.Repository.GetDiagramByGuid(GUID) normally gives back a Diagram (and did before). Now it gives back an Object and I have to cast it to Diagram.

Yes. This is because you're now having to deal with type equivalence yourself, instead of embedding the types.

Simple solution: embed the types.

Harder solution: get to grips with the whole COM <-> .NET type equivalence thing. You can start with https://docs.microsoft.com/en-us/dotnet/framework/interop/compiling-an-interop-project, https://docs.microsoft.com/en-us/previous-versions/dotnet/netframework-4.0/3y76b69k(v=vs.100), https://docs.microsoft.com/en-us/dotnet/framework/interop/type-equivalence-and-embedded-interop-types and https://docs.microsoft.com/en-us/dotnet/standard/assembly/embed-types-visual-studio.

Incidentally, I do have a product underway that takes the drudgery out of EA add-in construction. It handles all the interop stuff, creates an installer so you can distribute your add-in to others, and also allows you to debug your add-in, all out of the box. In short, with this thing you won't need to know how COM <-> .NET interop works in order to build an EA add-in. Coming SoonTM. :)


/Uffe
My theories are always correct, just apply them to the right reality.

Viking

  • EA User
  • **
  • Posts: 478
  • Karma: +2/-2
    • View Profile
Re: Problems with casting
« Reply #5 on: August 12, 2020, 07:18:07 pm »
Many thanks @Geert and @qwerty.

Viking

  • EA User
  • **
  • Posts: 478
  • Karma: +2/-2
    • View Profile
Re: Problems with casting
« Reply #6 on: August 12, 2020, 07:21:58 pm »
Incidentally, I do have a product underway that takes the drudgery out of EA add-in construction. It handles all the interop stuff, creates an installer so you can distribute your add-in to others, and also allows you to debug your add-in, all out of the box. In short, with this thing you won't need to know how COM <-> .NET interop works in order to build an EA add-in. Coming SoonTM. :)
/Uffe

Many thanks @Uffe. Sounds promising. Coming soon sounds even more promising :)

By the way: could you tell me what happened with the (promising) solution, mentioned here: https://www.sparxsystems.com/forums/smf/index.php?topic=39511.0

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Problems with casting
« Reply #7 on: August 12, 2020, 08:10:37 pm »
Yes, Embed Interop Types should be false.
Not sure what's happening there.
Geert

Why should it be false?

Yes, why should it?
I really don't remember. All I know is that it works when I have it set to false, and I don't really enjoy debugging COM dll issues. :-\
But you might be entirely correct that it would be better to embed the interop types.

Geert

Uffe

  • EA Practitioner
  • ***
  • Posts: 1859
  • Karma: +133/-14
  • Flutes: 1; Clarinets: 1; Saxes: 5 and counting
    • View Profile
Re: Problems with casting
« Reply #8 on: August 12, 2020, 08:24:55 pm »
Incidentally, I do have a product underway that takes the drudgery out of EA add-in construction. It handles all the interop stuff, creates an installer so you can distribute your add-in to others, and also allows you to debug your add-in, all out of the box. In short, with this thing you won't need to know how COM <-> .NET interop works in order to build an EA add-in. Coming SoonTM. :)
/Uffe

Many thanks @Uffe. Sounds promising. Coming soon sounds even more promising :)

By the way: could you tell me what happened with the (promising) solution, mentioned here: https://www.sparxsystems.com/forums/smf/index.php?topic=39511.0

Yes, uh... it got shelved, what with one reason and another.  :-[

Part of it was to do with one (or two?) nasty bugs in Visual Studio which I couldn't (and didn't want to) work around.
But they have subsequently been fixed, and the thing now works perfectly in Visual Studio 2019 Community and Professional.

There's three things left to do really: user manual, testing on other Studio and Windows versions (which is not difficult but time-consuming for a one-man shop) and implementing license management, which is a massive PITA to tell you the truth. I've got a third-party solution lined up, but I still need to integrate it into my code which is going to take a few weeks as I'm also consulting full-time.

/U
My theories are always correct, just apply them to the right reality.

Viking

  • EA User
  • **
  • Posts: 478
  • Karma: +2/-2
    • View Profile
Re: Problems with casting
« Reply #9 on: August 13, 2020, 05:31:03 pm »
There's three things left to do really: user manual, testing on other Studio and Windows versions (which is not difficult but time-consuming for a one-man shop) and implementing license management, which is a massive PITA to tell you the truth. I've got a third-party solution lined up, but I still need to integrate it into my code which is going to take a few weeks as I'm also consulting full-time.
/U

Hi Uffe, when will the product be available? Will it be a free / commercial, open source / closed source?

Uffe

  • EA Practitioner
  • ***
  • Posts: 1859
  • Karma: +133/-14
  • Flutes: 1; Clarinets: 1; Saxes: 5 and counting
    • View Profile
Re: Problems with casting
« Reply #10 on: August 14, 2020, 05:04:53 pm »
Hello,


I'm afraid I don't have an exact date. I'm in the middle of talking to a lawyer to get the license agreement properly worded, and there's a bit of code to write (and thus test) relating to license verification.

It will be a commercial license, closed source. There will be a free trial version entitling you to create a limited number of add-ins.
For the paid version I haven't decided on whether to offer a subscription license, a pay-per-use license, or both.

So a few weeks still for sure, tentatively shooting for an October 1st launch. But don't hold me to that. ;)


/Uffe
My theories are always correct, just apply them to the right reality.

Ian Mitchell

  • EA User
  • **
  • Posts: 507
  • Karma: +22/-4
  • The eaDocX and Model Expert guy
    • View Profile
Re: Problems with casting
« Reply #11 on: August 14, 2020, 05:53:18 pm »
A copy for me please, @Uffe.
Excellent idea for a product - even for expert EA users, the set of knowledge needed to go from "a great idea" to "a useful product" is very large, and I'm sure this will help lots of great ideas to get out into the market.
<revolution>
Maybe Release 2 could be a Restful web API into EA....
</revolution>
Ian Mitchell, Designer, eaDocX


www.eaDocX.com
www.theartfulmodeller.com