this is actually a follow up to a question I asked yesterday about problems with using older DLLs in Visual C# 2010. I have added the configuration file and the DLL runs well. The issue I'm having is that I would like to avoid having my entire project run in legacy mode.
I have gone around this by creating a new console project with command line access to all the functions I 开发者_开发知识库need from the DLL and read the output in my main project. This way it acts as a separate component, and I don't have to worry about legacy mode affecting anything in my main project.
The problem is that I feel as though this will really slow down my application in the long run, and since what I am developing needs to be fast, I was wondering if there is another approach to doing this. As I mentioned in the previous question, I cannot rebuild the DLL in 4.0.
Thanks,
PM
Sounds like you really misunderstand what that setting means. It most certainly doesn't mean that your project "runs in legacy mode", it is the exact opposite. The .NET 4.0 CLR version will be used by your old DLL with that setting. Instead of the new policy available in 4.0 that allows it to run with an old version of the CLR. Also known as in-process side-by-side feature. The new policy however doesn't support mixed-mode assemblies, that's why it complained.
You really don't want run it in a separate .exe with command line redirection, that's horrible. It is not only slow, it will make your app unreliable when the 'host' process dies on an unhandled exception but your main app doesn't notice. Very hard to diagnose.
It depends how frequently you call into it. If rarely, a process should be fine. If you call it a lot, then a lot of time is going to be spent on process-creation, reloading the dlls etc. You might improve this a bit by running NGEN on the console app, but I suspect a better option might be some basic IPC comms to a long-running exe or service. But keep the comms lightweight.
Another question is: have you profiled the process-based approach to see if this is actually an issue?
精彩评论