I had a project whose framework is 3.5 and i converted it to 4 and when i faced a problem of mixed mode. i changed the useLegacyV2RuntimeActivationPolicy from this answer
Now when i install my application to program files and try to run it, it crashes but when i place the config file beside my exe it runs.
Can anyone tell my the reason of that crash?
but when it was 3.5 i didn't need to place the app.config file beside the exe
That was required in 3.5 as well. It is the only way that the CLR can find the .config file. I'd have to guess that you somehow got away with it before and it just didn't matter. But now it is critical to let the CLR find the .config file since you really need that attribute to allow the mixed-mode assembly to load.
An obvious way ahead is to rebuild the C++/CLI assembly and have it target v4 as well. So you won't need the .config file anymore. If it is not yours then ask the vendor or author of the assembly for an update.
Related
I need to make API calls to methods in an EXE provided by a software company. In the past very old .Net version, I was able to make it work by renaming the exe to dll (I guess?). This time around the EXE they have provided seems to have been compiled in 4.6.1. I am not able to make it work and it causes runtime errors:
"Could not load file or assembly... A strongly-named assembly is required"
What are my options? Is it still possible to make API calls to an EXE whether or not I rename it to a DLL? Or Should I ask them to provide me a proper DLL?
Thank you.
Thanks to #vasily.sib and the following link, I was able to resolve this issue.
I can in fact reference any EXE assembly in the project and call methods on it. An EXE (and for that matter a DLL) can be strong named and signed by anyone, and not just by the developer who has the source code for that EXE. See the following link for details.
Thank you.
https://chrisbenard.net/2009/07/16/strong-name-an-assembly-without-source-code/
For some reasons I had to change the assembly name(.exe). Since .net settings are saved using assembly name. Framework cannot find the proper .config file that usually exists in [USER]/AppData/Local, hence when calling the Upgrade on Settings.Default does no upgrade. Which is working as intended by Framework. But since the assembly Guid is same, is there any possible flag that allows to use a specific assembly name for checking the Settings file.
My solution is to rename the directories of Setting file before calling the Upgrade or manually reading the old .config file and update each setting. But its just a mess.
I'm using .net framework 2.0
Any help would be nice.
Thank you
I am getting this error:
Could not load file or assembly, system could not find the file specified.
Images:
http://s30.postimg.org/4x936f6ch/error2.png
http://s17.postimg.org/41ta9aaj3/errro3.png
I have a solution built in .NET 4.0
In it I have projects that act as plugins. They use dlls and the issue is that one of the solutions projects dlls is being called, and that references the dll that is causing the issue.
I get no error when rebuilding etc just when the program gets to the part where it uses the dll that references this one.
I have also made sure that in the projects bin folder that it has the dll that it is complaining about.
I have opened the dll in reflector and I don't think it has any issues.
COuld someone point me to the next step to try with fixing this issue?
Thanks!
Couple of tips - hard to know if they'll help you:
Open the csproj file(s) in a text editor and see where the dlls are being referenced (GAC possibly)
If it's a signed assembly, make sure you've got a signed copy (if you've built an Open Source project yourself the signing will be lost)
Look at the references in Visual Studio - do you have Copy Local set to True and Specific Version set to False?
Look at you're App.config or Web.config - is there a binding redirect that failing to load
I remember reading a post about assemblies not being able to be unloaded - probably not an issue on this one but I think the trick was
to load the DLL in a separate AppDomain to keep it isolated - loadable
and unloadable.
I have written a small program with a reference to a dll file that will be included in the setup file.
What I still need is a way to update the dll (in case I change some functions), without the need to re-download the whole program again, just replace the dll file...
Is this possible ?
I just read somewhere that I have to update the xml file with the new dll version, but I really need the full steps to update the dll successfully...
Any help is really appreciated... Thanks a lot
Update
I really don't know what to say... Both ways are really great... Thanks a lot for the help... I will test them tonight and write the answer here...
Thanks again :)
If you already distributed your application, you can redirect the assembly binding by configuration.
You can redirect an assembly binding
reference to another version of an
assembly by using entries in the
application or machine configuration
files. You can redirect references to
.NET Framework assemblies, third-party
assemblies, or assemblies of your own
application.
http://msdn.microsoft.com/en-us/library/2fc472t2%28VS.71%29.aspx
Another article about Configuring Assembly Binding Redirection.
When you add a reference to a DLL, the visual studio takes binds it to the specific version (in case of 'Copy local' is true). Go to visual studio project, select the reference and view properties. You will see a property as 'Specific version'. The value will be true, set it to false. You have got what you wished.
I have created a dll that will be used by multiple applications, and have created an installer package that installs it to the program files, as well as adds it to the Global Assembly Cache.
The dll itself uses log4net, and requires a xml file for the logging definitions.
Therefore when the installer is run, the following files get copied to the install directory within program files:
The main dll that I developed
- The Log4Net.dll
- the Log4Net.xml file
I am now experiencing a problem. I have created a test console application for experimentation. I have added my dll as a reference, and set the 'local copy' flag to false.
When I compile the test console exe however, I noticed that it has copied the log4net.dll and log4net.xml files to the bin directory. And when running the test console, it appears that it will only work if the log4net.dll is in the same directory as the exe. This is dispite the fact that the test console application does not use log4net, only the dll that was added as a reference does.
Is there some way to have it so that the log4net.dll & xml files used will be the ones that were installed to the program files, rather than any application needed to copy over local copies? The applications that will be using my dll will not be using log4net, only the dll that they are referencing uses it.
Many thanks
Don't install into the Global Assembly Cache! Even if your library dll is used by multiple applications each should have it's own local copy. Otherwise you get into a whole world of pain for saving a few KB of disk space.
Always copy the required dlls locally. If you are really sure that the application won't need it you can simply delete the unnessesary dlls later or don't include them in the installer. But if your application will call ANY reference there it will crash at runtime. So best option is to leave them there (after all they WERE referenced for a reason).
No, it's not possible (at least not without much efford) to have .Net load dlls from arbitrary locations on the disk. And it should be this way (look up DLL-hell if you want to know why).
I suspect your problem is the configuration. You must use fully qualified names if you want it to work from the GAC. As per the documentation at http://logging.apache.org/log4net/release/faq.html:
"When loading an assembly from the GAC the fully qualified assembly name, including the version, culture and public key must be specified. This is in the standard syntax supported by System.Type.GetType. See the next FAQ on how to get the version and public key for an assembly."
I managed to resolve this by adding Log4net.dll to the GAC as well. It will now run without needing a local copy the dll.
It does however require a local copy of the XML file, to correctly log.