今天在asp.net core站點上做一個發送郵件附帶二維碼的功能,爲了方便郵件接受者直接手機掃描打開特定h5頁面。採用QRCoder,代碼很簡單幾行
QRCodeGenerator qrGenerator = new QRCodeGenerator();
QRCodeData qrCodeData = qrGenerator.CreateQrCode(content, QRCodeGenerator.ECCLevel.Q);
Base64QRCode qrCode = new Base64QRCode(qrCodeData);
return qrCode.GetGraphic(5);
返回二維碼的base64格式,嵌入img中顯示,運行->測試,一切順利。 提交代碼,生成鏡像更新到站點,同樣的路徑走一遍,發現收到的郵件中沒有圖片。檢查日誌發現
An unhandled exception has occurred while executing the request.
System.TypeInitializationException: The type initializer for 'Gdip' threw an exception. ---> System.DllNotFoundException: Unable to load shared library 'libdl' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: liblibdl: cannot open shared object file: No such file or directory
at Interop.Libdl.dlopen(String fileName, Int32 flag)
at System.Drawing.SafeNativeMethods.Gdip.LoadNativeLibrary()
在github早有前人提交過同樣的問題,解決方法是在生成鏡像時安裝缺失的包
FROM microsoft/aspnetcore:2.0 AS base
RUN apt-get update && apt-get install -y apt-utils libgdiplus libc6-dev
重新生成測試通過。
因爲安裝包的緣故,整個鏡像生成時間將近20分鐘,我就順便做了一個包含安裝包的基礎鏡像,這樣方便後續更新
docker push wyxnj/aspnetcore:latest
用這個作爲asp.net core runtime的基礎鏡像,可以和以前一樣快速生成鏡像並更新站點。