簡體   English   中英

.net 5 - Signalr - 消息包 - lz4 - 錯誤:無法找到 ext 類型 98

[英].net 5 - Signalr - Messagepack - lz4 - Error: unable to find ext type 98

在啟用 lz4BlockArray 壓縮后,使用 angular 客戶端在 .net 核心 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 庫自述文件

MessagePackCompression 有兩種模式,Lz4Block 和 Lz4BlockArray。 也不是簡單的二進制 LZ4 壓縮,而是集成到序列化管道中的特殊壓縮,使用 MessagePack ext 代碼(Lz4BlockArray (98) 或 Lz4Block (99))。 因此,它不容易與其他語言提供的壓縮兼容。

重要的部分是最后一句話,其他語言可能不兼容。 在這種情況下,Angular 客戶端使用的 MessagePack 庫不支持這些 ext 代碼進行壓縮。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM