dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
15.18k stars 4.72k forks source link

[wasm] Cannot get location for a loaded assembly (`Assembly.Location`) #52062

Closed ddobric closed 2 years ago

ddobric commented 3 years ago

Hi all,

trying to evaluate the CSharp expression, that fails when adding reference. Following code fails at the first line:

var options = ScriptOptions.Default.AddReferences(typeof(TItem).Assembly);

Func<TItem, bool> discountFilterExpression = await CSharpScript.EvaluateAsync<Func<TItem, bool>>(this.Expression, options);

The error:

"Can't create a metadata reference to an assembly without location"

The same code works in a .NET 5 application. It fails when started in the Blazor web assembly standalone.

Project settings


<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">
  <PropertyGroup>
    <TargetFramework>net5.0</TargetFramework>
    <RuntimeIdentifier>browser-wasm</RuntimeIdentifier>
    <UseBlazorWebAssembly>true</UseBlazorWebAssembly>
    <!--<RazorLangVersion>3.0</RazorLangVersion>-->
  </PropertyGroup>
dotnet-issue-labeler[bot] commented 3 years ago

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

ghost commented 3 years ago

Tagging subscribers to this area: @CoffeeFlux See info in area-owners.md if you want to be subscribed.

Issue Details
Hi all, trying to evaluate the CSharp expression, that fails when adding reference. Following code fails at the first line: ``` var options = ScriptOptions.Default.AddReferences(typeof(TItem).Assembly); Func discountFilterExpression = await CSharpScript.EvaluateAsync>(this.Expression, options); ``` The error: `"Can't create a metadata reference to an assembly without location" ` The same code works in a .NET 5 application. It fails when started in the Blazor web assembly standalone. ### Project settings ``` net5.0 browser-wasm true ```
Author: ddobric
Assignees: -
Labels: `area-VM-meta-mono`, `untriaged`
Milestone: -
ghost commented 3 years ago

Tagging subscribers to 'arch-wasm': @lewing See info in area-owners.md if you want to be subscribed.

Issue Details
Hi all, trying to evaluate the CSharp expression, that fails when adding reference. Following code fails at the first line: ``` var options = ScriptOptions.Default.AddReferences(typeof(TItem).Assembly); Func discountFilterExpression = await CSharpScript.EvaluateAsync>(this.Expression, options); ``` The error: `"Can't create a metadata reference to an assembly without location" ` The same code works in a .NET 5 application. It fails when started in the Blazor web assembly standalone. ### Project settings ``` net5.0 browser-wasm true ```
Author: ddobric
Assignees: -
Labels: `arch-wasm`, `area-VM-meta-mono`, `untriaged`
Milestone: -
lewing commented 3 years ago

The assemblies you load at startup in the webassembly runtime don't have a location so you are hitting https://github.com/dotnet/roslyn/blob/315c2e149ba7889b0937d872274c33fcbfe9af5f/src/Compilers/Core/Portable/MetadataReference/MetadataReference.cs#L333

lewing commented 2 years ago

Like with SingleFile applications Assembly.Location is expected to be empty in this case so this is the expected behavior.