Microsoft MVP성태의 닷넷 이야기
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일
(연관된 글이 2개 있습니다.)

WPF - .NET 3.5 이하에서 TextBox에 한글 입력 시 TextChanged 이벤트의 비정상 종료 문제

다음과 같은 질문이 있군요.

WPF .net 3.5에서 TextBox 한글 문제
; https://www.sysnet.pe.kr/3/0/4831

위의 문제에 대한 재현은 간단합니다. 기본 생성된 WPF 프로젝트의 MainWindow.xaml에 다음과 같이 TextBox를 하나 얹고,

<TextBox Text="TextBox" TextChanged="TextBox_TextChanged"/>

TextBox_TextChanged 이벤트에 MessageBox를 띄우게 코딩한 후,

private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
{
    MessageBox.Show("TEST");
}

실행 시에 TextBox에 한글을 입력하게 되면 다음과 같은 예외가 발생하거나,
System.InvalidOperationException occurred
  HResult=0x80131509
  Message=There is no registered CultureInfo with the IetfLanguageTag 'ug'.
  Source=<Cannot evaluate the exception source>
  StackTrace:
<Cannot evaluate the exception stack trace>

Inner Exception 1:
ArgumentException: Culture name 'ug' is not supported.

아니면 다음과 같이 간단한 debug 로그만 남긴 체 응용 프로그램이 비정상 종료해 버립니다.

The program '[8296] WpfApp1.exe' has exited with code -1073740940 (0xc0000374).
The program '[8296] WpfApp1.exe: Program Trace' has exited with code 0 (0x0).

사실, "There is no registered CultureInfo with the IetfLanguageTag 'ug'." 예외 메시지는 몇몇 환경에서 나타나는 부가적인 메시지일 뿐 설령 그 오류 메시지를 해결한다 해도 결국에는 0xc0000374 (Heap Corruption Exception) 예외를 발생하며 비정상 종료를 해버립니다.

이벤트 로그에도 역시 간단한 메시지만 남게 되어 도대체 이게 무슨 현상인가 싶을 정도입니다. ^^;

Log Name:      Application
Source:        .NET Runtime
Date:          2017-05-17 오전 12:32:44
Event ID:      1023
Task Category: None
Level:         Error
Keywords:      Classic
User:          N/A
Computer:      TESTPC
Description:
.NET Runtime version 2.0.50727.8784 - Unrecoverable system error.

Log Name:      Application
Source:        Windows Error Reporting
Date:          2017-05-17 오전 12:41:35
Event ID:      1001
Task Category: None
Level:         Information
Keywords:      Classic
User:          N/A
Computer:      TESTPC
Description:
Fault bucket , type 0
Event Name: CLR20r3
Response: Not available
Cab Id: 0

Problem signature:
P1: wpfapp1.exe
P2: 1.0.0.0
P3: 591b1c8a
P4: WindowsBase
P5: 3.0.0.0
P6: 58dbbc47
P7: df
P8: 0
P9: FatalError
P10: 




이 문제를 사실 어떻게 해결해야 할지 모르겠습니다. ^^;

일단, 가장 권장되는 방법은 .NET 4.0으로 올리는 것입니다. 또는 3.5로 개발되었다고 해도 4.0이 설치된 PC에서는 CLR 4.0에서 실행되도록 다음과 같이 app.config을 조정해 주는 것입니다.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <startup>
    <supportedRuntime version="v4.0.30319"/>
    <supportedRuntime version="v2.0.50727"/>
  </startup>
</configuration>

그렇다면 3.5 이하의 .NET Framework이 설치된 곳에서는 어떻게 해야 할까요? 이렇게 되면 약간의 꼼수를 써야 하는데요. 제가 생각해 낸 그나마 가장 우아한 방법은 Dispatcher.BeginInvoke를 이용하는 것이었습니다.

private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
{
    this.Dispatcher.BeginInvoke( (Action)(
        () => {
            MessageBox.Show("TEST");
        }), null);
}

혹시 다른 방법을 알고 계신 분은 덧글 부탁드립니다. ^^

(첨부 파일은 이 글의 예제 코드를 포함합니다.)




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

[연관 글]






[최초 등록일: ]
[최종 수정일: 5/17/2017]

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

비밀번호

댓글 작성자
 



2017-05-17 01시24분
[김신철] 항상 많은 정보 알려주셔서 감사합니다~ 큰 도움이 될것같습니다 ^^
[guest]

