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

비밀번호

댓글 작성자
 




... 76  77  78  79  80  81  82  83  84  85  [86]  87  88  89  90  ...
NoWriterDateCnt.TitleFile(s)
11820정성태2/20/201924483오류 유형: 515. 윈도우 10 1809 업데이트 후 "User Profiles Service" 1534 경고 발생
11819정성태2/20/201923557Windows: 158. 컴퓨터와 사용자의 SID(security identifier) 확인 방법
11818정성태2/20/201921607VS.NET IDE: 131. Visual Studio 2019 Preview의 닷넷 프로젝트 빌드가 20초 이상 걸리는 경우 [2]
11817정성태2/17/201917526오류 유형: 514. WinDbg Preview 실행 오류 - Error : DbgX.dll : WindowsDebugger.WindowsDebuggerException: Could not load dbgeng.dll
11816정성태2/17/201921479Windows: 157. 윈도우 스토어 앱(Microsoft Store App)을 명령행에서 직접 실행하는 방법
11815정성태2/14/201919603오류 유형: 513. Visual Studio 2019 - VSIX 설치 시 "The extension cannot be installed to this product due to prerequisites that cannot be resolved." 오류 발생
11814정성태2/12/201918235오류 유형: 512. VM(가상 머신)의 NT 서비스들이 자동 시작되지 않는 문제
11813정성태2/12/201919206.NET Framework: 809. C# - ("Save File Dialog" 등의) 대화 창에 확장 속성을 보이는 방법
11812정성태2/11/201916588오류 유형: 511. Windows Server 2003 VM 부팅 후 로그인 시점에 0xC0000005 BSOD 발생
11811정성태2/11/201922435오류 유형: 510. 서버 운영체제에 NVIDIA GeForce Experience 실행 시 wlanapi.dll 누락 문제
11810정성태2/11/201919372.NET Framework: 808. .NET Profiler - GAC 모듈에서 GAC 비-등록 모듈을 참조하는 경우의 문제
11809정성태2/11/201922267.NET Framework: 807. ClrMD를 이용해 메모리 덤프 파일로부터 특정 인스턴스를 참조하고 있는 소유자 확인
11808정성태2/8/201923707디버깅 기술: 123. windbg - 닷넷 응용 프로그램의 메모리 누수 분석
11807정성태1/29/201921452Windows: 156. 가상 디스크의 용량을 복구 파티션으로 인해 늘리지 못하는 경우 [4]
11806정성태1/29/201920549디버깅 기술: 122. windbg - 덤프 파일로부터 PID와 환경 변수 등의 정보를 구하는 방법
11805정성태1/28/201923334.NET Framework: 806. C# - int []와 object []의 차이로 이해하는 제네릭의 필요성 [4]파일 다운로드1
11804정성태1/24/201920911Windows: 155. diskpart - remove letter 이후 재부팅 시 다시 드라이브 문자가 할당되는 경우
11803정성태1/10/201919855디버깅 기술: 121. windbg - 닷넷 Finalizer 스레드가 멈춰있는 현상
11802정성태1/7/201921512.NET Framework: 805. 두 개의 윈도우를 각각 실행하는 방법(Windows Forms, WPF)파일 다운로드1
11801정성태1/1/201922452개발 환경 구성: 427. Netsh의 네트워크 모니터링 기능 [3]
11800정성태12/28/201821889오류 유형: 509. WCF 호출 오류 메시지 - System.ServiceModel.CommunicationException: Internal Server Error
11799정성태12/19/201823820.NET Framework: 804. WPF(또는 WinForm)에서 UWP UI 구성 요소 사용하는 방법 [3]파일 다운로드1
11798정성태12/19/201822380개발 환경 구성: 426. vcpkg - "Building vcpkg.exe failed. Please ensure you have installed Visual Studio with the Desktop C++ workload and the Windows SDK for Desktop C++"
11797정성태12/19/201818091개발 환경 구성: 425. vcpkg - CMake Error: Problem with archive_write_header(): Can't create '' 빌드 오류
11796정성태12/19/201818961개발 환경 구성: 424. vcpkg - "File does not have expected hash" 오류를 무시하는 방법
11795정성태12/19/201822355Windows: 154. PowerShell - Zone 별로 DNS 레코드 유형 정보 조회 [1]
... 76  77  78  79  80  81  82  83  84  85  [86]  87  88  89  90  ...