Answered by:
warning MSB4056

Question
-
Hi all
How this warning effect the compile process ?
I can't understand from the text"warning MSB4056: The MSBuild engine must be called on a single-threaded-apartment. Current threading model is "MTA". Proceeding, but some tasks may not function correctly."
Thanks
Monday, April 3, 2006 12:51 PM
Answers
-
Nir,
I believe you can change the apartment model of the just thread you're spinning off to use MSBuild, to STA. I don't recall the API off hand.
I don't recall what problem we encountered that led us to put this warning in, but most probably it won't lead to any actual issues for you.
Dan
Tuesday, May 2, 2006 11:20 PM
All replies
-
Certain COM Interop scenarios don't work with MTA threading, so when the MSBuild Engine is called from code with MTA set, the MSBuild Engine logs this warning just as a heads up in case any weird behavior results.
Are you hosting the MSBuild Engine in your own app? What sort of app is it? Console app? Windows app?
Thanks,
jeff.Monday, April 3, 2006 10:48 PM -
Thanks jeff for your quick answer.
I'm hosting the msbuild engine in a windows application and using delagate to start the compile operation.
When i use the async delegate to run the engine the process is becomeing MTA process. anlong with this warning i will get an error message if a "weird behavior" will result ?
Tuesday, April 4, 2006 5:39 AM -
Nir,
I believe you can change the apartment model of the just thread you're spinning off to use MSBuild, to STA. I don't recall the API off hand.
I don't recall what problem we encountered that led us to put this warning in, but most probably it won't lead to any actual issues for you.
Dan
Tuesday, May 2, 2006 11:20 PM -
I'm encountering the same warning. Funny thing is, my routine is attributed for STA. Here's the code:
[
Serializable]public class RemoteBuilder : MarshalByRefObject
{
[
STAThread] public bool Build(string projectFile){
Engine engine = new Engine();engine.BinPath =
@"d:\windows\microsoft.net\framework\v2.0.50727"; FileLogger logger = new FileLogger(); logger.Parameters = @"logfile=C:\build.log";engine.RegisterLogger(logger);
bool success = engine.BuildProjectFile(projectFile);engine.UnregisterAllLoggers();
return success;}
}
Any ideas on getting rid of this?
Tuesday, July 11, 2006 10:56 PM -
From the resource I’ve made .NET ignore the STA Thread attribute in some cases. Debug your program and check in different places the thread state, you'll see that something make the program to move to MTA. After the program executions moved to MTA there is no way (that I know :) ) to move back to STA.
I just ignore the warning...Hope this help
NirWednesday, July 12, 2006 6:45 PM -
I resolved putting attribute [STAThread] on the caller method too.Tuesday, July 4, 2017 1:26 PM