Microsoft MVP성태의 닷넷 이야기
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일
 

(시리즈 글이 9개 있습니다.)
오류 유형: 51. Vista(UAC) + 웹 프로젝트 디버깅: System.UnauthorizedAccessException
; https://www.sysnet.pe.kr/2/0/563

오류 유형: 211. ASP.NET 응용 프로그램을 IIS Express에서 디버깅할 때 "Requested registry access is not allowed" 오류 발생
; https://www.sysnet.pe.kr/2/0/1593

오류 유형: 234. IIS Express에서 COM+ 사용 시 SecurityException - "Requested registry access is not allowed" 발생
; https://www.sysnet.pe.kr/2/0/1726

디버깅 기술: 186. C# - CacheDependency의 숨겨진 예외 - System.Web.HttpException
; https://www.sysnet.pe.kr/2/0/13239

디버깅 기술: 187. ASP.NET Web Application (.NET Framework) 프로젝트의 숨겨진 예외 - System.Web.HttpException
; https://www.sysnet.pe.kr/2/0/13240

디버깅 기술: 188. ASP.NET Web Application (.NET Framework) 프로젝트의 숨겨진 예외 - System.IO.FileNotFoundException
; https://www.sysnet.pe.kr/2/0/13241

디버깅 기술: 189. ASP.NET Web Application (.NET Framework) 프로젝트의 숨겨진 예외 - System.UnauthorizedAccessException
; https://www.sysnet.pe.kr/2/0/13242

오류 유형: 895. ASP.NET - System.Security.SecurityException: 'Requested registry access is not allowed.'
; https://www.sysnet.pe.kr/2/0/13559

오류 유형: 896. ASP.NET - .NET Framework 기본 예제에서 System.Web에 대한 System.IO.FileNotFoundException 예외 발생
; https://www.sysnet.pe.kr/2/0/13562




ASP.NET Web Application (.NET Framework) 프로젝트의 숨겨진 예외 - System.UnauthorizedAccessException

지난 글에 이어,

ASP.NET Web Application (.NET Framework) 프로젝트의 숨겨진 예외 - System.IO.FileNotFoundException
; https://www.sysnet.pe.kr/2/0/13241

ASP.NET Web Application (.NET Framework) 프로젝트의 숨겨진 예외 - System.Web.HttpException
; https://www.sysnet.pe.kr/2/0/13240

마찬가지로 숨겨진 예외가 하나 더 있는데 바로 System.UnauthorizedAccessException입니다.

System.UnauthorizedAccessException
  HResult=0x80070005
  Message=Access to the path 'C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\~AspAccessCheck_2e46d48344384.tmp' is denied.
  Source=mscorlib
  StackTrace:
   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) in f:\dd\ndp\clr\src\BCL\system\io\__error.cs:line 160

  This exception was originally thrown at this call stack:
    System.IO.__Error.WinIOError(int, string) in __error.cs

사실 이건 아주 오래된 문제입니다.

Vista(UAC) + 웹 프로젝트 디버깅: System.UnauthorizedAccessException
; https://www.sysnet.pe.kr/2/0/563

즉, "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files" 경로가 기본적으로는 일반 사용자 권한으로 접근할 수 없기 때문인데요, 위의 내용에 따라 Users에 "Modify" 권한을 추가하면 문제가 사라집니다.




애석하게도, 위의 예외를 해결하면 이제 "System.Globalization.CultureNotFoundException" 예외가 발생합니다.

System.Globalization.CultureNotFoundException
  HResult=0x80070057
  Message=Culture is not supported.
Parameter name: name
UserCache is an invalid culture identifier.
  Source=<Cannot evaluate the exception source>
  StackTrace:
<Cannot evaluate the exception stack trace>

  This exception was originally thrown at this call stack:
    System.Globalization.CultureInfo.CultureInfo(string, bool) in cultureinfo.cs

이때의 코드를 보면,

