Lỗi có dạng thông báo như sau :
Could not load file or assembly '*******' or one of its dependencies. An attempt was made to load a program with an incorrect format.Thứ Ba, 21 tháng 11, 2023
[ASP.NET] Could not load file or assembly '*******' or one of its dependencies. An attempt was made to load a program with an incorrect format.
Thứ Năm, 21 tháng 9, 2023
[MSSQL] Lỗi không start được sau khi update
Sau khi update SQL mà bị lỗi không start lại được dịch vụ, kiểm tra log SQL có báo lỗi liên quan đến database master
Script level upgrade for database 'master' failed because upgrade step 'u_tables.sql' encountered error 25641, state 0, severity 16. This is a serious error condition which might interfere with regular operation and the database will be taken offline. If the error happened during upgrade of the 'master' database, it will prevent the entire SQL Server instance from starting. Examine the previous errorlog entries for errors, take the appropriate corrective actions and re-start the database so that the script upgrade steps run to completion.
Để start lại được SQL thì càn thêm biến /T902 để khi start SQL sẽ bỏ qua script update
net start mssql$instancename /T902
Hoặc khai báo tham số này trong SQL Configuration Manager
Thứ Ba, 22 tháng 11, 2022
[ASP.NET CORE] Các tình huống lỗi cơ bản
Support website .NET Core cơ bản
1. Lỗi không start được process .net : Mã lỗi sẽ là 502 , thường do thiếu quyền. Nếu site build dạng .exe thì cần set pool network service (do policy trên server), nếu site build file .dll thì có thể kiểm tra quyên thư mục c:/program file/dotnet , có quyền read theo user psacln và network services, nếu bị cái này thì sẽ bị toàn server.
Một nguyên nhân khác còn do source nên không start được web app. Có thể kiểm tra web app có start ok không thì check trực tiếp từ server:
- đối vói file .exe thì gọi chạy file exe đó từ CMD.
- đối với file .dll thì chạy CMD, sau chạy lênh : dotnet <đường dẫn file .dll>
Nếu start ok thì sẽ có thông tin như hình dưới , vd : Now listening on : http://localhost:xxxx
2. Các lỗi 500 chung chung, có thể bật error log trên web.config. stdoutLogEnabled="true" stdoutLogFile=".logsstdout" . lưu ý thư mục khai báo tại stdoutLogFile phải tồn tại mới ghi log được. Trường hợp này chỉ ghi log khi mà webapp chạy và IIS handle request được.
Một cách khác để check có thể chạy web app từ local như bước số 1 trên, nếu có lỗi cũng sẽ thể hiện ra màn hình
3. Trường hợp web app test chạy ok từ local server nhưng truy cập bên ngoài vẫn không được. một trong những trường hợp phổ biến là webapp Khách khai báo port cố định. phải bỏ khai báo port cố định đi để IIS lấy port random.
HTTP Error 500.0 - ANCM In-Process Handler Load Failure : Đây cũng là lỗi liên quan tới port. cụ thể trong web.config sẽ có khai báo hostingModel="InProcess" , khi này thì trên server sẽ chỉ chạy được 1 site có khai báo như vậy, nếu có site thứ 2 khai báo như vậy thì sẽ lỗi.
Cách khắc phục là yêu cầu KH bỏ khai báo hostingModel="InProcess" đi, hoặc set thành hostingModel="OutOfProcess". Hoặc set pool riêng cho site.
Out-of-process hosting model
For out-of-process hosting with IIS, CreateDefaultBuilder configures Kestrel server as the web server and enables IIS Integration by configuring the base path and port for the ASP.NET Core Module.
The ASP.NET Core Module generates a dynamic port to assign to the backend process.
4. Update các lỗi liên quan tới khai báo hostingModel mã nguồn .NET Core và hướng xử lý.
hostingModel là 1 thông số được khai báo trong web.config thuộc thẻ <aspNetCore ...>
hostingModel Có 2 thuộc tính như sau
- inprocess : sẽ chạy dựa vào process w3wp.exe của IIS. đặc thù là mỗi 1 pool chỉ được phép 1 site chạy như vậy.
- OutOfProcess : sẽ chạy dựa vào process dotnet.exe (hoặc process theo tên khách build), 1 pool có thể chạy nhiều site OutOfProcess. IIS lúc này đóng vai trò như proxy.
- HTTP Error 500.0 - ANCM In-Process Handler Load Failure
nguyên nhân : không start được dotnet core dạng inprocess, liên quan tới quyền của pool
xử lý : chuyển sang pool network services, hoặc chuyển sang OutOfProcess
- HTTP Error 500.30 - ASP.NET Core app failed to start
Kiểm tra : chạy lệnh (CMD) vẫn hoạt động bình thường
nguyên nhân : có thể do pool đang enable 32bit. Bị với mã nguồn umbraco
xử lý : Set 32bit application fale cho pool
- HTTP Error 500.34 - ANCM Mixed Hosting Models Not Supported
nguyên nhân : trong 1 pool vừa có site chạy inprocess vừa có site chạy outofprocess
xử lý : tách site chạy inprocess sang pool riêng, hoặc chuyển hết sang OutOfProcess
-HTTP Error 500.35 - ANCM Multiple In-Process Applications in same Process
nguyên nhân : trong cùng 1 pool mà có 2 web dotnet core đang set inprocess
xử lý : tách site inprocess sang pool riêng, hoặc phải chuyển hết sang OutOfProcess
-HTTP Error 500.36 ANCM Out-Of-Process Handler Load Failure
nguyên nhân : không start được kestrel thường do dll bị lỗi
xử lý : cài lại .net core
-HTTP Error 502.5 Process Failure
nguyên nhân : không start được process dotnet.
xử lý : Kiểm tra quyền thực thi đối với user web cho thư mục c:/Program File/dotnet . Kiểm tra quyền thực thi đối với user web cho file .exe của .net nếu code build dạng file exe
- HTTP Error 502.5 - ANCM Out-Of-Process Startup Failure
nguyên nhân : giống cái trên, do process donet build theo dạng file .exe chứ không phải file .dll nên không chạy được (do policy). VD khai báo trong web.config: <aspNetCore processPath=".\Gene.exe" ...>
xử lý : Chuyển pool sang network service indentity. Nếu pool riêng và chỉ có 1 site thì có thể chuyển về hostingModel = "inprocess"
*** hostingModel = "inprocess" hay hostingModel = "OutOfProcess" có 1 số ý nghĩa khác nhau trong lập trình. Tuy nhiên phần lớn website không có yêu cầu đặc biệt thì sử dụng cái nào cũng được. Do đó đối với hosting thì hướng xử lý khi gặp các case lỗi trên là kiểm tra set hostingModel = "OutOfProcess" . Một số trường hợp phải sử dụng InProcess thì sẽ set dedicate pool cho site để chạy
5. Một cách đơn giản để các bạn kiểm tra khai báo hostingModel trước và sau khi cấu hình.
Nếu website đang chạy. có thể dùng trình duyệt F12 và check header thông số server. Nếu kết quả là Kestrel thì site đang chạy hostingModel là "OutOfProcess", ngược lại server là InProcess. Sau khi config cho KH xong cũng có thể dùng cách này để xác minh lại chạy đúng chưa.
Thứ Năm, 22 tháng 9, 2022
[ASP.NET] Lỗi kết nối Database (A network-related or instance-specific...) mặc dù kiểm tra mọi thứ đã đúng
Tình huống :
Website đã config đúng thông số kết nói database (ConnectString) đồng thời kiểm tra kết nối DB đều OK, thậm chí khi monitor website truy cập vẫn có log kết nối DB thành công vào con SQL. Tuy nhiên website vẫn bị báo lỗi
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified).
Nguyên nhân :
- Vì 1 số lý do gì đó website sử dụng cả khai báo connectionString mặc định của .NET Framework (được khai báo trong file C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config\machine.config)
Xử lý :
- Trong khai báo connectionString của website thêm thẻ <clear /> vào
<connectionStrings>
<clear />
Thứ Năm, 14 tháng 10, 2021
[ASP.NET][IIS] Error CS0016: Could not write to output file ....
Lỗi liên quan tới compiler csc của .NET Framework
Compiler Error Message: CS0016: Could not write to output file 'c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\3ab7b770\3750c939\en-US\App_GlobalResources.l8frv07t.resources.dll' -- 'Access is denied. '
Thứ Năm, 9 tháng 9, 2021
[ASP.NET][MSSQL] Web ASP truy vấn SQL chậm qua network
Tình huống khi website asp.net truy cập chậm có liên quan đến truy vấn sql khi server web và server sql thuộc 2 server khác nhau
Quá trình kiểm tra lưu lượng network nếu sử dụng bandwidth nhiều mỗi lần có truy vấn database . Và kiểm tra Resource Waits trên SQL chỉ số Network I/O cao, có nghĩa là ứng dụng (application) không sử dụng hết lưu lượng dữ liệu mà SQL trả về, dẫn tới bị nghẽn cổ chai. mặc dù bandwidth network còn rất rộng và chưa sử dụng hết.
Để cải thiện, có thể kiểm tra cài đặt MARS trong ConnectionString.
MultipleActiveResultSets=True
Nếu có sử dụng thông số này thì bỏ đi hoặc set lại thành False.
Kếu quả Test thực tế trước và sau khi bỏ MultipleActiveResultSets : TTFB trang web giảm 1 nửa, bandwidth network tăng gấp đôi.
[ASP.NET] Xử lý lỗi Could not load file or assembly “*****” or one of its dependencies.
I. Lỗi Could not load file or assembly “*****” or one of its dependencies. Access is denied. ví dụ như ảnh dưới
Lỗi này là Access is denied nên không liên quan tới việc sai version. Nếu sai version khai báo trong code thì lỗi sẽ phải có nội dung như sau “The located assembly’s manifest definition does not match the assembly reference”
Access is denied : xảy ra do 1 số nguyên nhân sau.
- File dll bị lock truy cập, có thể kiểm tra process iis hoặc antivirus
- Thư mục ASP.NET Temp không có quyền ghi đối với user chạy web (lỗi này thường gặp hơn)
Thư mục ASP.NET Temp mặc định sẽ ở đường dẫn C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files
hoặc :
C:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files
Cần kiểm tra quyền write/read cho user chạy web (là user indentity của pool chứa website) cho thư mục ASP.NET Temp trên
Một số trường hợp thử mục ASP.NET Temp này sẽ được khai báo lại, không sử dụng thư mục mặc định của Window nữa. Ví dụ sử dụng Plesk Obsidian 18.x , xem trong web.config của site sẽ có mục khai báo như sau
<compilation tempDirectory=”D:\vhosts\aireal.vn\tmp” />
Với trường hợp này thì cần set quyền read/write cho user chạy web (là user indentity của pool chứa website) lên thư mục temp được khai báo trong web.config của website
II. Lỗi Could not load file or assembly ‘*****’ or one of its dependencies. The located assembly’s manifest definition does not match the assembly reference.
The located assembly’s manifest definition does not match the assembly reference : xảy ra do nguyên nhân là
- phiên bản (version) của file thư viên (dll) không khớp với khai báo trong web.config.
Lỗi này thường xảy ra khi update code mới nhưng quyên khai báo lại phiên bản thư viện cho đúng với file đang sử dụng.
Trường hợp lỗi này bắt buộc phải sửa lại khai báo trong web.config cho đúng mới chạy được
- Server không hỗ trợ thư viện mà Khách hàng sử dụng. Trường hợp này là những thư viện bắt buộc phải register vào registry của Window, đây là những loại thư viện bắt buộc phải setup trên server , ví dụ như thư viện của bộ ứng dụng văn phòng Office.
Could not load file or assembly ‘Microsoft.Office.Interop.Excel, Version=11.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c’ or one of its dependencies. The located assembly’s manifest definition does not match the assembly reference
III . Could not load file or assembly ‘**** or one of its dependencies. The system cannot find the file specified
The system cannot find the file specified : Xảy ra khi bị thiếu file thư viện. Nguyên nhân thường do khi upload source bị thiếu file, cần kiểm tra thông báo lỗi tên gì và đối chiếu với source xem có file đó tồn tại trong thư mục bin của source code hay không







