tags:

views:

244

answers:

3

Hello

I have a .NET DLL that writes to the Trace. But seems that when I call my DLL from a VB6 EXE the trace is not working. I have created an myApp.config file in the EXE folder with the trace configuration, but this does not solves the issue.

I've also tried creating the Trace objects in code,but doesn't work:

Dim _traceSrc as TraceSource= New TraceSource("myTraceSorce")
Dim flListener As FileLogTraceListener = New FileLogTraceListener("myFileLogTraceListener")
Dim tSwitch As SourceSwitch = New SourceSwitch("mySwitch")
tSwitch.Level = _logLevel

If I call my DLL from a .NET EXE it works, even if I dont have the app.config in the EXE folder, becusase I set it in code if the config is not found.

Thanks

A: 

I think the problem is that VB6 is using COM to load your managed DLL.

The .NET code won't load your .config file as it uses a single 'shim' handler for all COM Interop.

The best you might be able to do is to add something to your machine.config file (but most people don't like doing that).

Initialising tracing in code should work though. Remove your tracing configuration from the managed .EXE and run it in a debugger to check that the code version works there too.

David Gardiner
+1  A: 

If your VB6 application is called MyApp.exe then the config file should be called MyApp.exe.config. (MyApp.config does also work sometimes depending upon .NET Framework versions and service packs.)

Inside that config file your settings should work.

I have tracing in my code running from VB6 via COM that is working fine.

Also is there any chance your privileges are different when running the VB6 code?

Finally, if you're debugging the VB6 app in the VB6 IDE you need to add the settings to the VB6.exe.config in the VB6.exe folder, and restart VB6 to ensure changes are noticed.

Mark Hurd
A: 

I was having a very similar problem with a .Net COM Interop DLL hosting a WCF web service call for a VB6 application. When the VB6 app called the .Net DLL it would get the no endpoint found error from the com interop DLL.

The instructions Mark gave saved me! I was very close with the MyApp.exe.config, but I was in debug mode in VB6 and it wasn't helping(never tried it compiled). After seeing Mark's response, I tried the VB6 app compiled and it worked!!!! Thanks Mark! I 'assume' the vb6.exe.config will work to... haven't tried it yet.

Mike