Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8651563
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T14:06:09+00:00 2026-06-12T14:06:09+00:00

My team works with the COM API of a large simulation application. Most simulation

  • 0

My team works with the COM API of a large simulation application. Most simulation files run into the hundreds of megabytes and appear to get fully loaded into memory when they are opened.

The main task that we perform is iterating through all of the elements in the object model of the file and then doing ‘something’ to each element.

We have recently moved our code base from .NET 2 in to .NET 4 in VS 2010 and have seen the iteration speed drop by about 40 times (from ~10 seconds to about 8 minutes). We have reduced this to the smallest possible example of code (10 lines or so); compiled this in VS 2005, run it and then opened the project in VS 2010 and compiled, leaving the framework as 2 (we are using the manufacturer supplied COM interop assemblies).

In 2005 the test app completes in 10 seconds in 2010 it takes 8 minutes.

What could be causing this?

UPDATE

The code is equivalent to:

var server = new Server();
var elements = server.Elements;
var elementCount = elements.Count;

for(int i = 0; i < elementsCount; ++i)
{
    var element = elements[i];
}

This code takes 40 times longer to run through VS 2010 than VS 2005.

UPDATE 2

I rationalised that the only reason that the operation can be dramatically slower in one case than the other is that data is transferred differently over COM in the different versions.

We recorded the binding logs for both cases and this is what we found; in the fast version the native image of CustomMarshalers is not found (these are the binding logs captured by FUSLOGVW)

mscorlib

mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089.HTM

Fast

LOG: Start binding of native image mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089.
LOG: Start validating native image mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089.
WRN: Native image does not satisfy request. Looking for next native image.
WRN: No matching native image found.

Slow

LOG: Start binding of native image mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089.
LOG: Start validating native image mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089.
LOG: Bind to native image succeeded.

CustomMarshalers

CustomMarshalers, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a

Fast

LOG: Start binding of native image CustomMarshalers, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a.
LOG: Start validating native image CustomMarshalers, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a.
WRN: Native image does not satisfy request. Looking for next native image.
WRN: No matching native image found.

Slow

LOG: Start binding of native image CustomMarshalers, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a.
LOG: Start validating native image CustomMarshalers, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a.
LOG: Start validating all the dependencies.
LOG: [Level 1]Start validating native image dependency mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089.
LOG: Dependency evaluation succeeded.
LOG: [Level 1]Start validating IL dependency Microsoft.VisualC, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a.
LOG: Dependency evaluation succeeded.
LOG: Validation of dependencies succeeded.
LOG: Start loading all the dependencies into load context.
LOG: Loading of dependencies succeeded.
LOG: Bind to native image succeeded.
Native image has correct version information.
Attempting to use native image C:\WINDOWS\assembly\NativeImages_v2.0.50727_32\CustomMarshalers\3e6deccf191ab943d3a0812a38ab5c97\CustomMarshalers.ni.dll.
Native image successfully used.

So it looks like we get a big performance boost when the native image is not used.

Why would this bind fail in one case and succeed in an other, and how do we force the application to not use the native image?

UPDATE 3

The oddness continues. If I run this code in VS 2010 in a test method using the R# test runner, or the in-built Visual Studio test runner then it runs at the fast speed.

I have tried wrapping this code in an assembly and then loading that dynamically and that makes no difference.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T14:06:12+00:00Added an answer on June 12, 2026 at 2:06 pm

    It was kind of a long shot. Glad I could help.

    Matching MTA vs STA (threading model) is really important when making lots of distinct calls into any COM object. An [STAThread] directive at the top of a method is one way to be sure of threading model for every call in that method.

    Looks like Thread.SetApartmentState(ApartmentState.STA) will work for a whole thread, but not apparently for thread pool threads.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working with a team that works on a very large software project,
Our .NET team works on projects for our company that fall into distinct categories.
I am thinking about a platform for study application (it is team work). I
I work on a small Agile development team which is part of a large,
My team (3 developers) will be building a Silverlight LOB application. This is the
I have a .txt file with following content. [{key: HR, value: test@gmail.com}, {key: Team
i have used TF.exe (Team Foundation Client) to checkout files from outside with the
I recently tried out Microsoft's TFS-in-the-cloud service (TFSPreview.com) and felt the TFS team finally
My team is in the process of prototyping an application with a rather complex
I'm just starting to get into Django, and of course as of last night

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.