Roslyn Scripting APIs for Blazor WebAssembly
- Dominant language
- C#
- Stars
- 20.7k
- Forks
- 4.3k
- PR merge metrics
- PR metrics pending
Description
**Version Used**: Roslyn 4.10.0; .NET 8.0; Visual Studio 2022
**Steps to Reproduce**:
1. Create a Blazor WebAssembly project (with the default Visual Studio template)
2. Inside Counter.razor, change the IncrementCount() method to the following:
```cs
_ = CSharpScript.RunAsync("1 + 2").GetAwaiter().GetResult();
currentCount++;
```
3. Run the Blazor WebAssembly application, navigate to the Counter and click on the button
Counter.razor file to reproduce:
```cs
@using Microsoft.CodeAnalysis.CSharp.Scripting
@page "/counter"
Counter
Counter
Current count: @currentCount
Click me
@code {
private int currentCount = 0;
private void IncrementCount()
{
_ = CSharpScript.RunAsync("1 + 2").GetAwaiter().GetResult();
currentCount++;
}
}
```
**Expected Behavior**:
The C# script, "1 + 2", should evaluate without any issues.
**Actual Behavior**:
Instead, the following exception is thrown:
```
System.NotSupportedException: Can't create a metadata reference to an assembly without location.
at Microsoft.CodeAnalysis.MetadataReference.CreateFromAssemblyInternal(Assembly assembly, MetadataReferenceProperties properties, DocumentationProvider documentation)
at Microsoft.CodeAnalysis.MetadataReference.CreateFromAssemblyInternal(Assembly assembly)
```
**Note**: There is a [similar issue](https://github.com/dotnet/roslyn/issues/71371) created about half a year ago, but it did not receive response or attention.
Contributor guide
Assessment
This issue has not been assessed yet.