启用 lz4BlockArray 压缩后,使用 Angular 客户端在 .net core 5 解决方案中出现此错误。 如果没有压缩,一切似乎都工作得很好。 环顾四周寻找动力,但我一无所获。 似乎某些解码器未正确加载。
这是客户端错误,没有服务器端错误
Utils.js:208 [2020-12-01T09:01:42.527Z] Trace: (WebSockets transport) data received. Binary data of length 1086.
core.js:4352 ERROR Error: unable to find ext type 98
at decodeExt (decoder.js:432)
at tryDecode (decoder.js:266)
at decodeArray (decoder.js:338)
at tryDecode (decoder.js:288)
at decodeArray (decoder.js:338)
at tryDecode (decoder.js:288)
at decodeArray (decoder.js:338)
at tryDecode (decoder.js:288)
at Object.decode (decoder.js:103)
at MessagePackHubProtocol.push.jxpC.MessagePackHubProtocol.parseMessage (MessagePackHubProtocol.js:79)
重现
我的配置:
部分项目
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
<TypeScriptToolsVersion>Latest</TypeScriptToolsVersion>
<IsPackable>false</IsPackable>
<SpaRoot>ClientApp\</SpaRoot>
<DefaultItemExcludes>$(DefaultItemExcludes);$(SpaRoot)node_modules\**</DefaultItemExcludes>
<BuildServerSideRenderer>false</BuildServerSideRenderer>
<Configurations>Debug;Release;Development;DStaging;DProduction;Staging;Production</Configurations>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="HtmlSanitizer" Version="5.0.355" />
<PackageReference Include="IdentityModel" Version="4.5.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="5.0.0" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.Protocols.MessagePack" Version="5.0.0" />
<PackageReference Include="Microsoft.AspNetCore.SpaServices.Extensions" Version="5.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="5.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="5.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="5.0.0" />
<PackageReference Include="NLog.Targets.ElasticSearch" Version="7.5.0" />
<PackageReference Include="NLog.Web.AspNetCore" Version="4.9.3" />
</ItemGroup>
启动.cs
var resolver = CompositeResolver.Create(
DynamicEnumAsStringResolver.Instance,
StandardResolver.Instance
);
services.AddSignalR().AddMessagePackProtocol(
option =>
{
option.SerializerOptions =
MessagePackSerializerOptions.Standard.WithResolver(resolver)
.WithCompression(MessagePackCompression.Lz4BlockArray)
.WithSecurity(MessagePackSecurity.UntrustedData);
});
package.json
"@microsoft/signalr": "^5.0.0",
"@microsoft/signalr-protocol-msgpack": "^5.0.0",
连接
const builder = new HubConnectionBuilder();
// as per setup in the startup.cs
this._hubConnection = builder.withUrl('url', {
accessTokenFactory:
() => {
const token = sessionStorage.getItem('token');
return JSON.parse(token).access_token;
},
}).configureLogging(signalR.LogLevel.Trace).withAutomaticReconnect(new SignalrRetryPolicy()).withHubProtocol(new MessagePackHubProtocol()).build();
tsconfig
{
"compileOnSave": true,
"compilerOptions": {
"baseUrl": "./",
"downlevelIteration": true,
"module": "es2020",
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es2015",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2017",
"dom"
]
}
}
感谢您的帮助
最佳答案
来自.NET MessagePack libraries README
MessagePackCompression has two modes, Lz4Block and Lz4BlockArray. Neither is a simple binary LZ4 compression, but a special compression integrated into the serialization pipeline, using MessagePack ext code (Lz4BlockArray (98) or Lz4Block (99)). Therefore, it is not readily compatible with compression offered in other languages.
重要的是最后一句,其他语言可能不兼容。在这种情况下,Angular 客户端使用的 MessagePack 库不支持这些扩展代码进行压缩。
关于angular - .net 5 - 信号器 - 消息包 - lz4 - 错误 : unable to find ext type 98,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65087721/