unoplatform / uno

Open-source platform for building cross-platform native Mobile, Web, Desktop and Embedded apps quickly. Create rich, C#/XAML, single-codebase apps from any IDE. Hot Reload included! 90m+ NuGet Downloads!!
https://platform.uno
Apache License 2.0
8.89k stars 720 forks source link

Problem with references in library projects that should be TypeForwarded #446

Closed yowl closed 5 years ago

yowl commented 5 years ago

I'm submitting a...

Current behavior

The referenced type that should be resolved through a TypeForwardTo seems to cause problems.

Expected behavior

Should be possible to reference these types from a library project.

Minimal reproduction of the problem with instructions

Take the repo at https://github.com/yowl/UnoStandardRefTest build, deploy and run the UWP head, and hopefully it will fail with

{System.TypeLoadException: Could not load type 'System.Runtime.CompilerServices.IAsyncStateMachine' from assembly 'System.Runtime, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
   at UnoLib.Class1..ctor()
   at UnoStandardRefTest.MainPage..ctor()
   at UnoStandardRefTest.UnoStandardRefTest_UWP_XamlTypeInfo.XamlTypeInfoProvider.Activate_0_MainPage()
   at UnoStandardRefTest.UnoStandardRefTest_UWP_XamlTypeInfo.XamlUserType.ActivateInstance()}

It works ok if the type is used in the UWP head directly.

Environment

Nuget Package: 
Uno.UI 1.42.0
Package Version(s): 

Lib csproj:

<Project Sdk="MSBuild.Sdk.Extras/1.6.65">
  <PropertyGroup>
    <TargetFrameworks>netstandard2.0;uap10.0.16299</TargetFrameworks>

Affected platform(s):
- [ ] iOS
- [ ] Android
- [ ] WebAssembly
- [ x] Windows
- [ ] Build tasks

Visual Studio
- [x ] 2017 (version: 15.9.4)
- [ ] 2017 Preview (version: )
- [ ] for Mac (version: )

Relevant plugins
- [ ] Resharper (version: )
yowl commented 5 years ago

I note that changing the UWP head proj: from

      <Version>6.1.7</Version>

to

      <Version>6.2.3</Version>

Allows for successful loading of the type.

jeromelaban commented 5 years ago

That could be an issue caused by the fact that NuGet package references are not transitive between legacy style projects and sdk-styled projects. As of release 1.6.65, MSBuildExtras provides version 6.2.2 but the head project uses another. There was probably a breaking change between version 6.2.2 and 6.1.7 of the Microsoft.NETCore.UniversalWindowsPlatform package.

In a non-project dependency (e.g. if you library was referenced as a nuget package) this would not happen as the reference would be matching the one from the nuget package.

I'll adjust the Uno templates so the default works, at least.

yowl commented 5 years ago

Makes sense. If you're updating the templates you might want to change the MSBuild version from 14 to 15, unless of course you are supporting VS2015.

xperiandri commented 3 years ago

Solution template still has reference to this issue https://github.com/unoplatform/uno/blob/8cff819daaa72bbe694a06ffdc21424aa186d8f4/src/SolutionTemplate/UnoSolutionTemplate/UWP/UnoQuickStart.Uwp.csproj#L9 Is it still relevant?