internal static CultureInfo CreateReadOnlyCultureInfo(string name)
{
    if (!_cultureCache.Contains(name))
    {
        lock (_cultureCache)
        {
            if (_cultureCache[name] == null)
            {
                _cultureCache[name] = CultureInfo.ReadOnly(new CultureInfo(name));
            }
        }
    }
    return (CultureInfo)_cultureCache[name];
}

name 인자의 값이 "UserCache"입니다. ^^; 실제로 이것은 "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files" 하위에 생성되는 디렉터리 이름입니다. 가령, 제가 만든 예제에서는 ".\vs\b391cbbb\7e17a152" 디렉터리가 생성되는데, 그 하위에 보면, "assembly", "hash", "UserCache" 디렉터리가 생성돼 있습니다.

그중에서 UserCache가 문제가 되는 이유는,

private void FindSatelliteDirectories()
{
    string[] directories = Directory.GetDirectories(_cacheDir); // assembly, hash, UserCache 반환
    string[] array = directories;
    foreach (string text in array)
    {
        string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(text);
        if (!(fileNameWithoutExtension == "assembly") && !(fileNameWithoutExtension == "hash") && System.Web.UI.Util.IsCultureName(fileNameWithoutExtension))
        {
            if (_satelliteDirectories == null)
            {
                _satelliteDirectories = new ArrayList();
            }
            _satelliteDirectories.Add(Path.Combine(_cacheDir, text));
        }
    }
}

저 조건에 "UserCache"가 없기 때문입니다. 따라서, 이걸 부드럽게 해결할 수 있는 방법은 없습니다. 단지, 우회 방법이 하나 있긴 한데요, UserCache 디렉터리는 Global.asax에 기본 코드로 제공되는 아래의 2개 코드 때문입니다.

AreaRegistration.RegisterAllAreas(); // MVC-AreaRegistrationTypeCache.xml 파일 생성
GlobalConfiguration.Configure(WebApiConfig.Register); // MVC-AreaRegistrationTypeCache.xml 파일 생성

어차피 이전 예외에서 "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files" 경로에 접근 권한이 없어 저 파일이 생성되지 않아도 동작에는 문제가 없었기 때문에 그냥 삭제해도 무방할 것입니다. 그래서 다음과 같이 코딩하면,

// ...[생략]...

namespace WebApplication1
{
    public class Global : HttpApplication
    {
        void Application_Start(object sender, EventArgs e)
        {
            // Code that runs on application startup
            AreaRegistration.RegisterAllAreas();
            GlobalConfiguration.Configure(WebApiConfig.Register);

#if DEBUG
            // IIS 8.0 – How is .NET Framework Temp Folder Path Generated?
            // https://robinding.medium.com/iis-8-0-how-is-net-framework-temp-folder-path-generated-bbf1170a9714
            string tempPath = System.Threading.Thread.GetDomain().DynamicDirectory;
            string userCachePath = Path.Combine(tempPath, "UserCache");
            Directory.Delete(userCachePath, true);
#endif

            // ...[생략]...
        }

    }
}

UserCache 디렉터리를 생성 후 곧바로 삭제하기 때문에 다음번 F5 실행 시 해당 디렉터리가 존재하지 않아 CultureNotFoundException 예외가 발생하지 않게 됩니다. 자, 이제 다음부터 발생하는 예외들은 사용자 코드로 인한 것이므로 꾸준히 잘 관리만 하신다면 숨겨진 예외로 인한 버그 발생을 줄일 수 있을 것입니다.




[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]







[최초 등록일: ]
[최종 수정일: 2/4/2023]

Creative Commons License
이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-변경금지 2.0 대한민국 라이센스에 따라 이용하실 수 있습니다.
by SeongTae Jeong, mailto:techsharer at outlook.com

비밀번호

댓글 작성자
 




