Your project is now referencing a version of OpenSilver that is newer and contains many improvements but has some breaking changes which require migration of your project. To do that, simply follow the easy steps described below (or, alternatively, create a new project using the latest VSIX, which contains updated project templates).
Find <OpenSilverType>2</OpenSilverType> and replace it with <OpenSilverType>3</OpenSilverType>. If there is no <OpenSilverType> tag in your csproj, then follow these instructions at first.
using DotNetForHtml5;
using Microsoft.JSInterop;
using Microsoft.JSInterop.WebAssembly;
namespace YOUR_APP_NAMESPACE.Browser.Interop
{
public class UnmarshalledJavaScriptExecutionHandler : IJavaScriptExecutionHandler
{
private const string MethodName = "callJSUnmarshalled";
private readonly WebAssemblyJSRuntime _runtime;
public UnmarshalledJavaScriptExecutionHandler(IJSRuntime runtime)
{
_runtime = runtime as WebAssemblyJSRuntime;
}
public void ExecuteJavaScript(string javaScriptToExecute)
{
_runtime.InvokeUnmarshalled(MethodName, javaScriptToExecute);
}
public object ExecuteJavaScriptWithResult(string javaScriptToExecute)
{
return _runtime.InvokeUnmarshalled(MethodName, javaScriptToExecute);
}
}
}
Cshtml5Initializer.Initialize();
@page "/"
@using YOUR_APP_NAMESPACE.Browser.Interop;
@inject IJSRuntime JSRuntime;
@code{
protected override void OnInitialized()
{
base.OnInitialized();
Cshtml5Initializer.Initialize(new UnmarshalledJavaScriptExecutionHandler(JSRuntime));
Program.RunApplication();
}
}
using OpenSilver.Simulator;
using System;
namespace YOUR_APP_NAME.Simulator
{
static class Startup
{
[STAThread]
static int Main(string[] args)
{
return SimulatorLauncher.Start();
}
}
}
WinExe
net472
"..\..\..\..\YOUR_APP_NAME\bin\$(Configuration)\netstandard2.0\YOUR_APP_NAME.dll"
When you have completed the steps above, clear the cache of your browser and rebuild the solution.
Note: alternatively to the instructions above, you can create a new project using the latest VSIX, which contains updated project templates.
3.1 Go to Tools -> Options, then select Preview Features in Environment section.
3.2 Make sure to tick the “Use previews of the .NET SDK”
3.3 Restart Visual Studio
3.1 Replace <Project Sdk=”Microsoft.NET.Sdk.Web”> with <Project Sdk=”Microsoft.NET.Sdk.BlazorWebAssembly”> at the first line of the file.
3.2 Find the block
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<RazorLangVersion>3.0</RazorLangVersion>
</PropertyGroup>
and replace it with
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
3.3 Find the following lines
<PackageReference Include=”Microsoft.AspNetCore.Components.WebAssembly” Version=”3.2.0″ />
<PackageReference Include=”Microsoft.AspNetCore.Components.WebAssembly.Build” Version=”3.2.0″ />
<PackageReference Include=”Microsoft.AspNetCore.Components.WebAssembly.DevServer” Version=”3.2.0″ />
and replace them with
<PackageReference Include=”Microsoft.AspNetCore.Components.WebAssembly” Version=”6.0.0-preview.5.*” />
<PackageReference Include=”Microsoft.AspNetCore.Components.WebAssembly.DevServer” Version=”6.0.0-preview.5.*” PrivateAssets=”all” />
Replace the line
builder.Services.AddTransient(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
with
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
When you have completed the steps above, clear the cache of your browser and rebuild the solution.
If you have any questions, please contact us at: