|
| 1 | +--- |
| 2 | +title: "Breaking change: Asterisk no longer accepted for assembly name attributes" |
| 3 | +description: Learn about the breaking change in core .NET libraries in .NET 7 where assembly names no longer accept '*' as a wildcard attribute value. |
| 4 | +ms.date: 11/25/2024 |
| 5 | +ai-usage: ai-assisted |
| 6 | +ms.custom: https://github.com/dotnet/docs/issues/42598 |
| 7 | +--- |
| 8 | + |
| 9 | +# Asterisk no longer accepted for assembly name attributes |
| 10 | + |
| 11 | +Prior to .NET 7, assembly names allowed specifying `*` as a wildcard value for an attribute value, which was equivalent to not specifying the value at all. This undocumented feature was removed in .NET 7. |
| 12 | + |
| 13 | +## Version introduced |
| 14 | + |
| 15 | +.NET 7 |
| 16 | + |
| 17 | +## Previous behavior |
| 18 | + |
| 19 | +Previously, you could specify `*` as a value for assembly name attributes. For example, the following code succeeded: |
| 20 | + |
| 21 | +```csharp |
| 22 | +Assembly.Load("System.Runtime, Version=*, PublicKeyToken=*"); |
| 23 | +``` |
| 24 | + |
| 25 | +The asterisk had identical behavior to not specifying the attribute value at all: |
| 26 | + |
| 27 | +```csharp |
| 28 | +Assembly.Load("System.Runtime"); |
| 29 | +``` |
| 30 | + |
| 31 | +## New behavior |
| 32 | + |
| 33 | +Starting in .NET 7, the following code fails with a <xref:System.IO.FileLoadException> with the error message "The given assembly name was invalid". |
| 34 | + |
| 35 | +```csharp |
| 36 | +Assembly.Load("System.Runtime, Version=*, PublicKeyToken=*") |
| 37 | +``` |
| 38 | + |
| 39 | +## Type of breaking change |
| 40 | + |
| 41 | +This change is a [behavioral change](../../categories.md#behavioral-change). |
| 42 | + |
| 43 | +## Reason for change |
| 44 | + |
| 45 | +The previous behavior was an undocumented feature and it wasn't consistent implemented by all .NET assembly name parsers. The undocumented feature was removed to unify the behavior of assembly name parsing throughout .NET. |
| 46 | + |
| 47 | +## Recommended action |
| 48 | + |
| 49 | +Omit assembly name attributes that have a wildcard value. For example, change `System.Runtime, Version=*` to just `System.Runtime`. |
| 50 | + |
| 51 | +## Affected APIs |
| 52 | + |
| 53 | +- <xref:System.Reflection.Assembly.Load(System.String)?displayProperty=fullName> |
| 54 | +- <xref:System.Type.GetType(System.String)?displayProperty=fullName> |
| 55 | +- <xref:System.Reflection.AssemblyName.%23ctor(System.String)?displayProperty=fullName> |
0 commit comments