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

비밀번호

댓글 작성자
 




... 61  62  63  64  65  66  67  68  69  70  71  72  [73]  74  75  ...
NoWriterDateCnt.TitleFile(s)
12108정성태1/10/202017381오류 유형: 587. Kernel Driver 시작 시 127(The specified procedure could not be found.) 오류 메시지 발생
12107정성태1/10/202018517.NET Framework: 877. C# - 프로세스의 모든 핸들을 열람 - 두 번째 이야기
12106정성태1/8/202019596VC++: 136. C++ - OSR Driver Loader와 같은 Legacy 커널 드라이버 설치 프로그램 제작 [1]
12105정성태1/8/202018111디버깅 기술: 153. C# - PEB를 조작해 로드된 DLL을 숨기는 방법
12104정성태1/7/202019292DDK: 9. 커널 메모리를 읽고 쓰는 NT Legacy driver와 C# 클라이언트 프로그램 [4]
12103정성태1/7/202022388DDK: 8. Visual Studio 2019 + WDK Legacy Driver 제작- Hello World 예제 [1]파일 다운로드2
12102정성태1/6/202018763디버깅 기술: 152. User 권한(Ring 3)의 프로그램에서 _ETHREAD 주소(및 커널 메모리를 읽을 수 있다면 _EPROCESS 주소) 구하는 방법
12101정성태1/5/202018980.NET Framework: 876. C# - PEB(Process Environment Block)를 통해 로드된 모듈 목록 열람
12100정성태1/3/202016474.NET Framework: 875. .NET 3.5 이하에서 IntPtr.Add 사용
12099정성태1/3/202019289디버깅 기술: 151. Windows 10 - Process Explorer로 확인한 Handle 정보를 windbg에서 조회 [1]
12098정성태1/2/202019051.NET Framework: 874. C# - 커널 구조체의 Offset 값을 하드 코딩하지 않고 사용하는 방법 [3]
12097정성태1/2/202017127디버깅 기술: 150. windbg - Wow64, x86, x64에서의 커널 구조체(예: TEB) 구조체 확인
12096정성태12/30/201919848디버깅 기술: 149. C# - DbgEng.dll을 이용한 간단한 디버거 제작 [1]
12095정성태12/27/201921546VC++: 135. C++ - string_view의 동작 방식
12094정성태12/26/201919264.NET Framework: 873. C# - 코드를 통해 PDB 심벌 파일 다운로드 방법
12093정성태12/26/201918824.NET Framework: 872. C# - 로딩된 Native DLL의 export 함수 목록 출력파일 다운로드1
12092정성태12/25/201917651디버깅 기술: 148. cdb.exe를 이용해 (ntdll.dll 등에 정의된) 커널 구조체 출력하는 방법
12091정성태12/25/201919935디버깅 기술: 147. pdb 파일을 다운로드하기 위한 symchk.exe 실행에 필요한 최소 파일 [1]
12090정성태12/24/201920033.NET Framework: 871. .NET AnyCPU로 빌드된 PE 헤더의 로딩 전/후 차이점 [1]파일 다운로드1
12089정성태12/23/201918933디버깅 기술: 146. gflags와 _CrtIsMemoryBlock을 이용한 Heap 메모리 손상 여부 체크
12088정성태12/23/201917919Linux: 28. Linux - 윈도우의 "Run as different user" 기능을 shell에서 실행하는 방법
12087정성태12/21/201918380디버깅 기술: 145. windbg/sos - Dictionary의 entries 배열 내용을 모두 덤프하는 방법 (do_hashtable.py) [1]
12086정성태12/20/201920856디버깅 기술: 144. windbg - Marshal.FreeHGlobal에서 발생한 덤프 분석 사례
12085정성태12/20/201918833오류 유형: 586. iisreset - The data is invalid. (2147942413, 8007000d) 오류 발생 - 두 번째 이야기 [1]
12084정성태12/19/201919262디버깅 기술: 143. windbg/sos - Hashtable의 buckets 배열 내용을 모두 덤프하는 방법 (do_hashtable.py) [1]
12083정성태12/17/201922250Linux: 27. linux - lldb를 이용한 .NET Core 응용 프로그램의 메모리 덤프 분석 방법 [2]
... 61  62  63  64  65  66  67  68  69  70  71  72  [73]  74  75  ...