.net 5 - Signalr - Messagepack - lz4 - Error: unable to find ext type 98
.net 5 - Signalr - Messagepack - lz4 - Error: unable to find ext type 98
启用 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>
Startup.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 库不支持这些分机代码进行压缩。
启用 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>
Startup.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 库不支持这些分机代码进行压缩。