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

mark all BinaryFormatter-related tests as conditional #103471

Merged
merged 5 commits into from
Jun 17, 2024

Conversation

adamsitnik
Copy link
Member

fixes #103406

…atformDetection.IsBinaryFormatterSupported to be true, fixes dotnet#103406
@adamsitnik adamsitnik added the binaryformatter-migration Issues related to the removal of BinaryFormatter and migrations away from it label Jun 14, 2024
@adamsitnik adamsitnik self-assigned this Jun 14, 2024
@dotnet-issue-labeler dotnet-issue-labeler bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Jun 14, 2024
@matouskozak
Copy link
Member

/azp run runtime-extra-platforms

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@adamsitnik
Copy link
Member Author

The following failure is related:

  Starting:    System.Resources.Extensions.BinaryFormat.Tests (parallel test collections = on [2 threads], stop on fail = off)
    System.Resources.Extensions.Tests.FormattedObject.SystemDrawingTests.Bitmap_RoundTrip(typeStyle: TypesWhenNeeded, assemblyMatching: Full) [FAIL]
      System.TypeInitializationException : The type initializer for 'System.Drawing.DrawingCom' threw an exception.
      ---- System.PlatformNotSupportedException : Operation is not supported on this platform.
      Stack Trace:
           at System.Drawing.Image.Save(Stream stream, ImageCodecInfo encoder, EncoderParameters encoderParams)
           at System.Drawing.Image.Save(MemoryStream stream)
           at System.Drawing.Image.System.Runtime.Serialization.ISerializable.GetObjectData(SerializationInfo si, StreamingContext context)

Once I've added ConditionalClass to the base class, the derived type annotation is no longer respected...

[ConditionalClass(typeof(PlatformDetection), nameof(PlatformDetection.IsBinaryFormatterSupported))]
public abstract class SerializationTest<TSerializer> where TSerializer : ISerializer

[ConditionalClass(typeof(PlatformDetection), nameof(PlatformDetection.IsDrawingSupported))]
public abstract class SystemDrawingTests<T> : SerializationTest<T> where T : ISerializer

@adamsitnik
Copy link
Member Author

/azp run runtime-extra-platforms

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@adamsitnik
Copy link
Member Author

Despite adding [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsDrawingSupported))] to Bitmap_RoundTrip I keep getting following error for Mono on Windows:

C:\h\w\AA92092E\w\B55809CF\e>"C:\h\w\AA92092E\p\dotnet.exe" exec --runtimeconfig System.Resources.Extensions.BinaryFormat.Tests.runtimeconfig.json --depsfile System.Resources.Extensions.BinaryFormat.Tests.deps.json xunit.console.dll System.Resources.Extensions.BinaryFormat.Tests.dll -xml testResults.xml -nologo -nocolor -notrait category=IgnoreForCI -notrait category=OuterLoop -notrait category=failing  
  Discovering: System.Resources.Extensions.BinaryFormat.Tests (method display = ClassAndMethod, method display options = None)
  Discovered:  System.Resources.Extensions.BinaryFormat.Tests (found 132 test cases)
  Starting:    System.Resources.Extensions.BinaryFormat.Tests (parallel test collections = on [2 threads], stop on fail = off)
    System.Resources.Extensions.Tests.FormattedObject.SystemDrawingTests.Bitmap_RoundTrip(typeStyle: TypesWhenNeeded, assemblyMatching: Full) [FAIL]
      System.TypeInitializationException : The type initializer for 'System.Drawing.DrawingCom' threw an exception.
      ---- System.PlatformNotSupportedException : Operation is not supported on this platform.
      Stack Trace:
           at System.Drawing.Image.Save(Stream stream, ImageCodecInfo encoder, EncoderParameters encoderParams)
           at System.Drawing.Image.Save(MemoryStream stream)
           at System.Drawing.Image.System.Runtime.Serialization.ISerializable.GetObjectData(SerializationInfo si, StreamingContext context)
        /_/src/libraries/System.Runtime.Serialization.Formatters/src/System/Runtime/Serialization/Formatters/Binary/BinaryObjectInfo.cs(113,0): at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitSerialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter, SerializationBinder binder)
        /_/src/libraries/System.Runtime.Serialization.Formatters/src/System/Runtime/Serialization/Formatters/Binary/BinaryObjectInfo.cs(74,0): at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.Serialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter, SerializationBinder binder)
        /_/src/libraries/System.Runtime.Serialization.Formatters/src/System/Runtime/Serialization/Formatters/Binary/BinaryObjectWriter.cs(87,0): at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Serialize(Object graph, BinaryFormatterWriter serWriter)
        /_/src/libraries/System.Runtime.Serialization.Formatters/src/System/Runtime/Serialization/Formatters/Binary/BinaryFormatter.Core.cs(83,0): at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph)
        /_/src/libraries/System.Resources.Extensions/tests/BinaryFormatTests/Common/ISerializer.cs(26,0): at System.Resources.Extensions.Tests.Common.ISerializer.Serialize(Object value, SerializationBinder binder, ISurrogateSelector surrogateSelector, FormatterTypeStyle typeStyle)
        /_/src/libraries/System.Resources.Extensions/tests/BinaryFormatTests/Common/SerializationTest.cs(34,0): at System.Resources.Extensions.Tests.Common.SerializationTest`1[[System.Resources.Extensions.Tests.FormattedObject.FormattedObjectSerializer, System.Resources.Extensions.BinaryFormat.Tests, Version=9.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51]].Serialize(Object value, SerializationBinder binder, ISurrogateSelector surrogateSelector, FormatterTypeStyle typeStyle)
        /_/src/libraries/System.Resources.Extensions/tests/BinaryFormatTests/Common/SerializationTest.cs(51,0): at System.Resources.Extensions.Tests.Common.SerializationTest`1[[System.Resources.Extensions.Tests.FormattedObject.FormattedObjectSerializer, System.Resources.Extensions.BinaryFormat.Tests, Version=9.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51]].RoundTrip[Bitmap](Bitmap value, SerializationBinder binder, ISurrogateSelector surrogateSelector, FormatterTypeStyle typeStyle, FormatterAssemblyStyle assemblyMatching)
        /_/src/libraries/System.Resources.Extensions/tests/BinaryFormatTests/Common/SystemDrawingTests.cs(20,0): at System.Resources.Extensions.Tests.Common.SystemDrawingTests`1[[System.Resources.Extensions.Tests.FormattedObject.FormattedObjectSerializer, System.Resources.Extensions.BinaryFormat.Tests, Version=9.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51]].Bitmap_RoundTrip(FormatterTypeStyle typeStyle, FormatterAssemblyStyle assemblyMatching)
        /_/src/mono/System.Private.CoreLib/src/System/Reflection/MethodBaseInvoker.Mono.cs(22,0): at System.Reflection.MethodBaseInvoker.InterpretedInvoke_Method(Object obj, IntPtr* args)
        /_/src/libraries/System.Private.CoreLib/src/System/Reflection/MethodBaseInvoker.cs(178,0): at System.Reflection.MethodBaseInvoker.InvokeDirectByRefWithFewArgs(Object obj, Span`1 copyOfArgs, BindingFlags invokeAttr)
        ----- Inner Stack Trace -----

