diff --git a/global.json b/global.json index faaa0a0e1b7d8..32d5acb2563d0 100644 --- a/global.json +++ b/global.json @@ -1,11 +1,11 @@ { "sdk": { - "version": "9.0.100-preview.6.24328.19", + "version": "9.0.100-preview.7.24407.12", "allowPrerelease": true, "rollForward": "major" }, "tools": { - "dotnet": "9.0.100-preview.6.24328.19" + "dotnet": "9.0.100-preview.7.24407.12" }, "msbuild-sdks": { "Microsoft.DotNet.Arcade.Sdk": "9.0.0-beta.24408.2", diff --git a/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/AmbientValueAttribute.cs b/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/AmbientValueAttribute.cs index ae52e7ebc9384..72dc418fc446a 100644 --- a/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/AmbientValueAttribute.cs +++ b/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/AmbientValueAttribute.cs @@ -18,6 +18,7 @@ public sealed class AmbientValueAttribute : Attribute /// This is the default value. /// private object? _value; + private static readonly object? s_throwSentinel = IDesignerHost.IsSupported ? null : new(); /// /// Initializes a new instance of the class, converting the @@ -32,6 +33,7 @@ public AmbientValueAttribute([DynamicallyAccessedMembers(DynamicallyAccessedMemb Debug.Assert(IDesignerHost.IsSupported, "Runtime instantiation of this attribute is not allowed with trimming."); if (!IDesignerHost.IsSupported) { + _value = s_throwSentinel; return; } @@ -142,7 +144,7 @@ public AmbientValueAttribute(object? value) public object? Value { get { - if (!IDesignerHost.IsSupported) + if (!IDesignerHost.IsSupported && ReferenceEquals(_value, s_throwSentinel)) { throw new ArgumentException(SR.RuntimeInstanceNotAllowed); } diff --git a/src/libraries/System.ComponentModel.TypeConverter/tests/AmbientValueAttributeTests.cs b/src/libraries/System.ComponentModel.TypeConverter/tests/AmbientValueAttributeTests.cs index 1773c5d5b6fa9..9af0e61f424e6 100644 --- a/src/libraries/System.ComponentModel.TypeConverter/tests/AmbientValueAttributeTests.cs +++ b/src/libraries/System.ComponentModel.TypeConverter/tests/AmbientValueAttributeTests.cs @@ -8,7 +8,9 @@ namespace System.ComponentModel.Tests { public class AmbientValueAttributeTests { - [Theory] + public static bool IDesignerHostIsSupported => AppContext.TryGetSwitch("System.ComponentModel.Design.IDesignerHost.IsSupported", out bool isSupported) ? isSupported : true; + + [ConditionalTheory(nameof(IDesignerHostIsSupported))] [InlineData(null, null, null)] [InlineData(typeof(int*), "1", null)] [InlineData(typeof(string), "1", "1")] diff --git a/src/libraries/System.ComponentModel.TypeConverter/tests/ToolboxItemAttributeTests.cs b/src/libraries/System.ComponentModel.TypeConverter/tests/ToolboxItemAttributeTests.cs index d073840ed06b6..9b8210b9235bd 100644 --- a/src/libraries/System.ComponentModel.TypeConverter/tests/ToolboxItemAttributeTests.cs +++ b/src/libraries/System.ComponentModel.TypeConverter/tests/ToolboxItemAttributeTests.cs @@ -8,11 +8,19 @@ namespace System.ComponentModel { public class ToolboxItemAttributeTests { + internal static bool IDesignerHostIsSupported => AppContext.TryGetSwitch("System.ComponentModel.Design.IDesignerHost.IsSupported", out bool isSupported) ? isSupported : true; + [Theory] [InlineData(true)] [InlineData(false)] public void Ctor_Bool(bool defaultType) { + if (!IDesignerHostIsSupported && defaultType) + { + AssertExtensions.Throws(() => new ToolboxItemAttribute(defaultType)); + return; + } + var attribute = new ToolboxItemAttribute(defaultType); if (defaultType) { diff --git a/src/libraries/System.ObjectModel/tests/TrimmingTests/System.ObjectModel.TrimmingTests.proj b/src/libraries/System.ObjectModel/tests/TrimmingTests/System.ObjectModel.TrimmingTests.proj index da4a46f2ae141..2218182b4ab69 100644 --- a/src/libraries/System.ObjectModel/tests/TrimmingTests/System.ObjectModel.TrimmingTests.proj +++ b/src/libraries/System.ObjectModel/tests/TrimmingTests/System.ObjectModel.TrimmingTests.proj @@ -1,5 +1,15 @@ + + + _DefaultValueAttributeSupport + + + _DefaultValueAttributeSupport + + + + diff --git a/src/libraries/System.Private.Xml/tests/XmlSerializer/XmlSerializerTests.cs b/src/libraries/System.Private.Xml/tests/XmlSerializer/XmlSerializerTests.cs index 649f53108380c..44453deb7d003 100644 --- a/src/libraries/System.Private.Xml/tests/XmlSerializer/XmlSerializerTests.cs +++ b/src/libraries/System.Private.Xml/tests/XmlSerializer/XmlSerializerTests.cs @@ -43,6 +43,8 @@ static XmlSerializerTests() } #endif + public static bool DefaultValueAttributeIsSupported => AppContext.TryGetSwitch("System.ComponentModel.DefaultValueAttribute.IsSupported", out bool isEnabled) ? isEnabled : true; + [Fact] public static void Xml_TypeWithDateTimePropertyAsXmlTime() { @@ -823,7 +825,7 @@ public static void Xml_TypeWithTimeSpanProperty() Assert.StrictEqual(obj.TimeSpanProperty, deserializedObj.TimeSpanProperty); } - [Fact] + [ConditionalFact(nameof(DefaultValueAttributeIsSupported))] public static void Xml_TypeWithDefaultTimeSpanProperty() { var obj = new TypeWithDefaultTimeSpanProperty { TimeSpanProperty2 = new TimeSpan(0, 1, 0) }; @@ -868,7 +870,7 @@ public static void Xml_DeserializeEmptyTimeSpanType() } } - [Fact] + [ConditionalFact(nameof(DefaultValueAttributeIsSupported))] public static void Xml_TypeWithDateTimeOffsetProperty() { var now = new DateTimeOffset(DateTime.Now); @@ -893,7 +895,7 @@ public static void Xml_TypeWithDateTimeOffsetProperty() Assert.True(deserializedObj.NullableDTOWithDefault == null); } - [Fact] + [ConditionalFact(nameof(DefaultValueAttributeIsSupported))] public static void Xml_DeserializeTypeWithEmptyDateTimeOffsetProperties() { //var def = DateTimeOffset.Parse("3/17/1977 5:00:01 PM -05:00"); // "1977-03-17T17:00:01-05:00" diff --git a/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/ComponentModel/DefaultValueAttributeTests.cs b/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/ComponentModel/DefaultValueAttributeTests.cs index ba3f6a0882fab..641b74c940873 100644 --- a/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/ComponentModel/DefaultValueAttributeTests.cs +++ b/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/ComponentModel/DefaultValueAttributeTests.cs @@ -12,8 +12,10 @@ namespace System.ComponentModel.Tests { public class DefaultValueAttributeTests { + public static bool DefaultValueAttributeIsSupported => AppContext.TryGetSwitch("System.ComponentModel.DefaultValueAttribute.IsSupported", out bool isEnabled) ? isEnabled : true; + [Fact] - public static void Ctor() + public static void Ctor_value() { Assert.Equal((object)true, new DefaultValueAttribute(true).Value); Assert.Equal((object)false, new DefaultValueAttribute(false).Value); @@ -37,7 +39,11 @@ public static void Ctor() Assert.Equal("test", new DefaultValueAttribute("test").Value); Assert.Equal("test", new DefaultValueAttribute((object)"test").Value); + } + [ConditionalFact(nameof(DefaultValueAttributeIsSupported))] + public static void Ctor_type_string() + { Assert.Equal(DayOfWeek.Monday, new DefaultValueAttribute(typeof(DayOfWeek), "Monday").Value); Assert.Equal(TimeSpan.FromHours(1), new DefaultValueAttribute(typeof(TimeSpan), "1:00:00").Value); @@ -63,7 +69,7 @@ public class CustomType2 public int Value { get; set; } } - [Fact] + [ConditionalFact(nameof(DefaultValueAttributeIsSupported))] public static void Ctor_CustomTypeConverter() { TypeDescriptor.AddAttributes(typeof(CustomType), new TypeConverterAttribute(typeof(CustomConverter))); @@ -99,7 +105,7 @@ public void Ctor_TypeDescriptorNotFound_ExceptionFallback(Type type, bool return }, type.ToString(), returnNull.ToString(), stringToConvert, expectedValue.ToString()).Dispose(); } - [Theory] + [ConditionalTheory(nameof(DefaultValueAttributeIsSupported))] [InlineData(typeof(CustomType2))] [InlineData(typeof(DefaultValueAttribute))] public static void Ctor_DefaultTypeConverter_Null(Type type) diff --git a/src/libraries/System.Runtime/tests/System.Runtime.Tests/TrimmingTests/System.Runtime.TrimmingTests.proj b/src/libraries/System.Runtime/tests/System.Runtime.Tests/TrimmingTests/System.Runtime.TrimmingTests.proj index a5c28926b272f..ac7ab0c60226b 100644 --- a/src/libraries/System.Runtime/tests/System.Runtime.Tests/TrimmingTests/System.Runtime.TrimmingTests.proj +++ b/src/libraries/System.Runtime/tests/System.Runtime.Tests/TrimmingTests/System.Runtime.TrimmingTests.proj @@ -24,7 +24,9 @@ DebuggerSupport - + + _DefaultValueAttributeSupport + diff --git a/src/mono/sample/wasm/blazor-frame/blazor.csproj b/src/mono/sample/wasm/blazor-frame/blazor.csproj index 1de3023c4e481..f8f3a377bf8ce 100644 --- a/src/mono/sample/wasm/blazor-frame/blazor.csproj +++ b/src/mono/sample/wasm/blazor-frame/blazor.csproj @@ -11,8 +11,8 @@ - - + + diff --git a/src/mono/wasm/testassets/WasmOnAspNetCore/AspNetCoreServer/AspNetCoreServer.csproj b/src/mono/wasm/testassets/WasmOnAspNetCore/AspNetCoreServer/AspNetCoreServer.csproj index 3d0fa0a57f9a7..cb89a36cf488b 100644 --- a/src/mono/wasm/testassets/WasmOnAspNetCore/AspNetCoreServer/AspNetCoreServer.csproj +++ b/src/mono/wasm/testassets/WasmOnAspNetCore/AspNetCoreServer/AspNetCoreServer.csproj @@ -10,7 +10,7 @@ - + diff --git a/src/mono/wasm/testassets/WasmOnAspNetCore/BlazorClient/BlazorClient.csproj b/src/mono/wasm/testassets/WasmOnAspNetCore/BlazorClient/BlazorClient.csproj index b3535d0b965ab..1150699756bae 100644 --- a/src/mono/wasm/testassets/WasmOnAspNetCore/BlazorClient/BlazorClient.csproj +++ b/src/mono/wasm/testassets/WasmOnAspNetCore/BlazorClient/BlazorClient.csproj @@ -12,8 +12,8 @@ - - + + diff --git a/src/mono/wasm/testassets/WasmOnAspNetCore/Shared/Shared.csproj b/src/mono/wasm/testassets/WasmOnAspNetCore/Shared/Shared.csproj index 968e48496a1e8..0da5e2ce3bebc 100644 --- a/src/mono/wasm/testassets/WasmOnAspNetCore/Shared/Shared.csproj +++ b/src/mono/wasm/testassets/WasmOnAspNetCore/Shared/Shared.csproj @@ -10,7 +10,7 @@ - - + +