Skip to content

Commit

Permalink
[browser] Use whole assembly name when looking for already loaded ass…
Browse files Browse the repository at this point in the history
…emblies (dotnet#96018)
  • Loading branch information
maraf authored Jan 17, 2024
1 parent 6c9fbb4 commit f2c3541
Show file tree
Hide file tree
Showing 23 changed files with 33 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/mono/browser/runtime/lazyLoading.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export async function loadLazyAssembly(assemblyNameToLoad: string): Promise<bool
behavior: "assembly",
};

if (loaderHelpers.loadedAssemblies.some(f => f.includes(assemblyNameToLoad))) {
if (loaderHelpers.loadedAssemblies.includes(assemblyNameToLoad)) {
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion src/mono/browser/runtime/loader/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@ function download_resource(asset: AssetEntryInternal): LoadingResource {
totalResources.add(asset.name!);
response.response.then(() => {
if (asset.behavior == "assembly") {
loaderHelpers.loadedAssemblies.push(asset.resolvedUrl!);
loaderHelpers.loadedAssemblies.push(asset.name);
}

resourcesLoaded++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ protected void CopyTestAsset(string assetName, string generatedProjectNamePrefix

LogPath = Path.Combine(s_buildEnv.LogRootPath, Id);
Utils.DirectoryCopy(Path.Combine(BuildEnvironment.TestAssetsPath, assetName), Path.Combine(_projectDir!));

// WasmBasicTestApp consists of App + Library projects
if (assetName == "WasmBasicTestApp")
_projectDir = Path.Combine(_projectDir!, "App");
}

protected void BuildProject(string configuration)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@ public async Task FailOnMissingLazyAssembly()
BrowserQueryString: new Dictionary<string, string> { ["loadRequiredAssembly"] = "false" },
ExpectedExitCode: 1
));
Assert.True(result.ConsoleOutput.Any(m => m.Contains("Could not load file or assembly") && m.Contains("System.Text.Json")), "The lazy loading test didn't emit expected error message");
Assert.True(result.ConsoleOutput.Any(m => m.Contains("Could not load file or assembly") && m.Contains("Json")), "The lazy loading test didn't emit expected error message");
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Library;
using System;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Runtime.InteropServices.JavaScript;

public partial class LazyLoadingTest
Expand All @@ -16,11 +16,4 @@ public static void Run()
var text = JsonSerializer.Serialize(new Person("John", "Doe"), PersonJsonSerializerContext.Default.Person);
TestOutput.WriteLine(text);
}

public record Person(string FirstName, string LastName);

[JsonSerializable(typeof(Person))]
internal partial class PersonJsonSerializerContext : JsonSerializerContext
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
</PropertyGroup>

<ItemGroup>
<BlazorWebAssemblyLazyLoad Include="System.Text.Json$(WasmAssemblyExtension)" />
<ProjectReference Include="..\Library\Json.csproj" />
</ItemGroup>

<ItemGroup>
<BlazorWebAssemblyLazyLoad Include="Json$(WasmAssemblyExtension)" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ try {
break;
case "LazyLoadingTest":
if (params.get("loadRequiredAssembly") !== "false") {
await INTERNAL.loadLazyAssembly(`System.Text.Json${assemblyExtension}`);
await INTERNAL.loadLazyAssembly(`Json${assemblyExtension}`);
}
exports.LazyLoadingTest.Run();
exit(0);
Expand Down
11 changes: 11 additions & 0 deletions src/mono/wasm/testassets/WasmBasicTestApp/Library/Json.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Library;

public record Person(string FirstName, string LastName);

[JsonSerializable(typeof(Person))]
public partial class PersonJsonSerializerContext : JsonSerializerContext
{
}
8 changes: 8 additions & 0 deletions src/mono/wasm/testassets/WasmBasicTestApp/Library/Json.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<!-- The name of the assembly is important, one the lazy loading checks is that when System.Text.Json(.dll) is already loaded, we can lazy load Json(.dll) -->
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<OutputType>Library</OutputType>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
</Project>

0 comments on commit f2c3541

Please sign in to comment.