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

비밀번호

댓글 작성자
 




... 46  47  48  49  [50]  51  52  53  54  55  56  57  58  59  60  ...
NoWriterDateCnt.TitleFile(s)
12406정성태11/8/202013528.NET Framework: 966. C# 9.0 - (15) 최상위 문(Top-level statements) [5]파일 다운로드1
12405정성태11/8/202010884.NET Framework: 965. C# 9.0 - (14) 부분 메서드에 대한 새로운 기능(New features for partial methods)파일 다운로드1
12404정성태11/7/202011460.NET Framework: 964. C# 9.0 - (13) 모듈 이니셜라이저(Module initializers)파일 다운로드1
12403정성태11/7/202011461.NET Framework: 963. C# 9.0 - (12) foreach 루프에 대한 GetEnumerator 확장 메서드 지원(Extension GetEnumerator)파일 다운로드1
12402정성태11/7/202012063.NET Framework: 962. C# 9.0 - (11) 공변 반환 형식(Covariant return types) [1]파일 다운로드1
12401정성태11/5/202011093VS.NET IDE: 153. 닷넷 응용 프로그램에서의 "My Code" 범위와 "Enable Just My Code"의 역할 [1]
12400정성태11/5/20207985오류 유형: 679. Visual Studio - "Source Not Found" 창에 "Decompile source code" 링크가 없는 경우
12399정성태11/5/202011692.NET Framework: 961. C# 9.0 - (10) 대상으로 형식화된 조건식(Target-typed conditional expressions)파일 다운로드1
12398정성태11/4/202010253오류 유형: 678. Windows Server 2008 R2 환경에서 Powershell을 psexec로 원격 실행할 때 hang이 발생하는 문제
12397정성태11/4/202010434.NET Framework: 960. C# - 조건 연산자(?:)를 사용하는 경우 달라지는 메서드 선택 사례파일 다운로드1
12396정성태11/3/20208656VS.NET IDE: 152. Visual Studio - "Tools" / "External Tools..."에 등록된 외부 명령어에 대한 단축키 설정 방법
12395정성태11/3/202010049오류 유형: 677. SSMS로 DB 접근 시 The server principal "..." is not able to access the database "..." under the current security context.
12394정성태11/3/20208385오류 유형: 676. cacls - The Recycle Bin on ... is corrupted. Do you want to empty the Recycle Bin for this drive?
12393정성태11/3/20208918오류 유형: 675. Visual Studio - 닷넷 응용 프로그램 디버깅 시 Disassembly 창에서 BP 설정할 때 "Error while processing breakpoint." 오류
12392정성태11/2/202013125.NET Framework: 959. C# 9.0 - (9) 레코드(Records) [4]파일 다운로드1
12390정성태11/1/202011296디버깅 기술: 173. windbg - System.Configuration.ConfigurationErrorsException 예외 분석 방법
12389정성태11/1/202011005.NET Framework: 958. C# 9.0 - (8) 정적 익명 함수 (static anonymous functions)파일 다운로드1
12388정성태10/29/202010482오류 유형: 674. 어느 순간부터 닷넷 응용 프로그램 실행 시 System.Configuration.ConfigurationErrorsException 예외가 발생한다면?
12387정성태10/28/202011266.NET Framework: 957. C# - static 필드의 정보가 GC Heap에 저장될까요? [3]파일 다운로드1
12386정성태10/28/202011483Linux: 34. 사용자 정보를 함께 출력하는 리눅스의 ps 명령어 사용 방법
12385정성태10/28/20209296오류 유형: 673. openssl - req: No value provided for Subject Attribute CN, skipped
12384정성태10/27/202010544오류 유형: 672. AllowPartiallyTrustedCallers 특성이 적용된 어셈블리의 struct 멤버 메서드를 재정의하면 System.Security.VerificationException 예외 발생
12383정성태10/27/202011473.NET Framework: 956. C# 9.0 - (7) 패턴 일치 개선 사항(Pattern matching enhancements) [3]파일 다운로드1
12382정성태10/26/20209057오류 유형: 671. dotnet build - The local source '...' doesn't exist
12381정성태10/26/202010850VC++: 137. C++ stl map의 사용자 정의 타입을 key로 사용하는 방법 [1]파일 다운로드1
12380정성태10/26/20208171오류 유형: 670. Visual Studio - Squash_FailureCommitsReset
... 46  47  48  49  [50]  51  52  53  54  55  56  57  58  59  60  ...