I have a dll. That dll is uploaded on a server. I want that each time the application starts to get the "latest" dll from the server, so I've used the following code in my app.config. Why isn't it working?
here is the app.config file:
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="ReflectionTest"
publicKeyToken="f94c9b9f0707ee96"
culture="neutral" />
<codeBase version="1.0.0.0"
href="http://127.0.0.1/ReflectionTest.dll"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
First, you may be on the wrong track. Even if you didn't change the version, your application may end up using an older copy of the assembly.
Assuming a valid URI in your <codebase> element, when your application runs for the first time, the runtime will not find the assembly in until it probes your codebase. Then, it will download the assembly to the GAC. When your application runs again, the runtime will find that assembly in the GAC, so it will not need to probe for it.
Instead of using <codebase>, consider using Reflection. Specifically, you might want to use Assembly.LoadFrom(assemblyUri) in your application, getting the URI from an application setting. From there, you'd create objects using the Reflection API, particularly using Activator.CreateInstance<T>().
As for getting that assembly from your server is concerned, make sure that your DLL is in the right location and that your web server is running and properly configured.
Is your .dll actually available at that location? Are you serving it up through some web application?
If you type that URL into a web browser, does it let you download or open that file?
Related
I have a visual studio project with is running absolutely fine.
But a new client requirement comes up for deployment for placing the different dlls in different folders.
We have a framework dll which can be used in a different project. There are some third-party dlls on which this framework dll depends upon. So when I use this dll from my project every dependent dll is copied to my local on the build as CopyLocal property is true.
But now with new requirement we can not have CopyLocal property set as True. The client wants no local copy of any dll, rather he wants framework related dll in some location. When I am doing this the dependent DLL's are not getting loded.
I know I have two options:
I can put them in GAC, but I don't want to do this as I want them to support xcopy.
Using reflection(But I am not sure of this that is this the right approach)
Can we do anything using configurations??
You can configure assembly probing paths using the <probing> configuration element:
Specifies application base subdirectories for the common language runtime to search when loading assemblies.
Example from MSDN:
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="bin;bin2\subbin;bin3"/>
</assemblyBinding>
</runtime>
</configuration>
However, if the assemblies in question reside outside the application base ("which is the root location where the application is being executed"), you have the <codeBase> configuration element:
Specifies where the common language runtime can find an assembly.
Example from MSDN:
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="myAssembly"
publicKeyToken="32ab4ba45e0a69a1"
culture="neutral" />
<codeBase version="2.0.0.0"
href="http://www.litwareinc.com/myAssembly.dll"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
For the exact details of how the runtime locates assemblies you can refer to this MSDN article.
As OP pointed out, unfortunately codeBase element is a usable option for strong named assemblies only. For private assemblies you need a workaround. Some viable ideas can be found in this discussion such as:
file system links (NTFS junction point) + probing element or AppDomainSetup.PrivateBinPath
AppDomain.CurrentDomain.AssemblyResolve event
I've tested the latter and can confirm it works:
AppDomain.CurrentDomain.AssemblyResolve += (s, e) =>
Assembly.LoadFile(Path.Combine(Settings.Default.AssemblyPath, Path.ChangeExtension(e.Name.Substring(0, e.Name.IndexOf(',')), ".dll")));
I've a dll with 2.0.0.1 version in one server which can be downloaded by accessing http://someipaddress/assembly/test.dll and I'm having another application which need to download this test.dll and have to access those methods.
When surfing for this, i've got three different methods to do,
1. Assembly.LoadFrom()
2. Assembly.LoadFile()
3. Assembly.Load()
I've tried Assembly.LoadFrom("http://someipaddress/assembly/test.dll")
Now i've replaced test.dll with 2.0.0.2 version and
What will happen the application download 2.0.0.2 test.dll and already downloaded test.dll 2.0.0.1.
Application which dll will refer?
Will it use existing test.dll 2.0.0.1 since its already downloaded while accessing test.dll 2.0.0.2?
Please suggest on this.
It'll depend on how you're referencing the assembly. By default if there's no binding redirect, your new dll will cause an exception. You can get around this by specifying an binding redirect rule in your application's configuration file like so;
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Test" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.0.0.2" newVersion="2.0.0.2" />
</dependentAssembly>
</assemblyBinding>
</runtime>
But you'd need to update it upon getting the new version of the dll.
I am new in C#.
I have created a small windows application with a reference to a my other project dll file that is included in the setup file. I have forwarded the setup to the client.
Now I have few changes in my other project dll.
How do I update this Dll in Client System or How Do I create the patch for the my application with new DLL?
Please help?
NOTE:- I have use Standard Setup Project to create the Setup File.
There are two ways, I can think of immediately:
If you have access to client system, just replace the new dll in the physical load path, assuming this is not a GAC dll and the new dll will get loaded at the runtime
If the assembly is installed in GAC then use something like this in the App.config:
<dependentAssembly>
<assemblyIdentity name="Microsoft.WindowsAzure.ServiceRuntime" publicKeyToken="31bf3856ad364e35"
culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.5.0.0" newVersion="2.5.0.0" />
We have windows service application which is using Aspose.Words.NET version 11.10.0 Now we have recently upgraded the Aspose.Words dll version latest 13.7.0
Since we have already deployed our windows service applications in multiple clients, we tried replacing the old Aspose.Words dll with latest its latest version. But when we restart the existing windows application it doesn't work with the replaced latest Aspose.Words dll.
We have resolved it by recompiling the whole windows application referencing the latest version of Aspose.Words dll. Are we required to recompile and redeploy our whole windows service application every time we upgrade the Aspose.Words dll?
Check this answer on SO too.
You need to update the config files of the desktop/web clients as follows.
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<publisherPolicy apply="no" />
<assemblyIdentity name="Aspose.Words" publicKeyToken="716fcc553a201e56" />
<bindingRedirect oldVersion="11.0.0.0-13.6.0.0"
newVersion="13.7.0.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
Please also note that there might be breaking changes in API which might lead to other errors. For example a method or property which existed in 11.0 is deleted in 13.7. The exception will be thrown when the client application calls the specific method/property. So, you must verify in development environment that the new version will not break your application. If it works, then you can just replace the old DLL with new version.
The config file is loaded at runtime, so you can update the config files where your applications are deployed.
I work for Aspose as a Developer Evangelist.
I am trying to use JSON.NET and after including the .dll and trying to use one of the methods I get this error:
Could not load file or assembly 'Newtonsoft.Json.Net35, Version=4.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The system cannot find the file specified.
Any know why I might be this error?
Two things to check:
(1) You may have to "Unblock" the DLL. By default, when you download a .zip file from the Internet, that file, and all .dll or .exe files extracted from that .zip file, are given a file system attribute that prevents them from loading and executing. Right-click on the DLL in Windows Explorer, choose "Properties", and in the resulting dialog box click on the "Unblock" button. Or better yet, do that for the .zip file, and then re-extract all the files.
(2) The Newtonsoft JSON.NET library comes in five flavors: one each for .NET 2.0, 3.5, 4.0, Silverlight, and Windows Phone. You need to use the right one for your particular environment. I presume that this is a .NET 3.5 project?
In my case, I resolved this problem once I realized that a library that I was using was itself using the Json.NET but with the earlier version (3.5). Linking the second library to the new Json.NET version solved the issue.
Hope this helps.
You need to download release 1 instead of release 2 of the Newtonsoft.Json.
try to add assembly binding redirect to app config like:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.5.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
Related posts:
System.IO.FileNotFoundException
At least one module has an unresolved import
Debugging tests that require an external dll