Код: Выделить всё
[SupportedOSPlatform("browser")] // suppress CA1416 "only supported on: 'browser'"
public static partial class Code
{
[JSExport]
public static string NameOf([JSMarshalAs] object entity)
=> ((IHasName)entity).Name;
}
Код: Выделить всё
import { DictionaryOfInt32_String } from 'csharp'; // generated TypeScript
let dict = DictionaryOfInt32_String.new(7); // .NET dictionary, capacity 7
dict.set(7, "se7en"); // dict[7] = "se7en";
console.log(dict.get(7));
Код: Выделить всё
net8.0
true
enable
true
obj/generated
...
net8.0
true
enable
проект WebAssembly требует метод Main() для предотвращения этой ошибки:
Программа не содержит статического метода Main, подходящего для точки входа
(Я не только не вызываю Main(), но даже не мог понять, как его вызвать.) Но если я добавлю метод Main() в оба проекта, возникнет следующая ошибка:
C:\Program Files\dotnet\sdk\9.0.305\Sdks\Microsoft.NET.Sdk.StaticWebAssets\targets\Microsoft.NET.Sdk.StaticWebAssets.targets(616,5): ошибка: конфликтующие ресурсы с одинаковым целевым путем «_framework/blazor.boot.json». Для ресурсов Identity: C:\Dev\MyApp\Server\MyAppWasm\bin\Debug\net8.0\wwwroot_framework\blazor.boot.json, SourceType: Computed, SourceId: MyAppWasm, ContentRoot: C:\Dev\MyApp\Server\MyAppWasm\bin\Debug\net8.0\wwwroot, BasePath: /, RelativePath: _framework/blazor.boot.json, AssetKind: Build, AssetMode: All, AssetRole: Primary, AssetRole: , AssetRole: , linkedAsset: , AssetTraitName: WasmResource, AssetTraitValue: манифест, Fingerprint: fmiu3i5gfl, Integrity: OYuLu5ui6DeTmqCHsz8viTMsr9s2gps4W8mqrbYrE4w=, FileLength: 22689, LastWriteTime: 05.11.2025 4:27:23 +00:00, CopyToOutputDirectory: PreserveNewest, CopyToPublishDirectory: Никогда, OriginalItemSpec: obj\Debug\net8.0\blazor.boot.json" и "Идентификация: C:\Dev\MyApp\Server\JSMarshalerWasm\bin\Debug\net8.0\wwwroot_framework\blazor.boot.json, SourceType: Project, SourceId: JSMarshalerWasm, ContentRoot: C:\Dev\MyApp\Server\JSMarshalerWasm\bin\Debug\net8.0\wwwroot, BasePath: /, RelativePath: _framework/blazor.boot.json, AssetKind: Build, AssetMode: All, AssetRole: Primary, AssetRole: , AssetRole: , linkedAsset: , AssetTraitName: WasmResource, AssetTraitValue: манифест, отпечаток пальца: qpeekuqssc, целостность: /q1cS1sIQjh1Us8LmqZQEEOpnikjG+LDv6FJZIMtp+U=, FileLength: 17475, LastWriteTime: 05.11.2025 4:26:53 +00:00, CopyToOutputDirectory: PreserveNewest, CopyToPublishDirectory: Never, OriginalItemSpec: obj\Debug\net8.0\blazor.boot.json' из разных проектов.
Поэтому вместо этого я использовал Microsoft.NET.Sdk, но тогда атрибуты JSExport в Marshaler не работают:
Код: Выделить всё
import { dotnet } from '_framework/dotnet.js';
...
...
const { setModuleImports, getAssemblyExports, getConfig, runMain } = await dotnet
.withApplicationArguments('start')
.create();
const config = getConfig();
DotNetExports = await getAssemblyExports(config.mainAssemblyName);
// RUNTIME ERROR:
// TypeError: can't access property "Marshaler", DotNetExports.JSMarshaling is undefined
Marshaler = DotNetExports.JSMarshaling.Marshaler;
Подробнее здесь: https://stackoverflow.com/questions/798 ... e-webc-app
Мобильная версия