The version of OpenSilver that you are referencing (1.0.0-alpha-019 or newer) requires the migration of your project.

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).

1. Open the .CSPROJ of the project that has the “.Browser” suffix, and make the following changes:

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.

2. Add the folder “Interop” inside  project that has the “.Browser” suffix and add the file “UnmarshalledJavaScriptExecutionHandler.cs” inside the “Interop” folder with the following code (and make sure to replace YOUR_APP_NAMESPACE):

				
					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<string, object>(MethodName, javaScriptToExecute);
        }

        public object ExecuteJavaScriptWithResult(string javaScriptToExecute)
        {
            return _runtime.InvokeUnmarshalled<string, object>(MethodName, javaScriptToExecute);
        }
    }
}
				
			

3. Edit the file named “Program.cs” and delete the following line at the beginning of the method “Main”:

Cshtml5Initializer.Initialize();

4. Replace the content of “Pages/Index.razor” with the following code (and make sure to replace YOUR_APP_NAMESPACE):

				
					@page "/"
@using YOUR_APP_NAMESPACE.Browser.Interop;
@inject IJSRuntime JSRuntime;

@code{
    protected override void OnInitialized()
    {
        base.OnInitialized();

        Cshtml5Initializer.Initialize(new UnmarshalledJavaScriptExecutionHandler(JSRuntime));

        Program.RunApplication();
    }
}
				
			

5. In the project that has the “.Simulator” suffix, add a file named “Startup.cs” with the following content (and make sure to replace YOUR_APP_NAME):

 
				
					using OpenSilver.Simulator;
using System;

namespace YOUR_APP_NAME.Simulator
{
    static class Startup
    {
        [STAThread]
        static int Main(string[] args)
        {
            return SimulatorLauncher.Start();
        }
    }
}
				
			

6. Open the .CSPROJ of the project that has the “.Simulator” suffix, and replace its content with the following one (and make sure to replace YOUR_APP_NAME):

 
 
				
					<Project Sdk="Microsoft.NET.Sdk">

    <PropertyGroup>
        <OutputType>WinExe</OutputType>
        <TargetFramework>net472</TargetFramework>
        <StartArguments>"..\..\..\..\YOUR_APP_NAME\bin\$(Configuration)\netstandard2.0\YOUR_APP_NAME.dll"</StartArguments>
    </PropertyGroup>

    <ItemGroup>
        <PackageReference Include="OpenSilver.Simulator" Version="1.0.0-alpha-019" />
    </ItemGroup>

    <ItemGroup>
        <ProjectReference Include="..\YOUR_APP_NAME\YOUR_APP_NAME.csproj" />
    </ItemGroup>

</Project>
				
			

7. Remove the .csproj.user files from the .Browser and .Simulator projects, if any

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.

Also, you can migrate your project to .NET 6.0. To do that, simply follow the easy steps described below:

1. Update your Visual Studio 2019 to version 16.10.0 or newer. We recommend you to use Visual Studio Installer for this.

2. Install SDK 6.0.100-preview.5 or newer. You can download it here.

3. Enable support of Preview SDK in Visual Studio 2019:

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. Open the .CSPROJ of the project that has the “.Browser” suffix, and make the following changes:

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” />

4. Edit the file named “Program.cs”:

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.

Need help?

If you have any questions, please contact us at:

[email protected]

Shopping Basket