Skip to content

Add support for in parameter modifier on .NET Core by adding .NET Standard 1.5 as additional target - #344

Merged
jonorossi merged 5 commits into
castleproject:masterfrom
stakx:valuetype-ref-semantics
May 2, 2018
Merged

jonorossi merged 5 commits into
castleproject:masterfrom
stakx:valuetype-ref-semantics

Conversation

@stakx

@stakx stakx commented Apr 20, 2018 •

Copy link
Copy Markdown
Member

This is an attempt at solving #339.

It would be good if someone who's intimately familiar with the build process could take a closer look at what I've done in order to add the additional netstandard1.5 target:

  • Have I done all that's required when adding a new TFM, or did I miss something, somewhere?
  • Should the 3 logging integration projects also get the new netstandard1.5 target to stay in-sync with Castle.Core?

@stakx

stakx commented Apr 20, 2018

Copy link
Copy Markdown
Member Author

Regarding the Travis CI build failures:

CSC : error CS1617: Invalid option '7.2' for /langversion; must be ISO-1, ISO-2, Default
or an integer in range 1 to 6.
[/home/travis/build/castleproject/Core/src/Castle.Core.Tests/Castle.Core.Tests.csproj]

Since this seems to be Microsoft's compiler (csc), I wonder why it doesn't know language versions >6. Is this because of the .NET 4.6 targeting pack?

Also, it seems that Mono's C# compiler (mcs) does not yet know C# 7.2 features. Both the <LangVersion> in Castle.Core.Tests.csproj as well as the unit tests added in this PR should be hidden from Mono. I'm not exactly sure how to do this properly.

/usr/share/dotnet/sdk/1.0.4/NuGet.targets(97,5): error : Unable to resolve 
'Microsoft.DiaSymReader.Native (>= 1.4.1)' for '.NETCoreApp,Version=v1.1'.
[/home/travis/build/castleproject/Core/buildscripts/BuildScripts.csproj]

This seems to be a general issue with the build process, and therefore unrelated to this PR.

@jonorossi

Copy link
Copy Markdown
Member

Have I done all that's required when adding a new TFM, or did I miss something, somewhere?

Looks great, pretty sure that's it.

Should the 3 logging integration projects also get the new netstandard1.5 target to stay in-sync with Castle.Core?

.NET Standard versions of dependencies:

  • log4net - 1.3
  • NLog - 1.3, 1.5, 2.0
  • Serilog - 1.0, 1.3

Do you know what happens if a user picks NLog and is on a platform where NuGet could choose .NET Standard 1.5/2.0 but we only have a 1.3, .NET Standard is obviously additive, but if NuGet picked a higher platform it would add members/types etc that could break us depending on it. This will probably determine if we should add it to these too.

Also, it seems that Mono's C# compiler (mcs) does not yet know C# 7.2 features. Both the in Castle.Core.Tests.csproj as well as the unit tests added in this PR should be hidden from Mono. I'm not exactly sure how to do this properly.

This seems to be a general issue with the build process, and therefore unrelated to this PR.

I disagree that it is unrelated to this pull request, this pull request merged would break the build.

Yes, Mono now ships Roslyn as its default compiler (csc) even though it still ships mcs. Since we are still using Mono 4.6.1 (30 Sep 2016) I think we should upgrade it first, it is likely that a new version of the compiler has been shipped with a newer Mono version.

// that was introduced with C# language version 7.2.
[TestFixture]
public class ValueTypeReferenceSemanticsTestCase : BasePEVerifyTestCase
{

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Indentation mix up here.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed. Sorry for that.

Comment thread CHANGELOG.md Outdated
Enhancements:
- Added .NET Standard/.NET Core support for NLog (@snakefoot, #200)
- Added .NET Standard/.NET Core support for log4net (@snakefoot, #201)
- Add .NET Standard 1.5 as additional target to NuGet package. This adds support for `in` parameter modifiers on e.g. .NET Core (@stakx, #339)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could to clarify the changelog entry so it is clear this wasn't a problem on .NET Framework. Thanks.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I rewrote the changelog entry as follows:

DynamicProxy supported C# in parameter modifiers only on the .NET Framework up until now. Adding .NET Standard 1.5 as an additional target to the NuGet package makes them work on .NET Core, too (@stakx, #339)

Is that OK?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yep

@jonorossi jonorossi added this to the vNext milestone Apr 24, 2018
stakx added 3 commits April 24, 2018 23:08
The `in` modifier on parameters that was introduced with C# 7.2 gets
encoded as a modreq. Because .NET Standard 1.3 (the sole `netstandard`
TFM currently targeted by Castle Core) does not support emitting
custom modifiers in IL, we couldn't support proxying methods with such
an `in` modifier.

However we can support this scenario by adding `netstandard1.5` as a
TFM to Castle Core: .NET Standard 1.5 supports emitting modreqs in IL.
@stakx
stakx force-pushed the valuetype-ref-semantics branch 2 times, most recently from 280941d to 369516e Compare April 24, 2018 21:34
 * Rewrite changelog entry so it's clear that `in` parameter modifiers
   already worked on the .NET Framework, and that only support for
   .NET Core is being added.

 * Fix indentation.
@stakx
stakx force-pushed the valuetype-ref-semantics branch 4 times, most recently from ed1c9d2 to fe6ef2b Compare April 24, 2018 22:16
@stakx

stakx commented Apr 24, 2018 •

Copy link
Copy Markdown
Member Author
CSC : error CS1617: Invalid option '7.2' for /langversion; must be ISO-1, ISO-2, Default
or an integer in range 1 to 6.
[/home/travis/build/castleproject/Core/src/Castle.Core.Tests/Castle.Core.Tests.csproj]

Trial and error suggests this is caused by an outdated .NET Core SDK version (1.0.4). So .travis.yml to the rescue. Let's try...

dotnet: 2.0.3

With this, only C# language versions up to 7.1 will be supported. But we need 7.2.

dotnet: 2.1.105

With this, we're good to go with C# 7.2. But we get two new problems:

  • It no longer installs .NET Core Runtime 1.1. .travis.yml to the rescue once more:

    install:
        - sudo apt-get install dotnet-sharedframework-microsoft.netcore.app-1.1.6
    
  • Executing .NET Framework 4.6.1 tests suddenly doesn't work anymore (Permission denied):

    --------------------
    Running NET461 Tests
    --------------------
    ./build.sh: line 50: ./src/Castle.Core.Tests/bin/Release/net461/Castle.Core.Tests.exe: Permission denied
    ./build.sh: line 51: ./src/Castle.Core.Tests.WeakNamed/bin/Release/net461/Castle.Core.Tests.WeakNamed.exe: Permission denied
    

    I don't know where that problem came from, nor how to resolve it... would simply preceding these commands with mono possibly help?

Dear gods... the joys of modern .NET. 🦆 🏜

@stakx
stakx force-pushed the valuetype-ref-semantics branch 2 times, most recently from 8f8efc5 to bb89f3a Compare April 24, 2018 23:46
@jonorossi

Copy link
Copy Markdown
Member

Executing .NET Framework 4.6.1 tests suddenly doesn't work anymore (Permission denied):

I don't know where that problem came from, nor how to resolve it... would simply preceding these commands with mono possibly help?

Possibly if binfmt isn't set up anymore after changing the Travis settings. Sounds like a good change anyway.

@stakx

stakx commented Apr 25, 2018

Copy link
Copy Markdown
Member Author

Joy! Prepending mono to the commands that invoke an .exe indeed worked. 🎆

@stakx

stakx commented Apr 25, 2018 •

Copy link
Copy Markdown
Member Author

There's still this open question from you:

Should the 3 logging integration projects also get the new netstandard1.5 target to stay in-sync with Castle.Core?

.NET Standard versions of dependencies:

  • log4net - 1.3
  • NLog - 1.3, 1.5, 2.0
  • Serilog - 1.0, 1.3

Do you know what happens if a user picks NLog and is on a platform where NuGet could choose .NET Standard 1.5/2.0 but we only have a 1.3, .NET Standard is obviously additive, but if NuGet picked a higher platform it would add members/types etc that could break us depending on it. This will probably determine if we should add it to these too.

I don't know as of now. I'll probably need to run a few experiments later on.

@stakx

stakx commented Apr 25, 2018 •

Copy link
Copy Markdown
Member Author

Do you know what happens if a user picks NLog and is on a platform where NuGet could choose .NET Standard 1.5/2.0 but we only have a 1.3, .NET Standard is obviously additive, but if NuGet picked a higher platform it would add members/types etc that could break us depending on it. This will probably determine if we should add it to these too.

I don't know as of now. I'll probably need to run a few experiments later on.

TL;DR: While we might be on the safer side by adding netstandard1.5 to the logging packages, I suspect that it wouldn't make any difference in practice.

I ran two quick experiments:


(1) What if the logging packages didn't target netstandard1.5? (status quo)

  • Created a BaseLibrary NuGet that targets both .NET Standard 1.3 and .NET Standard 1.5. (This is the equivalent to Castle.Core.)
  • Created a DependentLibrary NuGet that depends on BaseLibrary, but targets only .NET Standard 1.3. (This is the equivalent of e.g. Castle.Core-NLog.)
  • A console app Consumer that depends on DependentLibrary and runs on .NET Framework 4.6.2 (which implements .NET Standard 1.5).

In this case, this is what gets loaded when running Consumer:

  • BaseLibrary, .NET Standard 1.5 version. (!)
  • DependentLibrary, .NET Standard 1.3 version (as there is no other).

(2) What if the logging packages additionally targeted netstandard1.5? (considered change)

Same setup as (1), but DependentLibrary (aka Castle.Core-NLog) targets both .NET Standard 1.3 and .NET Standard 1.5.

In this case, this is what gets loaded when running Consumer:

  • BaseLibrary, .NET Standard 1.5 version.
  • DependentLibrary, .NET Standard 1.5 version.

In both cases, the version of BaseLibrary (aka Castle.Core) that targets .NET Standard 1.5 got chosen, supposedly because that's what Consumer's platform (.NET Framework 4.6.2) supports.

This would suggest that there's no point in adding a netstandard1.5 TFM to the logging packages, because the presence or absence of that TFM won't influence which Castle.Core target will get picked.

Disclaimer: Obviously, the .NET tooling being what it currently is, YMMV... I simply don't have a thorough-enough understanding of the target/version resolution algorithm of msbuild / dotnet / nuget. I'd be happy if someone could validate my above reasoning. /cc @Fir3pho3nixx

@jonorossi

Copy link
Copy Markdown
Member

In both cases, the version of BaseLibrary (aka Castle.Core) that targets .NET Standard 1.5 got chosen, supposedly because that's what Consumer's platform (.NET Framework 4.6.2) supports.

This would suggest that there's no point in adding a netstandard1.5 TFM to the logging packages, because the presence or absence of that TFM won't influence which Castle.Core target will get picked.

That is what I thought would happen, it is expected that newer .NET Standard versions won't make breaking changes and the IL generated when compiling against lower .NET Standard versions will always be compatible even if new members appear in a higher .NET Standard compatible assembly.

@jonorossi
jonorossi merged commit 7ef5e62 into castleproject:master May 2, 2018
@jonorossi

Copy link
Copy Markdown
Member

Squished and merged the changes. Thanks @stakx.

@stakx
stakx deleted the valuetype-ref-semantics branch May 2, 2018 09:27
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.

2 participants