Blazor WASM无法运行。找不到依赖的程序集。

huangapple go评论89阅读模式
英文:

Blazor WASM failing to run. Not finding dependent assemblies

问题

托管的 wasm 应用程序(wasm 客户端、托管服务器、共享项目)已经运行良好很长一段时间。最近它开始出现了运行问题。它将在处理程序主程序时失败,寻找依赖的程序集。我已经尽我所能去追踪问题的根本原因,而没有深入研究 aspnetcore webassembly 源代码。

浏览器控制台显示错误的程序集并不总是相同的。对于作为依赖的程序集的依赖项,我已经尝试从主项目引用它们,但没有任何区别。如果我查看浏览器缓存,我可以看到所有程序集的 dll 和 pdb 文件都已下载。我注意到的一件事是缓存中的程序集名称(以及 blazor.boot.json 中的名称)总是更改为全大写,而无法加载的程序集名称也随之更改。就好像服务器端的某些东西正在干扰程序集名称一样。它以大写名称下载到浏览器中。异常是找不到带有帕斯卡大小写的程序集。如果有人也想指导我在 github 存储库中的正确方向,服务器在哪里生成 blazor.boot.json 清单,以及在 webassembly 源代码中哪里使用清单,获取和加载程序集,我可以在源代码中查看是否有什么原因。

我可能会在存储库问题中发布这个,以防这是由最近的版本更改引起的。我知道有一段时间我在 7.0.5 运行时上,然后 VS 2022 更新了,同时也更新了 SDK,并将我转到了 7.0.9。似乎几乎不可能恢复版本,因为在 Windows 中的 SDK 安装与安装的 VS 版本相关联。

>System.IO.FileNotFoundException: 无法加载文件或程序集 'Dgc.External.Ui.BlazorWasm.Shared, Version=2023.7.14.2, Culture=neutral, PublicKeyToken=null' 或其依赖项。

Dgc.External.Ui.BlazorWasm.Shared 是客户端和服务器项目之间的共享类库项目

Blazor WASM无法运行。找不到依赖的程序集。

请注意,在浏览器缓存截图中,有一些程序集是大写的。有问题的程序集总是大写的

任何想法都会很有帮助。它在执行我的代码之前崩溃。我有一个 try/catch,但它甚至都没有进入那里。

更新:在进入客户端项目的 bin 文件夹后,有问题的程序集也是大写的。我不知道这些错误编译的来源是什么。如果我删除大写的程序集并重新构建项目,它们会变成正常大小写,并且项目会按预期工作。我尝试构建客户端项目,构建/运行服务器项目,并在运行时更改其中一个程序集,看看这些方法中是否有任何一个会导致错误的编译。到目前为止什么都没发生。如果有人对可能导致 VS/MSBuild 编译不正确的特定条件有任何想法,请告诉我,我可以进行测试。谢谢。

英文:

The hosted wasm app (wasm client, hosting server, shared project) has been working fine for a long time. Recently it started having issues running. It will fail processing the Program Main looking for dependent assemblies. I've tried as much as I can to track down the cause without digging through the aspnetcore webassembly source.

The assembly that the browser console shows an error for is not always the same. In the case of assemblies that are dependents of dependent assemblies, I've tried referencing those from the main project and it doesn't make a difference. If I look in the browser cache I can see all the assembly dlls and pdb files downloaded. The one thing I have noticed is the assembly name in cache (and in the blazor.boot.json) is ALWAYS changed to all uppercase for the assembly that is failing to load. It's as if something server side is messing with the assembly name. It gets downloaded to the browser with the uppercase name. The exception is it can't find the assembly with pascal cased name. If someone also wants to point me in the right direction on the github repo where the server generates the blazor.boot.json manifest and also the are in the webassembly source where the manifest is consumed, assemblies fetched and loaded, I could poke around through the source to see if something looks to be the cause.

I'll probably post this in the repo issues in case this was caused by a recent version change. I know for a while I was on the 7.0.5 runtime then VS 2022 updated along with the SDK and moved me to 7.0.9. It seems to be nearly impossible to revert versions as the SDK installation in windows is tied to the version of VS installed.

>System.IO.FileNotFoundException: Could not load file or assembly 'Dgc.External.Ui.BlazorWasm.Shared, Version=2023.7.14.2, Culture=neutral, PublicKeyToken=null' or one of its dependencies.

Where Dgc.External.Ui.BlazorWasm.Shared is the shared class library project between the client and server projects

Blazor WASM无法运行。找不到依赖的程序集。

Note in the browser cache screenshot, there are some assemblies Uppercased. The problem assemblies are ALWAYS uppercased

Any ideas would be helpful. It is crashing before the Program Main is executing my code currently. I have a try/catch that it is not even hitting there.

Update: After going into the client project bin folder the problem assemblies are also uppercase there as well. I don't know what the source of those bad compilations are. If I delete the uppercase assemblies and re-build the project they are normal cased and the project works as expected. I tried building the client project, building/running the server project and changing one of the assembiles while running to see if any of those methods cause a bad compile. Nothing happened so far. If anyone has any ideas on a certain condition that would cause VS/MSBuild to compile incorrectly, lmk and I can test. Thanks.

答案1

得分: 1

我在Blazor ASP.NET的Github上看到了你的帖子。我也遇到了相同的问题,并且已经在如何解决它方面进行了许多测试。(https://developercommunity.visualstudio.com/t/Blazor-Webassembly-published-assembly-fi/10423695)

似乎在重新构建或发布项目时出现了一个错误。在它被修复之前,我更改了以下VS2022选项:

打开VS2022选项 -> 转到项目和解决方案 -> 编译和运行 -> 更改第一个选项,"最大并行项目构建数"为1 -> 保存。

然后在重新构建之前,我清理整个项目(生成 -> 清理...)。然后它似乎又可以工作一段时间了。

在发布之前,我删除所有的 "bin" 和 "obj" 文件夹。然后它就能正确构建了。

英文:

I saw your post on the Blazor ASP.NET Github. I encountered the same behavior and I already tested a lot on how to cure it. (https://developercommunity.visualstudio.com/t/Blazor-Webassembly-published-assembly-fi/10423695)

It seems to be a bug when rebuilding or publishing a project. Until it's fixed, I changed the following VS2022 option:

Open VS2022 options -> go to Projects and Solutions -> Compile and run -> change the first option, "max number of parallel project builds" to 1 -> save.

Then before rebuilding again, I clean the whole project (Build -> clean ...). Then it seems to work for some time again.

Before publishing, I delete all "bin" and "obj" folders. Then it works to build correctly.

huangapple
  • 本文由 发表于 2023年7月28日 01:00:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/76781978.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定