BlazorWasmPreRendering.Build: Publish fails when blazor app uses BlazorWasmAntivirusProtection Nuget in the project
Sometimes blazor apps dlls are flagged as false positive and blocked by firewalls or antiviruses. There is already an issue 36978 tracking this.
Meanwhile there is an another great library BlazorWasmAntivirusProtection which is used to overcome this false flagging of blazor apps by antivirus or firewall.
When we use this BlazorWasmAntivirusProtection library and try to prerender, publish fails!!!.
Here is the repo - BlazorWasmAVPrerender to replicate the issue.
Error log:
BlazorWasmAVPrerender -> /home/runner/work/BlazorWasmAVPrerender/BlazorWasmAVPrerender/dist/BlazorWasmAVPrerender/
Unhandled exception. System.Exception: Could not load the assembly "BlazorWasmAVPrerender" in search directories below.
/home/runner/work/BlazorWasmAVPrerender/BlazorWasmAVPrerender/dist/BlazorWasmAVPrerender/wwwroot/_framework
(pwd: /home/runner/work/BlazorWasmAVPrerender/BlazorWasmAVPrerender/BlazorWasmAVPrerender)
---> System.BadImageFormatException: Could not load file or assembly 'BlazorWasmAVPrerender, Culture=neutral, PublicKeyToken=null'. An attempt was made to load a program with an incorrect format.
File name: 'BlazorWasmAVPrerender, Culture=neutral, PublicKeyToken=null' ---> System.BadImageFormatException: Bad IL format.
at System.Runtime.Loader.AssemblyLoadContext.InternalLoad(ReadOnlySpan`1 arrAssembly, ReadOnlySpan`1 arrSymbols)
at System.Runtime.Loader.AssemblyLoadContext.LoadFromStream(Stream assembly, Stream assemblySymbols)
at System.Runtime.Loader.AssemblyLoadContext.LoadFromStream(Stream assembly)
at Toolbelt.Blazor.WebAssembly.PrerenderServer.CustomAssemblyLoader.LoadAssemblyFrom(String assemblyDir, String assemblyName) in C:\Projects\My\Blazor\BlazorWasmPreRendering.Build\BlazorWasmPreRendering.Build\CustomAssemblyLoader.cs:line 36
at Toolbelt.Blazor.WebAssembly.PrerenderServer.CustomAssemblyLoader.<>c__DisplayClass1_0.<.ctor>b__1(String dir) in C:\Projects\My\Blazor\BlazorWasmPreRendering.Build\BlazorWasmPreRendering.Build\CustomAssemblyLoader.cs:line 20
at System.Linq.Enumerable.SelectListIterator`2.MoveNext()
at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
at System.Linq.Enumerable.TryGetFirst[TSource](IEnumerable`1 source, Boolean& found)
at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source)
at Toolbelt.Blazor.WebAssembly.PrerenderServer.CustomAssemblyLoader.<.ctor>b__1_0(AssemblyLoadContext context, AssemblyName name) in C:\Projects\My\Blazor\BlazorWasmPreRendering.Build\BlazorWasmPreRendering.Build\CustomAssemblyLoader.cs:line 19
at System.Runtime.Loader.AssemblyLoadContext.GetFirstResolvedAssemblyFromResolvingEvent(AssemblyName assemblyName)
at System.Runtime.Loader.AssemblyLoadContext.ResolveUsingEvent(AssemblyName assemblyName)
at System.Runtime.Loader.AssemblyLoadContext.ResolveUsingResolvingEvent(IntPtr gchManagedAssemblyLoadContext, AssemblyName assemblyName)
at System.Reflection.RuntimeAssembly.InternalLoad(ObjectHandleOnStack assemblyName, ObjectHandleOnStack requestingAssembly, StackCrawlMarkHandle stackMark, Boolean throwOnFileNotFound, ObjectHandleOnStack assemblyLoadContext, ObjectHandleOnStack retAssembly)
at System.Reflection.RuntimeAssembly.InternalLoad(AssemblyName assemblyName, RuntimeAssembly requestingAssembly, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, AssemblyLoadContext assemblyLoadContext)
at System.Runtime.Loader.AssemblyLoadContext.LoadFromAssemblyName(AssemblyName assemblyName)
at Toolbelt.Blazor.WebAssembly.PrerenderServer.CustomAssemblyLoader.LoadAssembly(String assemblyName) in C:\Projects\My\Blazor\BlazorWasmPreRendering.Build\BlazorWasmPreRendering.Build\CustomAssemblyLoader.cs:line 49
--- End of inner exception stack trace ---
at Toolbelt.Blazor.WebAssembly.PrerenderServer.CustomAssemblyLoader.LoadAssembly(String assemblyName) in C:\Projects\My\Blazor\BlazorWasmPreRendering.Build\BlazorWasmPreRendering.Build\CustomAssemblyLoader.cs:line [55](https://github.com/fingers10/BlazorWasmAVPrerender/actions/runs/3374441807/jobs/5600065526#step:7:56)
at Toolbelt.Blazor.WebAssembly.PrerenderServer.Program.BuildPrerenderingOptions(CustomAssemblyLoader assemblyLoader, CommandLineOptions commandLineOptions) in C:\Projects\My\Blazor\BlazorWasmPreRendering.Build\BlazorWasmPreRendering.Build\Program.cs:line 103
at Toolbelt.Blazor.WebAssembly.PrerenderServer.Program.Main(String[] args) in C:\Projects\My\Blazor\BlazorWasmPreRendering.Build\BlazorWasmPreRendering.Build\Program.cs:line 28
at Toolbelt.Blazor.WebAssembly.PrerenderServer.Program.<Main>(String[] args)
Aborted (core dumped)
BlazorWasmAvPrerender GitHub Actions Link to check additional details if needed
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 1
- Comments: 22 (11 by maintainers)
@fingers10 Now the latest version of the “BlazorWasmPreRendering.Build” has supported lazy loading assemblies! 🎉
Could you check it out? and, thank you for giving me the big challenge that is adding support for lazy loading assemblies!
@jsakamoto Many thanks for your suggestions and guidance. This thread can be closed.
@fingers10 I could not reproduce the error with that I forked the “ILoveDotNet/ilovedotnet” repository, hard reset the
main
branch point to the commit 66c8265f, and re-run thegh-pages
workflow forcibly. (The log line is here)Moreover, the error you reported seems telling us that the reason of the error comes from the “BlazorWasmAntivirusProtection” package, not the “BlazorWasmPreRendering.Build” package.
I would like to recommend:
@jsakamoto salute to you. You are making a great solutions. You earned my respect a lot. I’ll check this and keep you posted
@fingers10 The latest version of the “BlazorWasmPreRendering.Build” has now supported the latest version of the “BlazorWasmAntivirusProtection”. Please check it out.
However, your sample project still failed because the project uses the “lazy assembly loading” feature of Blazor WebAssembly.
Again, the “BlazorWasmPreRendering.Build” depends on the pre-rendering feature of the Blazor Server. The “BlazorWasmPreRendering.Build” is implemented pre-rendering feature by making a Blazor WebAssembly app run as a Blazor Server app forcibly with some hacking. But these magics are not applicable for the “lazy assembly loading” feature because that feature is very specific on the client side running.
I’ll try to add support for the “lazy assembly loading” feature to the “BlazorWasmPreRendering.Build” later, but it must be very tough work, and please keep your mind that it might be impossible.
@fingers10 I’m currently investigating the revival problem. I’ll inform you the progress as soon as I can.
@jsakamoto Just confirmed. Prerendering is working with
BlazorWasmAntivirusProtection 1.9.0
without the work around in.csproj
file.@jsakamoto No worries. Yep I know that you are watching .NET Conf 22. I saw your question on C# required properties. Your question was too specific on adding required to property injection in blazor. Good question.
Back to this issue. I’ll validate this and get back.
@fingers10 Sorry too late since I was busy watching the .NET Conf 2022 that was held this week. (I live in Japan, so I had to wake up at midnight in the Japan Standard Time zone and keep staying up).
Yes, that’s right, it should work well even after removing that workaround. However, please remember that I’ve not verified it yet in my hand.
@fingers10 Hi,
Yes, I strongly agree with that your opinion. So, I created and sent a pull request to the author of the “BlazorWasmAntivirusProtection” to resolve this problem.
I hope the pull request above will be accepted and resolve the problem.
@jsakamoto , I tried the new package. Publish is successful. Here is the link.
However, I noticed two issues.
Navigation makes full page reload. Try clicking on any links in the link.
Counter button click not working.
@fingers10 Could you try out the ver.2.0.0-preview.4?