Solved: The C++ module failed to load while attempting to initialize the default appdomain.

By dsandor at July 02, 2010 20:37
Filed Under: Programming

Summary of Errors:

Exception of type 'System.Web.HttpUnhandledException' was thrown.

The type initializer for '' threw an exception.

The C++ module failed to load while attempting to initialize the default appdomain.

Illegal operation attempted on a registry key that has been marked for deletion.

 

The full ugly error:

System.Web.HttpUnhandledException: Exception of type 'System.Web.HttpUnhandledException' was thrown. ---> System.ServiceModel.FaultException`1[System.ServiceModel.ExceptionDetail]: The type initializer for '' threw an exception. (Fault Detail is equal to An ExceptionDetail, likely created by IncludeExceptionDetailInFaults=true, whose value is: System.TypeInitializationException: The type initializer for '' threw an exception. ----> System.TypeInitializationException: The type initializer for '' threw an exception. ----> .ModuleLoadException: The C++ module failed to load while attempting to initialize the default appdomain. ----> System.Runtime.InteropServices.COMException: Illegal operation attempted on a registry key that has been marked for deletion. (Exception from HRESULT: 0x800703FA) at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo) at .GetDefaultDomain() at .DoCallBackInDefaultDomain(IntPtr function, Void* cookie) at .LanguageSupport.InitializeDefaultAppDomain(LanguageSupport* ) at .LanguageSupport._Initialize(LanguageSupport* ) ...). --- End of inner exception stack trace --- at System.Web.UI.Page.HandleError(Exception e) at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) at System.Web.UI.Page.ProcessRequest() at System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context) at System.Web.UI.Page.ProcessRequest(HttpContext context) at ASP.fieldreceiptdetail_aspx.ProcessRequest(HttpContext context) at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

Solution:

This problem was related to a cross-appdomain failure.  We are using the Microsoft Dynamics AX 2009 Business Connector in this application.  The Business Connector is a C++ application that we use to talk to AX.  From what I can gather, there are two applications using the C++ DLL at the same time.  The problem is that the DLL is mixing appdomains because of our Application Pool setup in IIS 7. 

image

So to solve the problem, I created a new Application Pool for this application.  I also set the pipeline mode to Classic.  This solved the problem for me.

Solved: .NET 4.0 cannot find assembly reference even though assembly is there and there are no exclamation marks on the reference in Visual Studio 2010.

By dsandor at November 08, 2009 19:25
Filed Under:

Error    1    The type or namespace name 'log4net' could not be found (are you missing a using directive or an assembly reference?)    c:\projects\DevSQL\…\Properties\AssemblyInfo.cs    4    7    SomeService

And warning:

Warning    8    The referenced assembly "c:\projects\DevSQL\…\AccountService\aaa.ServerCommon\bin\Debug\aaa.ServerCommon.dll" could not be resolved because it has a dependency on "System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" which is not in the currently targeted framework ".NETFramework,Version=v4.0,Profile=Client".    aaaService

 

image

So you are getting an error that typically points to an assembly reference not found.  Well just hang on a second before you go wild with debugging this.  First, check to make sure that there are no yellow exclamation marks on the assembly reference.  That would be a classic assembly not found problem.  If it is not there you may have another issue as discussed here.

Check to see if you have any warnings.

image

If you have warning messages like this you have a .NET 4.0 Profile settings error.  This is super easy to fix.  To give you some background on this, there are now more than one installation profile for .NET Runtime Libraries.  One is Full and one is Client.  The idea behind this is that if you are building a program that does not need to reference server side assemblies (System.Web.* as an example) then why install them?  You can now target a Full or Client profile.  The Client profiles will NOT have the server assemblies installed. 

To fix the problem, you need to target the full profile.  Simply Right click on your project and go to Properties.

image

Simply change the Target Framework drop down to .NET Framework 4 instead of .NET Framework 4 Client Profile and your code should compile.