Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Errors when getting started #155

Open
qwertie opened this issue May 19, 2024 · 6 comments
Open

Errors when getting started #155

qwertie opened this issue May 19, 2024 · 6 comments

Comments

@qwertie
Copy link

qwertie commented May 19, 2024

My first problem was that the JSInvokable attribute mentioned in the guide does not exist. I tried adding <PackageReference Include="Microsoft.JSInterop" Version="7.0.19" /> to my .NET 7 project, but this doesn't help and the Microsoft.JSInterop package has a yellow warning icon in the package list.

My second problem is this error when building:

error NETSDK1147: To build this project, the following workloads must be installed: wasm-tools-net7
error NETSDK1147: To install these workloads, run the following command: dotnet workload restore

dotnet workload restore says:

dotnet : Failed to restore workload for project C:\Dev\Barreleye\Server......Test.csproj: Failed to run MSBuild Target _GetRequiredWorkloads

This refers to a test project that I do not want to compile to Wasm, so I change the command to say

PM> dotnet workload restore --project .\[ProjectFolder]\[ProjectName].csproj

This appears to install various things (after demanding Administrator permissions), and says

Successfully installed workload(s) wasm-tools-net7.

but the Microsoft.JSInterop package icon is still yellow and the build fails with the same error:

error NETSDK1147: To build this project, the following workloads must be installed: wasm-tools-net7
error NETSDK1147: To install these workloads, run the following command: dotnet workload restore

If I remove the reference to Bootsharp, I get a different error instead:

I also tried upgrading to .NET 8, but it doesn't help; the error just changes to

error NETSDK1147: To build this project, the following workloads must be installed: wasm-tools
error NETSDK1147: To install these workloads, run the following command: dotnet workload restore

And again, the command above installs some things but it doesn't remove the error.

Since my project uses several other packages, I thought maybe those could be causing a problem, so I created a new empty project called DeleteMe. In the empty project I am able to use the JSInvokable attribute and the Microsoft.JSInterop package does not have a yellow warning icon, but adding <RuntimeIdentifier>browser-wasm</RuntimeIdentifier> causes the same error:

error NETSDK1147: To build this project, the following workloads must be installed: wasm-tools-net7
error NETSDK1147: To install these workloads, run the following command: dotnet workload restore

Again, dotnet workload restore --project .\DeleteMe\DeleteMe.csproj doesn't help. It doesn't seem to matter whether I reference Bootsharp or not. Any ideas how to fix this?

Finally, if Bootsharp is referenced and browser-wasm is not, then the error changes to

CSC : error CS5001: Program does not contain a static 'Main' method suitable for an entry point

Does Bootsharp require a Main()?

@qwertie
Copy link
Author

qwertie commented May 19, 2024

The recurring error stopped after I closed Visual Studio, started Visual Studio Installer, clicked Modify on VS 2022, clicked "ASP.NET and web development" (making sure it is checked), selected ".NET 7.0 WebAssembly Build Tools" and ".NET WebAssembly Build Tools", clicked Modify and waited...

IZD7e

The new project still does not build due to a Bootsharp-related error:

C:\Users\Family.nuget\packages\bootsharp\0.3.1\build\Bootsharp.targets(63,9): error MSB4062: The "Bootsharp.Publish.BootsharpEmit" task could not be loaded from the assembly C:\Users\Family.nuget\packages\bootsharp\0.3.1\build..//tasks/Bootsharp.Publish.dll. Could not load file or assembly 'System.Runtime, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified. Confirm that the declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask.

Note: since it mentions System.Runtime, Version=8.0, note that my project does have <TargetFramework>net8.0</TargetFramework>.

@elringus
Copy link
Owner

Min. supported .NET version is 8.0. Check any of the sample projects for reference. Regarding visual studio, see #137

@qwertie
Copy link
Author

qwertie commented May 19, 2024

Okay, dotnet build and dotnet publish work while Visual Studio won't build.

I'm puzzled that the output shows no signs of any wrapping/interop. For example, given this code

using Microsoft.JSInterop;

public class Program {
    public static void Main() { }

    [JSInvokable] public static string GetHello() => "hello there!!!!";
}

and this project

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
    <RuntimeIdentifier>browser-wasm</RuntimeIdentifier>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.JSInterop" Version="8.0.1" />
    <PackageReference Include="Bootsharp" Version="0.3.1" />
  </ItemGroup>
</Project>

I get 4 MB file called index.mjs, but there is no sign of Program or GetHello and the following code prints [ "boot", "exit", "getStatus", "BootStatus", "resources", "dotnet" ]:

import bootsharp from 'bootsharp/index.mjs';

bootsharp.boot().then(() => {
    console.log(bootsharp);
});

@elringus
Copy link
Owner

while Visual Studio won't build.

Please read the issue I've linked above.

there is no sign of Program or GetHello

Again, please, read the guide and/or check the samples. It should be import bootsharp, { Program, ...} from ....

@qwertie
Copy link
Author

qwertie commented May 24, 2024

Please read the issue I've linked above.

I did. That's why I said "Okay, dotnet build and dotnet publish work while Visual Studio won't build."

Again, please, read the guide and/or check the samples. It should be import bootsharp, { Program, ...} from ...

It's not only missing at runtime. There is no sign of Program anywhere. It cannot be imported.

@elringus
Copy link
Owner

Have you checked the samples? They're all working fine on my end.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants