开发者

C# Unmanaged application crash when using Enterprise Library

开发者 https://www.devze.com 2023-04-07 18:38 出处:网络
I have a C# library DLL which is loaded from an unmanaged process. So far everything is good. Now I wanted to incorporate the Enterprise Library 5.0 with its logging capabilities. I added these refere

I have a C# library DLL which is loaded from an unmanaged process. So far everything is good. Now I wanted to incorporate the Enterprise Library 5.0 with its logging capabilities. I added these references:

  • Microsoft.Practices.EnterpriseLibrary.Common.dll
  • Microsoft.Practices.Unity.dll
  • Microsoft.Practices.Unity.Interception.dll
  • Microsoft.Practices.ServiceLocation.dll
  • Microsoft.Practices.EnterpriseLibrary.Logging.dll

...and all the using statements required. Here is an excerpt from the class:

using Microsoft.Practices.EnterpriseLibrary.Common;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
using Microsoft.Practices.Unity;
using Microsoft.Practices.Unity.InterceptionExtension;
using Microsoft.Practices.ServiceLocation;
using Microsoft.Practices.Unity.Configuration;    

[StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack=2)]
unsafe public static class DLLDispatch
{
    private static IConfigurationSourceBuilder LoggingBuilder = new ConfigurationSourceBuilder();
    ...
}

The problem is that when this field is defined the unmanaged processes crashes. If it is commented out, this crash does not happen. And here is the windows application log for this crash:

**Sig[0].Name=Application Name

Sig[0].Value=terminal64.exe

Sig[1].Name=Application Version

Sig[1].Value=5.0.0.507

Sig[2].Name=Application Timestamp

Sig[2].Value=003f5e00

Sig[3].Name=Fault Module Name

Sig[3].Value=clr.dll

Sig[4].Name=Fault Module Version

Sig[4].Value=4.0.30319.237

Sig[5].Name=Fault Module Timestamp

Sig[5].Value=4dd2333e

Sig[6].Name=Exception Code

Sig[6].Value=c00000fd

Sig[7].Name=Exception Offset

Sig[7].Value=000000000007382a**

I searched the web for the exception code c00000fd and found it to be a stackoverflow :-) exception. I played around a bit and this crash occures everytime there开发者_如何转开发 is an instance involved from the enterprise library. If nothing is used of that library then there is no crash. What is going on here? Is it becasue the class is in unsafe context or what else can it be? Thanks in advance.


I found the solution to this problem. One has to put a app-config file in the unmanaged application folder with this content:

<?xml version="1.0" encoding="UTF-8" ?>
<configuration>
 <runtime>
   <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
     <probing privatePath="Unmanaged application startup folder" />
   </assemblyBinding>
 </runtime>
</configuration>

With this information the CLR can bind assemblies and searches in the correct folder. It was not clear to me that a config file is also useful for unmanaged applications.

Thanks, Juergen

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号