Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -600,7 +600,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 @@ -42,6 +42,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
{
}
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>