... 46  47  48  [49]  50  51  52  53  54  55  56  57  58  59  60  ...
NoWriterDateCnt.TitleFile(s)
12402정성태11/7/202011541.NET Framework: 962. C# 9.0 - (11) 공변 반환 형식(Covariant return types) [1]파일 다운로드1
12401정성태11/5/202010465VS.NET IDE: 153. 닷넷 응용 프로그램에서의 "My Code" 범위와 "Enable Just My Code"의 역할 [1]
12400정성태11/5/20207519오류 유형: 679. Visual Studio - "Source Not Found" 창에 "Decompile source code" 링크가 없는 경우
12399정성태11/5/202011134.NET Framework: 961. C# 9.0 - (10) 대상으로 형식화된 조건식(Target-typed conditional expressions)파일 다운로드1
12398정성태11/4/20209578오류 유형: 678. Windows Server 2008 R2 환경에서 Powershell을 psexec로 원격 실행할 때 hang이 발생하는 문제
12397정성태11/4/20209727.NET Framework: 960. C# - 조건 연산자(?:)를 사용하는 경우 달라지는 메서드 선택 사례파일 다운로드1
12396정성태11/3/20208134VS.NET IDE: 152. Visual Studio - "Tools" / "External Tools..."에 등록된 외부 명령어에 대한 단축키 설정 방법
12395정성태11/3/20209424오류 유형: 677. SSMS로 DB 접근 시 The server principal "..." is not able to access the database "..." under the current security context.
12394정성태11/3/20207840오류 유형: 676. cacls - The Recycle Bin on ... is corrupted. Do you want to empty the Recycle Bin for this drive?
12393정성태11/3/20208327오류 유형: 675. Visual Studio - 닷넷 응용 프로그램 디버깅 시 Disassembly 창에서 BP 설정할 때 "Error while processing breakpoint." 오류
12392정성태11/2/202012453.NET Framework: 959. C# 9.0 - (9) 레코드(Records) [4]파일 다운로드1
12390정성태11/1/202010569디버깅 기술: 173. windbg - System.Configuration.ConfigurationErrorsException 예외 분석 방법
12389정성태11/1/202010501.NET Framework: 958. C# 9.0 - (8) 정적 익명 함수 (static anonymous functions)파일 다운로드1
12388정성태10/29/20209865오류 유형: 674. 어느 순간부터 닷넷 응용 프로그램 실행 시 System.Configuration.ConfigurationErrorsException 예외가 발생한다면?
12387정성태10/28/202010584.NET Framework: 957. C# - static 필드의 정보가 GC Heap에 저장될까요? [3]파일 다운로드1
12386정성태10/28/202010860Linux: 34. 사용자 정보를 함께 출력하는 리눅스의 ps 명령어 사용 방법
12385정성태10/28/20208612오류 유형: 673. openssl - req: No value provided for Subject Attribute CN, skipped
12384정성태10/27/20209835오류 유형: 672. AllowPartiallyTrustedCallers 특성이 적용된 어셈블리의 struct 멤버 메서드를 재정의하면 System.Security.VerificationException 예외 발생
12383정성태10/27/202010858.NET Framework: 956. C# 9.0 - (7) 패턴 일치 개선 사항(Pattern matching enhancements) [3]파일 다운로드1
12382정성태10/26/20208485오류 유형: 671. dotnet build - The local source '...' doesn't exist
12381정성태10/26/202010127VC++: 137. C++ stl map의 사용자 정의 타입을 key로 사용하는 방법 [1]파일 다운로드1
12380정성태10/26/20207631오류 유형: 670. Visual Studio - Squash_FailureCommitsReset
12379정성태10/21/202010530.NET Framework: 955. .NET 메서드의 Signature 바이트 코드 분석 [1]파일 다운로드2
12378정성태10/15/202010011.NET Framework: 954. C# - x86/x64 환경에 따라 달라지는 P/Invoke 함수의 export 이름파일 다운로드1
12377정성태10/15/202011348디버깅 기술: 172. windbg - 파일 열기 시점에 bp를 걸어 파일명 알아내는 방법(Managed/Unmanaged)
12376정성태10/15/20208092오류 유형: 669. windbg - sos의 name2ee 명령어 실행 시 "Failed to request module list." 오류
... 46  47  48  [49]  50  51  52  53  54  55  56  57  58  59  60  ...