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)
13853정성태12/26/20244782디버깅 기술: 213. Windbg - swapgs 명령어와 (Ring 0 커널 모드의) FS, GS Segment 레지스터
13852정성태12/25/20245877디버깅 기술: 212. Windbg - (Ring 3 사용자 모드의) FS, GS Segment 레지스터파일 다운로드1
13851정성태12/23/20245091디버깅 기술: 211. Windbg - 커널 모드 디버깅 상태에서 사용자 프로그램을 디버깅하는 방법
13850정성태12/23/20246193오류 유형: 940. "Application Information" 서비스를 중지한 경우, "This file does not have an app associated with it for performing this action."
13849정성태12/20/20246180디버깅 기술: 210. Windbg - 논리(가상) 주소를 Segmentation을 거쳐 선형 주소로 변경
13848정성태12/18/20245677디버깅 기술: 209. Windbg로 알아보는 Prototype PTE파일 다운로드2
13847정성태12/18/20245754오류 유형: 939. golang - 빌드 시 "unknown directive: toolchain" 오류 빌드 시 이런 오류가 발생한다면?
13846정성태12/17/20246296디버깅 기술: 208. Windbg로 알아보는 Trans/Soft PTE와 2가지 Page Fault 유형파일 다운로드1
13845정성태12/16/20245145디버깅 기술: 207. Windbg로 알아보는 PTE (_MMPTE)
13844정성태12/14/20246636디버깅 기술: 206. Windbg로 알아보는 PFN (_MMPFN)파일 다운로드1
13843정성태12/13/20245164오류 유형: 938. Docker container 내에서 빌드 시 error MSB3021: Unable to copy file "..." to "...". Access to the path '...' is denied.
13842정성태12/12/20245352디버깅 기술: 205. Windbg - KPCR, KPRCB
13841정성태12/11/20245950오류 유형: 937. error MSB4044: The "ValidateValidArchitecture" task was not given a value for the required parameter "RemoteTarget"
13840정성태12/11/20245250오류 유형: 936. msbuild - Your project file doesn't list 'win' as a "RuntimeIdentifier"
13839정성태12/11/20246149오류 유형: 936. msbuild - error CS1617: Invalid option '12.0' for /langversion. Use '/langversion:?' to list supported values.
13838정성태12/4/20245925오류 유형: 935. Windbg - Breakpoint 0's offset expression evaluation failed.
13837정성태12/3/20246738디버깅 기술: 204. Windbg - 윈도우 핸들 테이블 (3) - Windows 10 이상인 경우
13836정성태12/3/20245284디버깅 기술: 203. Windbg - x64 가상 주소를 물리 주소로 변환 (페이지 크기가 2MB인 경우)
13835정성태12/2/20246699오류 유형: 934. Azure - rm: cannot remove '...': Directory not empty
13834정성태11/29/20246693Windows: 275. C# - CUI 애플리케이션과 Console 윈도우 (Windows 10 미만의 Classic Console 모드인 경우) [1]파일 다운로드1
13833정성태11/29/20246060개발 환경 구성: 737. Azure Web App에서 Scale-out으로 늘어난 리눅스 인스턴스에 SSH 접속하는 방법
13832정성태11/27/20245685Windows: 274. Windows 7부터 도입한 conhost.exe
13831정성태11/27/20245046Linux: 111. eBPF - BPF_MAP_TYPE_PERF_EVENT_ARRAY, BPF_MAP_TYPE_RINGBUF에 대한 다양한 용어들
13830정성태11/25/20246553개발 환경 구성: 736. 파이썬 웹 앱을 Azure App Service에 배포하기
13829정성태11/25/20246652스크립트: 67. 파이썬 - Windows 버전에서 함께 설치되는 py.exe
13828정성태11/25/20245178개발 환경 구성: 735. Azure - 압축 파일을 이용한 web app 배포 시 디렉터리 구분이 안 되는 문제파일 다운로드1
1  2  3  4  [5]  6  7  8  9  10  11  12  13  14  15  ...