Click here to Skip to main content
15,877,446 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
AnswerRe: FileInfo.LastWriteTime(-12) is fetching Files modified long time back Pin
Jochen Arndt9-Mar-17 0:28
professionalJochen Arndt9-Mar-17 0:28 
AnswerRe: FileInfo.LastWriteTime(-12) is fetching Files modified long time back Pin
Richard Deeming9-Mar-17 0:58
mveRichard Deeming9-Mar-17 0:58 
GeneralRe: FileInfo.LastWriteTime(-12) is fetching Files modified long time back Pin
indian1439-Mar-17 8:09
indian1439-Mar-17 8:09 
QuestionNeed to write an Outlook Email in which body contains information a Table format Pin
indian1435-Mar-17 12:17
indian1435-Mar-17 12:17 
AnswerRe: Need to write an Outlook Email in which body contains information a Table format Pin
Dave Kreskowiak5-Mar-17 14:45
mveDave Kreskowiak5-Mar-17 14:45 
AnswerRe: Need to write an Outlook Email in which body contains information a Table format Pin
Gerry Schmitz6-Mar-17 9:00
mveGerry Schmitz6-Mar-17 9:00 
GeneralRe: Need to write an Outlook Email in which body contains information a Table format Pin
indian1438-Mar-17 23:51
indian1438-Mar-17 23:51 
QuestionFaking AppDomain.CurrentDomain.BaseDirectory, is this way too bad? .net/c# Pin
User 110609793-Mar-17 6:08
User 110609793-Mar-17 6:08 
Dear experts

The task I need to solve
For a legacy C++ application -let's call it NativeW32App.exe- I need to use an third party SDK to control an USB device and this SDK is only available as a .net assembly.
The whole SDK consists of about 70 assemblies and one of them -let's call it ThridPartyNetSDK - represents the interface for me.

The approach I go is, I implement a proxy in .net which is COMVisible and can be easely consumed by the C++ application.
So far everything works fine as long as the whole bunch of SDK assemblies is available in the directory from where the NativeW32App.exe is startet. And this (all assemblies in the app's directory) I try to avoid because it is one of about 50 SDK (from different third parties) we need to support.

So my next step was/is
Separate the SDK assemblies and my COMVisible proxy in a separate directory and hook into assembly resolving...
C#
AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(SDK_AssemblyResolve);
... where I load the assemblies from the separate directrory in my SDK_AssemblyResolve.

The problem
It seems, that the SDK itself is loading some DLLs dynamicaly relative to the AppDomain.CurrentDomain.BaseDirectory which is
my NativeW32App.exe's startup directory.

The dirty (?) solution
I'm faking AppDomain.CurrentDomain.BaseDirectory in my proxy assembly class ctor
C#
// Very (?) dirty way to fake  BaseDirectory
AppDomain.CurrentDomain.SetData("APPBASE", Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location));

Now finally this works, but I have my doubts
a.) According to the MSDN documentation setting system values (and I assume "APPBASE" is one) should have no effect. But it works fine so far Confused | :confused:
b.) I assume this can have side effects and is not appropriate for production
c.) It seems that there are better way, e.g. creating the AppDomain by myself. But I have no idea how to manage this for a COM assembly consumer.

Is AppDomain.CurrentDomain.SetData dirty or not reliable for production?
Does anybody has a hint to solve it in a better way, maybe with seperate AppDomain or what else?

Thank you very much in advance for your comments.

modified 19-Jan-21 21:04pm.

AnswerRe: Faking AppDomain.CurrentDomain.BaseDirectory, is this way too bad? .net/c# Pin
Gerry Schmitz3-Mar-17 7:06
mveGerry Schmitz3-Mar-17 7:06 
GeneralRe: Faking AppDomain.CurrentDomain.BaseDirectory, is this way too bad? .net/c# Pin
User 110609793-Mar-17 7:09
User 110609793-Mar-17 7:09 
GeneralRe: Faking AppDomain.CurrentDomain.BaseDirectory, is this way too bad? .net/c# Pin
Gerry Schmitz3-Mar-17 8:59
mveGerry Schmitz3-Mar-17 8:59 
GeneralRe: Faking AppDomain.CurrentDomain.BaseDirectory, is this way too bad? .net/c# Pin
User 110609793-Mar-17 9:07
User 110609793-Mar-17 9:07 
Questionc# Pin
rationcard20-Feb-17 0:52
rationcard20-Feb-17 0:52 
AnswerRe: c# Pin
Pete O'Hanlon20-Feb-17 1:10
mvePete O'Hanlon20-Feb-17 1:10 
GeneralRe: c# Pin
Richard Deeming20-Feb-17 2:06
mveRichard Deeming20-Feb-17 2:06 
GeneralRe: c# Pin
Pete O'Hanlon20-Feb-17 2:16
mvePete O'Hanlon20-Feb-17 2:16 
AnswerRe: c# Pin
Patrice T21-Feb-17 13:12
mvePatrice T21-Feb-17 13:12 
GeneralRe: c# Pin
Dave Kreskowiak21-Feb-17 13:32
mveDave Kreskowiak21-Feb-17 13:32 
GeneralRe: c# Pin
Patrice T21-Feb-17 14:41
mvePatrice T21-Feb-17 14:41 
GeneralRe: c# Pin
Dave Kreskowiak21-Feb-17 16:10
mveDave Kreskowiak21-Feb-17 16:10 
GeneralRe: c# Pin
Patrice T21-Feb-17 16:25
mvePatrice T21-Feb-17 16:25 
GeneralRe: c# Pin
Dave Kreskowiak21-Feb-17 16:51
mveDave Kreskowiak21-Feb-17 16:51 
GeneralRe: c# Pin
Pete O'Hanlon21-Feb-17 21:05
mvePete O'Hanlon21-Feb-17 21:05 
GeneralRe: c# Pin
Dave Kreskowiak22-Feb-17 3:06
mveDave Kreskowiak22-Feb-17 3:06 
GeneralRe: c# Pin
Pete O'Hanlon22-Feb-17 3:15
mvePete O'Hanlon22-Feb-17 3:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.