Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / CLR / June 2005

Tip: Looking for answers? Try searching our database.

String.Trim method throws ExecutionEngineException

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Eugene - 16 Jun 2005 21:07 GMT
This problem occurs after system has been fully initialized and main form is
displayed. Calling 'Trim' method during initialization causes no problem.

I tried to avoid using this method but some framework classes use it as
well. For example 'DataView.Sort' property uses it according to call stack
window.

Please help who knows what's going on.

Thank you,

Eugene
Jon Skeet [C# MVP] - 16 Jun 2005 21:22 GMT
> This problem occurs after system has been fully initialized and main form is
> displayed. Calling 'Trim' method during initialization causes no problem.
[quoted text clipped - 4 lines]
>
> Please help who knows what's going on.

Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Eugene - 17 Jun 2005 19:13 GMT
Jon,

Thank you for your reply. I will prepare short program after the weekends.

For now I have a feeling that this problem is related to the one described
in the following bug article -

http://support.microsoft.com/default.aspx?scid=kb;en-us;327416

Although I do not use Activator.CreateInstance() method but I do use this
approach -

string file_name = ...
Type target_type = ...
System.Reflection.Assembly assembly = System.Reflection.Assembly.LoadFile(
file_name );
object oCreated = assembly.CreateInstance( target_type, true );

Would you agree with my conclusion that Activator.CreateInstance() and
Assembly.CreateInstance() execute the same routine therefore the fix
Microsoft may have for the bug described in the article I have referred to
above is applicable in my case as well?

Please advice.

Thank you once again for taking time to reply to me.

Eugene

> > This problem occurs after system has been fully initialized and main form is
> > displayed. Calling 'Trim' method during initialization causes no problem.
[quoted text clipped - 10 lines]
> See http://www.pobox.com/~skeet/csharp/complete.html for details of
> what I mean by that.
Jon Skeet [C# MVP] - 18 Jun 2005 10:16 GMT
> Thank you for your reply. I will prepare short program after the weekends.
>
[quoted text clipped - 16 lines]
> Microsoft may have for the bug described in the article I have referred to
> above is applicable in my case as well?

I think it's unlikely to be connected, for a few reasons:

1) That KB article applies to the 1.0 version of the framework.
2) Unless you're creating an array type that way, I don't think the KB
  article is actually relevant.
3) I would expect the exception to be thrown immediately, whereas you
  said before that you were having problems with String.Trim, rather
  than Assembly.CreateInstance.

(I hope the code above isn't actually representative of your real code
though - it would suggest that you're asking the assembly to create a
type which isn't from it. You should be loading the assembly, then
fetching the type from it, then creating an instance.)

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Eugene - 20 Jun 2005 19:41 GMT
Jon,

I have solved my problem by inserting string strA = strB.Trim( ) statement
between several lines of code until I have pinpointed exact place where
"Trim( )" method starts failing.

The reason was an incorrect declaration of "GetPrivateProfileString" API -

[DllImport("kernel32.dll", CharSet=CharSet.Unicode, SetLastError=true,
EntryPoint = "GetPrivateProfileString", CallingConvention =
CallingConvention.StdCall )]
    public extern static int GetPrivateProfileString( string section, string
key, string default, [Out, MarshalAsAttribute(UnmanagedType.LPTStr)] string
buffer, ref int size, string fileName );

which I used in the following way -

    string fileName = "C:\\Windows\\file.ini";
    string buffer = String.Empty;
    int size = 0;
    size = GetPrivateProfileString( "Section", "Key", "Default", buffer, ref
size, fileName );
    version = new string( '\0', size );
    GetPrivateProfileString( "Section", "Key ", "Default", buffer, ref size,
fileName );

After the last call the "buffer" variable did contain correctly read value
but all subsequent calls to String.Trim( ) method began to throw
‘ExecutionEngineException’.

Now I am using the following declaration -

    [DllImport("kernel32.dll", CharSet=CharSet.Unicode, SetLastError=true,
EntryPoint = "GetPrivateProfileString", CallingConvention =
CallingConvention.StdCall )]
    public extern static int GetPrivateProfileString( string section, string
key, string default, IntPtr buffer, ref int size, string fileName );

I would appreciate if you briefly explained what was wrong with the
declaration I had used in the first place.

Thank you for your help.

Eugene.

> > Thank you for your reply. I will prepare short program after the weekends.
> >
[quoted text clipped - 30 lines]
> type which isn't from it. You should be loading the assembly, then
> fetching the type from it, then creating an instance.)
Jon Skeet [C# MVP] - 20 Jun 2005 22:17 GMT
<snip>

> Now I am using the following declaration -
>
[quoted text clipped - 6 lines]
> I would appreciate if you briefly explained what was wrong with the
> declaration I had used in the first place.

Well, I don't know much about GetPrivateProfileString myself, but I
suspect that .NET thought it "owned" the memory which was being
referenced by your out parameter. I believe that *usually* when you
need to effectively get a string as an out parameter, you should pass
in a StringBuilder, but I'm afraid I'm really not an interop expert.

Sorry to pass the buck like this, but it's much better that you get
advice from someone who definitely knows their way around P/Invoke
better than me - I'd suggest asking on the .interop group.

You might also want to look at
http://www.codeproject.com/csharp/cs_ini.asp

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too


Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.