full log

@akoeplinger @dotnet/area-system-drawing what am I missing?

@akoeplinger
Copy link
Member

IsDrawingSupported just checks that we're on Windows, but Mono doesn't support COM Interop which this is apparently trying to use. You can check for SupportsComInterop or IsBuiltInComEnabled

@adamsitnik
Copy link
Member Author

@akoeplinger thank you!!

@adamsitnik
Copy link
Member Author

/azp run runtime-extra-platforms

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@adamsitnik
Copy link
Member Author

There is another build failure that I am not sure how to solve:

log

  Xcode: /tmp/helix/working/96D20869/w/ADE9093D/e/apple_build/AppBundle/System.Resources.Extensions.Tests/System.Resources.Extensions.Tests.xcodeproj
  App: /tmp/helix/working/96D20869/w/ADE9093D/e/apple_build/AppBundle/System.Resources.Extensions.Tests/Release-appletvos/System.Resources.Extensions.Tests.app
  App moved to: /private/tmp/helix/working/96D20869/w/ADE9093D/e/System.Resources.Extensions.Tests.app/
/private/tmp/helix/working/96D20869/p/dotnet-cli/sdk/9.0.100-preview.5.24307.3/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.RuntimeIdentifierInference.targets(314,5): message NETSDK1057: You are using a preview version of .NET. See: https://aka.ms/dotnet-support-policy [/private/tmp/helix/working/96D20869/w/ADE9093D/e/publish/ProxyProjectForAOTOnHelix.proj]
/private/tmp/helix/working/96D20869/p/dotnet-cli/sdk/9.0.100-preview.5.24307.3/Microsoft.Common.CurrentVersion.targets(888,5): warning MSB3539: The value of the property "BaseIntermediateOutputPath" was modified after it was used by MSBuild which can lead to unexpected build results. Tools such as NuGet will write outputs to the path specified by the "MSBuildProjectExtensionsPath" instead. To set this property, you must do so before Microsoft.Common.props is imported, for example by using Directory.Build.props.  For more information, please visit https://go.microsoft.com/fwlink/?linkid=869650 [/private/tmp/helix/working/96D20869/w/ADE9093D/e/publish/ProxyProjectForAOTOnHelix.proj]
Signing bundle /tmp/helix/working/96D20869/w/ADE9093D/e/System.Resources.Extensions.Compat.Tests.app
No embedded provisioning profile found at /tmp/helix/working/96D20869/w/ADE9093D/e/System.Resources.Extensions.Compat.Tests.app/embedded.mobileprovision! Failed to sign the app!

Since the goal of System.Resources.Extensions.Compat.Tests is to just ensure that it's possible to enable BinaryFormatter and run the tests for it, we can simply disable the whole test projects for the mobile targets

@akoeplinger But how can I do that?

@simonrozsival
Copy link
Member

@adamsitnik you should be able to skip the whole test project by adding <ProjectExclusions> in src/libraries/tests.proj

@adamsitnik
Copy link
Member Author

/azp run runtime-extra-platforms

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@adamsitnik adamsitnik merged commit f1f2635 into dotnet:main Jun 17, 2024
116 of 122 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Jul 18, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
binaryformatter-migration Issues related to the removal of BinaryFormatter and migrations away from it needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[android][apple] BinaryFormatter serialization and deserialization not supported on mobile targets
4 participants