我尝试为我的 Android 项目提供 WebAssembly 功能v8 7.2。我已成功导入v8为静态库。但我遇到了一个问题,WebAssembly 既没有调用then也没有catch回调。下面是我的代码:
std::unique_ptr<v8::Platform> platform;
v8::Isolate *isolate;
v8::Persistent<v8::Context> persistentContext;
void runMain();
void runScript();
void _log(const v8::FunctionCallbackInfo<v8::Value>& info) {
v8::String::Utf8Value utf(isolate, info[0].As<v8::String>());
__android_log_print(ANDROID_LOG_DEBUG, "V8Native", "%s",*utf);
}
void JNICALL
Java_com_hustunique_v8demoapplication_MainActivity_initV8(JNIEnv *env, jobject /* this */) {
// Initialize V8.
v8::V8::InitializeICU();
platform = v8::platform::NewDefaultPlatform();
v8::V8::InitializePlatform(&(*platform.get()));
v8::V8::Initialize();
runMain();
}
void runMain() {
// Create a new Isolate and make it the current one.
v8::Isolate::CreateParams create_params;
create_params.array_buffer_allocator = v8::ArrayBuffer::Allocator::NewDefaultAllocator();
isolate = v8::Isolate::New(create_params);
// …Run Code Online (Sandbox Code Playgroud) 我的任务是运行 CLI 命令(在客户端系统中)并在 Web 应用程序上向用户显示输出。[假设,一个基于网络的 cmd.exe ]
基于对 WebAssembly 功能的了解,我使用 .NET CORE Blazor WebAssembly 来完成该任务。但是在客户端中使用System.Diagnostics.ProcessStartInfo会引发运行时错误Native error= Cannot find the specified file。
如果我对 WebAssembly 的理解有误,请告诉我。另外,建议我如何完成任务?
Razor 页面中使用的代码:
protected override async Task OnInitializedAsync()
{
quiz = await Http.GetJsonAsync<List<QuizItem>>("Quiz");
// My actual code...
string process = @"C:\Windows\System32\cmd.exe", arguments = "start", workingFolder = ".";
System.Diagnostics.ProcessStartInfo startinfo = new System.Diagnostics.ProcessStartInfo {
FileName = process, Arguments = arguments, WorkingDirectory = workingFolder,
CreateNoWindow = false, UseShellExecute = false,
RedirectStandardError = true, RedirectStandardOutput …Run Code Online (Sandbox Code Playgroud) 在开发过程中,我在 Blazor WebAssembly 应用程序的服务器端使用了 Swagger。始终使用 kestrel 而不是 IIS Express 启动(调试)。路由按预期工作,我的所有组件都正确路由,如果我手动输入 /swagger,我就会进入 swagger 页面。都好。
我们已经在预生产服务器上的 IIS 下部署,服务器端和 Blazor WebAssembly 应用程序(客户端)按预期工作并且可用,但是,我的 /swagger url 被重写(我假设)以转到我的应用程序中的某个位置,而不是让它转到 Swagger,显然没有任何组件可以响应 /swagger。
我唯一的猜测是,当托管在 IIS 上时,aspnet core 应用程序负责告诉 IIS 重写什么以及如何重写(类似于可以通过 web.config 提供的“独立”部署的配置。)
我找不到如何指定异常,我一直在关注 https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/blazor/web assembly?view=aspnetcore- 上的文档3.1#iis
知道如何为 /swagger 添加例外吗?
编辑:
事实证明,它在 Chrome 中运行没有问题,只有 Firefox 出现了不需要的行为。如果我清除缓存或使用隐身模式,则 Firefox 中不会出现此问题。因此,Firefox 似乎缓存了一些内容,并尝试将我的 URL 输入发送到 Blazor Wasm,而不是通过服务器。我将使用开发工具和打开的 fiddler 进行更多调试,尝试找出答案,然后进行报告。
我目前正在开发 .NET Standard 2.1 Blazor WebAssembly 应用程序。我尝试将不同的 appsettings.{Environment}.json 配置加载到我的 Window 命名空间 (JavaScript) 中。
因此,我按照这篇博文进行操作:
https://jkdev.me/blazor-appsettings/
到目前为止一切顺利:我在我的 wwwroot 目录中添加了 3 个 appsettings.*.json 文件:
应用程序设置.json:
{
"App": {
"Message": "Hello World!"
}
}
Run Code Online (Sandbox Code Playgroud)
appsettings.Development.json:
{
"App": {
"Environment": "Development"
}
}
Run Code Online (Sandbox Code Playgroud)
appsettings.Staging.json:
{
"App": {
"Environment": "Staging"
}
}
Run Code Online (Sandbox Code Playgroud)
在我的 program.cs Main 方法中,我构建了新的配置设置,如下所示:
public class Program
{
public static async Task Main(string[] args)
{
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("app");
ConfigureServices(builder.Services);
await builder.Build().RunAsync();
}
private static void ConfigureServices(IServiceCollection services)
{
services.AddSingleton(
provider => …Run Code Online (Sandbox Code Playgroud) 我定义了一个元组结构:
pub struct ChangedCell(pub bool, pub u32, pub u32);
Run Code Online (Sandbox Code Playgroud)
我的假设
ChangedCell重 9 个字节(bool:1 个字节,u32:4 个字节,u32:4 个字节)
我做了什么
我向 JavaScript返回了一个pointer, lengthfor :Vec<ChangedCell>
pub struct ChangedCell(pub bool, pub u32, pub u32);
Run Code Online (Sandbox Code Playgroud)
const arr = new Uint8Array(memory.buffer, pointer, length * 9);
Run Code Online (Sandbox Code Playgroud)
预期行为
isVal成为valid [byte]val1成为valid [byte] * 4val2成为valid [byte] * 4问题
I am getting Garbage values!
如何将这样的内容读入 JavaScript 中?
我一直在寻找 WASM 中发生的错误来解决此错误:
Newtonsoft.Json.JsonSerializationException: Unable to find a constructor to use for type Hqub.MusicBrainz.API.Entities.Recording.
A class should either have a default constructor, one constructor with arguments or a constructor marked with the JsonConstructor attribute. Path 'recordings[0].id', line 1, position 86.
Run Code Online (Sandbox Code Playgroud)
我目前拥有的最好的线索是这篇关于 Xamarin for Android 使用的 Mono 运行时的旧博客文章: ,其中指出:
在项目属性的“Android 选项”选项卡中,有一个“链接器”选项卡。“链接”下拉列表中选定的选项是“仅限 Sdk 程序集”还是“Sdk 和用户程序集”?
如果是后者,则在链接时会跳过无参数构造函数,因为未检测到任何使用。因此将其更改为“Sdk Assemblies only”。
我尝试切换到 System.Text.Json,这会导致类似的错误:
System.NotSupportedException: Deserialization of reference types without parameterless constructor is not supported. Type 'Hqub.MusicBrainz.API.Entities.Recording'
at System.Text.Json.ThrowHelper.ThrowNotSupportedException_DeserializeCreateObjectDelegateIsNull (System.Type invalidType) <0x4b45408 + 0x0004e> in …Run Code Online (Sandbox Code Playgroud) 目标是将最新的稳定GSL编译为Web 程序集并使其可作为Node.js使用模块使用。
受emscripten 手册这一部分的启发,我尝试了以下过程:
git clone git://git.savannah.gnu.org/gsl.git
cd gsl
git checkout tags/release-2-6
autoreconf -i
emconfigure ./configure
emmake make
Run Code Online (Sandbox Code Playgroud)
不幸的是,我得到了多个wasm-ld: error: duplicate symbol.
但是编译 GSL (make ) 工作得很好。
我在用emsdk version 2.0.16我在 Ubuntu 18.04 上
有谁知道如何解决这个问题?
非常感谢您的帮助。
我正在使用 Visual Studio 2019(版本 16.9.4)在 Razor 中构建一个 WebAssembly 项目,每当我尝试构建身份时,都会收到一条错误消息,指出包还原不起作用,并且所有内容都已回滚。
我的问题有两个:
格茨,
伊德·斯诺克
在我使用的 .razor 文件中
@inject HttpClient Http
Run Code Online (Sandbox Code Playgroud)
访问 HTTPClient。
有没有办法在 .cs 文件中执行相同的操作,或者我是否必须将其作为参数传递?
更新
我以为我有,但我没有。
使用语句
@inject HttpClient Http
Run Code Online (Sandbox Code Playgroud)
定义为类参数
using System.Net.Http;
using Microsoft.AspNetCore.Components;
using System.Net.Http.Json;
Run Code Online (Sandbox Code Playgroud)
在我的通话任务中
[Inject]
protected HttpClient Http {get;set;}
Run Code Online (Sandbox Code Playgroud)
出现以下错误
Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
Unhandled exception rendering component: Value cannot be null. (Parameter 'client')
Run Code Online (Sandbox Code Playgroud) 对于网络服务器来说非常新:
我正在尝试配置我的 Web 服务器以将 WebAssemblies (编辑:.wasm)作为应用程序/wasm 提供服务,据我所知,我所在的 Hostinger 主机使用 Apache。我也在使用gzip
(编辑#3 该网页是 Unity“WebGL”构建,并且 WebAssemblies 正在流式传输)
(编辑#2)
这是我的 public_html .htaccess 文件:
# BEGIN LSCACHE
## LITESPEED WP CACHE PLUGIN - Do not edit the contents of this block! ##
<IfModule LiteSpeed>
RewriteEngine on
CacheLookup on
RewriteRule .* - [E=Cache-Control:no-autoflush]
RewriteRule \.litespeed_conf\.dat - [F,L]
### marker CACHE RESOURCE start ###
RewriteRule wp-content/.*/[^/]*(responsive|css|js|dynamic|loader|fonts)\.php - [E=cache-control:max-age=3600]
### marker CACHE RESOURCE end ###
### marker FAVICON start ###
RewriteRule favicon\.ico$ - [E=cache-control:max-age=86400]
### marker …Run Code Online (Sandbox Code Playgroud) webassembly ×10
blazor ×5
asp.net-core ×2
c# ×2
javascript ×2
linker ×2
.net-core ×1
apache ×1
asp.net ×1
c ×1
c++ ×1
embedded-v8 ×1
emscripten ×1
gsl ×1
gzipstream ×1
iis ×1
json.net ×1
mime-types ×1
razor ×1
rust ×1
uno-platform ×1
v8 ×1
wasm-bindgen ×1
webserver ×1