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

Xamarin.Forms.Platform.WPF dependency issue using .Net5.0 #8

Closed
topeterk opened this issue May 8, 2021 · 12 comments
Closed

Xamarin.Forms.Platform.WPF dependency issue using .Net5.0 #8

topeterk opened this issue May 8, 2021 · 12 comments

Comments

@topeterk
Copy link

topeterk commented May 8, 2021

Hi, maybe you guys know, how to handle this problem:

I'm trying to build a WPF application using Xamarin by targeting .Net5.0.
But I cannot figure out any way of getting this working as it looks like that <PackageReference Include="Xamarin.Forms.Platform.WPF" Version="5.0.0.2012" /> will implictily load OpenTK.GLControl in version 3.0.1 as this is the latest one. But it is not compatible with the <TargetFramework>net5.0-windows</TargetFramework>.
OpenTK 4.4.0 seem to be compatible but it is not providing OpenTK.GLControl via NuGet, so this doesn't help me either.

Any idea what I am missing?

My hope was building this project here and just replace the dependency from the NuGet packages of OpenTK.GLControl. But I cannot get rid of this dependency error:
image

Can this approach even work (replacing the dependency)?

Any help is appreciated!

Thanks,
Peter

@seanofw
Copy link
Collaborator

seanofw commented May 9, 2021

I don’t know for sure if that’ll work, but you can try it with an updated Nuget package. There is a Nuget package for the new GLControl, but @varon has been too busy to switch it over to the official account. You could try downloading it to your local Nuget folder and see if it gets picked up properly.

https://www.nuget.org/packages/OpenTK.WinForms/4.0.0-pre.5

@topeterk
Copy link
Author

topeterk commented May 9, 2021

With enabling the preview versions I found and integrated this version into the project.

The visual studio project keeps showing me as target framework ".NET 5.0" now, which is good (previously as it was "empty" after adding the Xamarin.Forms.Platform.WPF NuGet package.
However, the NuGet package for OpenTK.GLControl in version 3.0.1 was still added to the project and still shows me an incompatibility warning.

Just for my understanding, the OpenTK.WinForms is the "successor" of OpenTK.GLControl and (in the future) should be used as replacement of the OpenTK.GLControl dependency in Xamarin.Forms.Platform.WPF? Or will it be released as OpenTK.GLControl 4.x.x?

@seanofw
Copy link
Collaborator

seanofw commented May 10, 2021

I can't really speak about Xamarin, since I really don't know it.

OpenTK 4.0 was a major rewrite/restructuring of OpenTK; it has some similarities to OpenTK 3, but under they hood, they're very, very different. Likewise, the OpenTK GLControl 4 is a near-total rewrite; and while it has a similar API to the OpenTK GLControl 3, it's almost completely different code under the hood, designed for the needs of OpenTK 4 and .NET Core.

So OpenTK 4 is a successor to OpenTK 3; it's for .NET Core and .NET 5+, while OpenTK 3 is for .NET Framework 4.x and earlier. The GLControl 4 is not really a direct successor to GLControl 3; it's more of an equivalent control, but for OpenTK 4, if that makes sense. It replaces the GLControl 3 in a lot of instances, but it's only superficially similar to the old control, so I don't know if it's an exact replacement for your needs.

However, it will be released as the new OpenTK.GLControl Nuget package at some point when @varon can get to it.

@topeterk
Copy link
Author

Hmm okay, I understand.

A (preview) release of OpenTK.GLControl would be great because this will eventually eliminate the NuGet dependency issues.
I know it can be quite hard to keep the "old API" alive while reworking the back end.

Until new NuGet packages become available, I will try figuring out if I can get it running with the locally built version. Or I have to fallback to .Net Framework in the meantime.

Thank you!

@seanofw
Copy link
Collaborator

seanofw commented May 10, 2021

The preview release is the link I provided above. Eventually, @varon will just move it from the account @bezo97 created it in to be owned by OpenTK instead, and then it'll be the official new release.

Hope that helps!

@topeterk
Copy link
Author

For me, it looks like that NuGet sees "OpenTK.WinForms" != "OpenTK.GLControl" and that is why it loads OpenTK.GLControl even when OpenTK.WinForms is already part of the project's available NuGet packages. Can those names actually be different or it this the reason for "bypassing" the NuGet dependencies - I'm not so familiar with the NuGet "behind the scenes".

@seanofw
Copy link
Collaborator

seanofw commented May 11, 2021

NuGet goes by the package names, not the namespaces; but it wouldn't surprise me if they're different enough that it just assumes they're different packages. You may need a special version of the new GLControl package to satisfy the dependency, and even so, that's no guarantee that the new GLControl is compatible enough that Xamarin's WPF code will accept it.

Looking at what you're doing, I realized you're doing WPF, so it's worth pointing out that there's a native OpenTK WPF control in development as well. You may want to consider looking at that project for your needs: It's not a wrapper around WinForms, but is a real, native WPF control. I don't know whether Xamarin will like that either, but I suspect that may lead to better results than trying to hack the new GLControl into Xamarin's dependency chain. I don't follow that project closely, but you could try seeing if their control meets your needs better.

@topeterk
Copy link
Author

Interesting .. I was following this guide here: https://docs.microsoft.com/en-us/xamarin/xamarin-forms/platform/other/wpf Unfortunately it seems to me, the guide is out of date as it uses .Net Framework in its example but I haven't found any example for .Net 5.0 anywhere on the internet.
It feels like I'm the first and only one actually doing this.

WindowsForms was not really listed for a Xamarin application and I'm not sure if UWP would fit my needs, so I though about using WPF - maybe I have to rethink that. I'm still surprised that I ran into OpenTK at all as I expected the full WPF stack being provided by Microsoft.

By now, cross platform development worked a lot better for me with .Net Framework 2.0: One file that can be launched on Windows, Linux and Mac even with a GUI. By running into this Xarmarin complexity, its dependencies and incompatibilities, I'm not sure if I should continue at all porting my old application to the "latest and greatest" technology 🤔

@seanofw
Copy link
Collaborator

seanofw commented Oct 28, 2021

Since this issue hasn't had any activity in several months, I'm going to close it. If you have other questions, please open another issue.

@seanofw seanofw closed this as completed Oct 28, 2021
@NogginBops
Copy link
Member

I'll add here that if you are using Wpf you might want to look into the OpenTK.GLWpfControl package as it provides a control better suited for Wpf

@topeterk
Copy link
Author

I just want to use Xamarin on various platforms. As it is not portable I have to choose platform specific parts for like iOS, Android or Desktop like using GTK or WPF. For WPF the way to go is using Xamarin.Forms.Platform.WPF but this package (not myself!) is referring to old OpenTK version, so it blocks upgrading to .Net5 as OpenTK version 3 does not support .Net5. Do you mean by that, that I can somehow replace OpenTK 3 references from Xamarin.Forms.Platform.WPF with (a specific? version of) OpenTK.GLWpfControl instead?

@NogginBops
Copy link
Member

Atm it's currently impossible to run newer versions of OpenTK on Xamarin due to this issue. Xamarin has not considered changing this until recently when they finally (after 8 years) decided to make a binary breaking change. This issue can be tracked at xamarin/xamarin-macios#13160 and should be fixed in the upcomming release of .net 6 (November 9th).

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

No branches or pull requests

3 participants