temp0
temp0
CC#
Created by temp0 on 4/10/2024 in #help
Using Roslyn in WebAssembly, error creating an AdHocWorkspace
Hello, this could be a really convoluted use case and I don't know what sort of support is expected to work here, although I've seen examples working in Blazor where people can create a Workspace, Project, Document, etc. from Roslyn. I am using a library called bootsharp (https://github.com/elringus/bootsharp) to compile a dotnet project to wasm, the easy stuff is working just fine, simple types/function invoking etc. My goal is to create a Roslyn workspace to be able to get completion data for the Monaco editor and I am trying to new up a Workspace with
var workspace = new AdhocWorkspace(MefHostServices.DefaultHost);
var workspace = new AdhocWorkspace(MefHostServices.DefaultHost);
And I am busting on what looks like some DI for a WorkspaceServiceMetadata service from the host. I am at the end of my debugging abilities and humbly ask for an outside opinion here. Am I out of my league, is there a way to get something like this working? Attached a stack trace of the managed side. The error is
"Error: The type 'WorkspaceServiceMetadata' cannot be used as a metadata view. A metadata view must be a concrete class with a parameterless or dictionary constructor.
"Error: The type 'WorkspaceServiceMetadata' cannot be used as a metadata view. A metadata view must be a concrete class with a parameterless or dictionary constructor.
1 replies
CC#
Created by temp0 on 3/18/2024 in #help
✅ Sharing executing Assembly in Roslyn script
Howdy, this could be a very specific use case, but if anyone has any insights here I would appreciate it: I am hosting am embedded .net runtime in a c++ app using nethost.h and loading my assembly and getting fn pointers with load_assembly_and_get_function_pointer. It's invoking everything fine. In the function I'm calling on the .net side I am using Roslyn to run .csx scripts. In that .net lib I define an interface INpcEvent and in the .csx I create a class that implements that interface and returns a new instance. I want to be able to get a reference to that new instance via this code: var scriptOptions = ScriptOptions.Default.WithReferences(Assembly.GetExecutingAssembly()); var state = await CSharpScript.RunAsync<GlobalType.INpcEvent>(text, scriptOptions, globals: global, globalsType: typeof(GlobalType)); And I get the error Exception thrown: 'System.ArgumentException' in System.Private.CoreLib.dll: 'Cannot bind to the target method because its signature is not compatible with that of the delegate type.' - seems to be that although they're the same types it's not the same assembly reference so it can't be cast as the return value. I see that Roslyn is loading that dll in runtime with the WithReferences option. Is there a way to use what I have defined in memory as the caller for types to sync those up?
13 replies