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]

... 61  62  63  64  65  66  67  68  [69]  70  71  72  73  74  75  ...
NoWriterDateCnt.TitleFile(s)
11904정성태5/21/201916640.NET Framework: 833. C# - Open Hardware Monitor를 이용한 CPU 온도 정보 [1]파일 다운로드1
11903정성태5/21/201911680오류 유형: 540. .NET Core - System.PlatformNotSupportedException: The named version of this synchronization primitive is not supported on this platform.
11902정성태5/21/201910860오류 유형: 539. mstest 실행 시 "The directory name is invalid." 오류 발생
11901정성태5/21/201911994오류 유형: 538. msbuild 오류 - Could not find a part of the path '%LOCALAPPDATA%\Temp\2\.NETFramework,Version=v4.0.AssemblyAttributes.cs'
11900정성태5/18/201911288오류 유형: 537. "sfc /scannow" 실행 중 시스템이 부팅되는 현상
11899정성태5/17/201912266Linux: 9. Linux에서 윈도우의 OutputDebugString 대신 사용할 수 있는 syslog [1]
11898정성태5/16/201913633VC++: 130. C++ string의 c_str과 data 함수의 차이점 [3]
11897정성태5/16/201920225오류 유형: 536. Visual Studio - "Developer Pack"을 설치했는데도 "대상 프레임워크" 목록에 나오지 않는 경우 [2]
11896정성태5/15/201914997개발 환경 구성: 440. C#, C++ - double의 Infinity, NaN 표현 방식파일 다운로드1
11895정성태5/12/201913398.NET Framework: 832. ML.NET Model Builder - 회귀(Regression), 다중 분류(Multi-class classification) 예제파일 다운로드1
11894정성태5/10/201914559VS.NET IDE: 135. Visual Studio - ML.NET Model Builder 소개 [5]
11893정성태5/10/201912272오류 유형: 535. C# 6.0 이상의 문법을 컴파일 시 오류가 발생한다면?
11892정성태5/10/201912340웹: 38. HTTP Cookie의 expires 시간 형식(RFC7231)
11891정성태5/9/201914837.NET Framework: 831. (번역글) .NET Internals Cookbook Part 12 - Memory structure, attributes, handles
11890정성태5/8/201910552개발 환경 구성: 439. "Visual Studio Enterprise is required to execute the test." 메시지와 관련된 코드 기록
11889정성태5/8/201911315개발 환경 구성: 438. mstest, QTAgent의 로그 파일 설정 방법
11888정성태5/8/201926441.NET Framework: 830. C# - 비동기 호출을 취소하는 CancellationToken의 간단한 예제 코드 [1]파일 다운로드1
11887정성태5/8/201913119.NET Framework: 829. C# - yield 문을 사용할 수 있는 메서드의 조건
11886정성태5/7/201912159오류 유형: 534. mstest.exe 실행 시 "Visual Studio Enterprise is required to execute the test." 오류 [2]
11885정성태5/7/20199143오류 유형: 533. mstest.exe 실행 시 "File extension specified '.loadtest' is not a valid test extension." 오류 발생
11884정성태5/5/201912846.NET Framework: 828. C# DLL에서 Win32 C/C++처럼 dllexport 함수를 제공하는 방법 - 두 번째 이야기
11883정성태5/3/201917072.NET Framework: 827. C# - 인터넷 시간 서버로부터 받은 시간을 윈도우에 적용하는 방법파일 다운로드1
11882정성태5/2/201914039.NET Framework: 826. (번역글) .NET Internals Cookbook Part 11 - Various C# riddles파일 다운로드1
11881정성태4/28/201914318오류 유형: 532. .NET Core 프로젝트로 마이그레이션 시 "CS0579 Duplicate 'System.Reflection.AssemblyCompanyAttribute' attribute" 오류 발생
11880정성태4/25/201911087오류 유형: 531. 이벤트 로그 오류 - Task Scheduling Error: m->NextScheduledSPRetry 1547, m->NextScheduledEvent 1547
11879정성태4/24/201916342.NET Framework: 825. (번역글) .NET Internals Cookbook Part 10 - Threads, Tasks, asynchronous code and others파일 다운로드2
... 61  62  63  64  65  66  67  68  [69]  70  71  72  73  74  75  ...