1  2  3  4  5  6  7  8  9  [10]  11  12  13  14  15  ...
NoWriterDateCnt.TitleFile(s)
13693정성태7/24/20247233개발 환경 구성: 717. Visual Studio - C# 프로젝트에서 레지스트리에 등록하지 않은 COM 개체 참조 및 사용 방법파일 다운로드1
13692정성태7/24/20248012디버깅 기술: 199. Windbg - 리눅스에서 뜬 닷넷 응용 프로그램 덤프 파일에 포함된 DLL의 Export Directory 탐색
13691정성태7/23/20247370디버깅 기술: 198. Windbg - 스레드의 Win32 Message Queue 정보 조회
13690정성태7/23/20247005오류 유형: 919. Visual C++ 리눅스 프로젝트 - error : ‘u8’ was not declared in this scope
13689정성태7/22/20248511디버깅 기술: 197. Windbg - PE 포맷의 Export Directory 탐색
13688정성태7/21/20247615닷넷: 2281. C# - Lock / Wait 상태에서도 일부 Win32 메시지 처리파일 다운로드1
13687정성태7/19/20248045닷넷: 2280. C# - PostThreadMessage로 보낸 메시지를 Windows Forms에서 수신하는 방법파일 다운로드1
13686정성태7/19/20247842오류 유형: 918. Visual Studio - ATL Simple Object 추가 시 error C2065: 'IDR_...': undeclared identifier
13685정성태7/19/20247990스크립트: 66. Windows 디렉터리 경로를 WSL의 /mnt 포맷으로 구하는 방법 - 두 번째 이야기
13684정성태7/19/20248164닷넷: 2279. C# - 문자열 보간식 사례 (예: 조건 연산자 사용)
13683정성태7/18/20247637오류 유형: 917. ClrMD - Linux 환경의 .NET 5 덤프 분석 시 hang 현상
13682정성태7/18/20247854닷넷: 2278. WPF - 스레드에 종속되는 DependencyObject파일 다운로드1
13681정성태7/17/20247459닷넷: 2277. C# 13 - (2) 메서드 그룹의 자연 타입 개선 (메서드 추론 개선)파일 다운로드1
13680정성태7/16/20247838닷넷: 2276. C# - Method Group, Natural Type, function_type파일 다운로드1
13679정성태7/16/20246934Linux: 76. Linux - C++ (getaddrinfo 등을 담고 있는) libnss 정적 링크
13678정성태7/15/20247051VS.NET IDE: 191. Visual Studio 2022 - .NET 5 프로젝트를 Docker Support로 실행했을 때 오류
13677정성태7/15/20247132오류 유형: 916. MSBuild - CheckEolTargetFramework (warning NETSDK1138)
13676정성태7/14/20247315Linux: 75. gdb에서 glibc의 함수에 Breakpoint 걸기
13675정성태7/13/20249102C/C++: 166. C/C++ - DLL에서 template 함수를 export하는 방법 [1]파일 다운로드1
13674정성태7/13/20247986오류 유형: 915. Unhandled Exception: Microsoft.Diagnostics.NETCore.Client.ServerNotAvailableException: Unable to connect to Process
13673정성태7/11/20248427닷넷: 2275. C# 13 - (1) 신규 이스케이프 시퀀스 '\e'파일 다운로드1
13672정성태7/10/20247142닷넷: 2274. IIS - (프로세스 종료 없는) AppDomain Recycle
13671정성태7/10/20247260오류 유형: 914. Package ca-certificates is not installed.
13669정성태7/9/20247366오류 유형: 913. C# - AOT StaticExecutable 정적 링킹 시 빌드 오류
13668정성태7/8/20247393개발 환경 구성: 716. Hyper-V - Ubuntu 22.04 Generation 2 유형의 VM 설치
13667정성태7/7/20246608닷넷: 2273. C# - 리눅스 환경에서의 Hyper-V Socket 연동 (AF_VSOCK)파일 다운로드1
1  2  3  4  5  6  7  8  9  [10]  11  12  13  14  15  ...