473,396 Members | 1,846 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Why do I need to check the version myself?

Hi,

I got bit by the fact that applications using library files that are NOT
strongly named will use older versions of the library without generating an
error, so........

Is there a way to tell an application "Use the library files you were built
with or NEWER versions" without using the GAC?

I have tried giving my library files strong names, but that locks them to
ONE version of the library file. I know that you can add lines to your
application configuration file to tell the application to use a specific
version of a new file (i.e. if you using version 1.2.0.0- 1.2.3.0 now use
1.2.4.0). However, it doesn't allow me to specifiy "USE ALL newer versions"
(e.g. if you using version 1.2.0.0- 1.2.3.0 now use 1.2.*). I have to target
ONE newer version, which means EVERY time I have an update, I would have to
update every applications configuration file with new routing information.

I can use this code at runtime to fix the problem, but I'm look for other
options:

public static bool IsOkToUseLibraries(string sDirectory, string
sLibStartsWith,
Assembly asm, out string sProblem)
{
string sFileName;
sProblem = string.Empty;

foreach (AssemblyName asname in asm.GetReferencedAssemblies())
{
if (asname.Name.StartsWith(sLibStartsWith))
{
sFileName = sDirectory + "\\" + asname.Name + ".dll";
if (System.IO.File.Exists(sFileName))
{
System.Diagnostics.FileVersionInfo fvi =
System.Diagnostics.FileVersionInfo.GetVersionInfo( sFileName);

// major.minor[.build[.revision]]
if ((fvi.FileMajorPart != asname.Version.Major))
{
sProblem = string.Format("{0}.dll -> System {1} file " +
"found by a system {2} application.\n", asname.Name,
fvi.FileMajorPart, asname.Version.Major);
}
else if ((fvi.FileMinorPart < asname.Version.Minor) ||
(fvi.FileBuildPart < asname.Version.Build) ||
(fvi.FilePrivatePart < asname.Version.Revision))
{
sProblem = string.Format("{0}.dll -> Expecting a " +
"version number greater than or equal to {1}, but found
{2}.\n",
asname.Name, asname.Version.ToString(), fvi.FileVersion);
}
}
}
}

return (sProblem == string.Empty);
}
Thanks for any suggestions,
Dave
Apr 10 '06 #1
6 2207
The behavior you describe is by design. The reason the app will use
the old version of the library is because the newer version's behavior
may not be compatiable with the older version. This is the cause of
many problems in the COM base world.

That said, you can specify using the application configuration file to
use newever versions of assemblies. Look up the bindingRedirect method
of the configuration file, that will give you information to force a
newer version of the library. Of course you would only want to do this
after you've tested your application against the newer version of the
library.

HTH
Andy

Apr 10 '06 #2
Andy,

Thanks for your response. I have looked at the bindingRedirect, but I would
have to modify the application configuration file of at least four different
application every time that I updated a library file because I can't specify
"use ALL newer files than the one you were compiled with".

Do you know if there is a way to do this in the configuration file without
naming the newer version number directly (i.e. 2.4.*)?

Dave
Apr 10 '06 #3
Dave,

I found somewhere that keeping the AssemblyVersion the same, but
changing the AssemblyFileVersion would work. Not sure if that would be
useful to you however.

Does using a wildcard in the newVersion attribute work?

Andy

Apr 10 '06 #4
> Does using a wildcard in the newVersion attribute work?

I've tried it, but it doesn't work. You can specify a range for the old
version, but you have to specifically target the new version. Like:

<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="mscorcfg"
publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
<bindingRedirect
oldVersion="0.0.0.0-65535.65535.65535.65535" newVersion="1.0.3300.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>

it would be nice if this worked:
<bindingRedirect oldVersion="1.0.0.0-1.3.2.65535" newVersion="1.3.3.*"/>
or

<bindingRedirect oldVersion="1.0.0.0-1.3.65535.65535" newVersion="1.4.*"/>

Dave
Apr 11 '06 #5
> else if ((fvi.FileMinorPart < asname.Version.Minor) ||
(fvi.FileBuildPart < asname.Version.Build) ||
(fvi.FilePrivatePart < asname.Version.Revision))


Should read:
else if ((fvi.FileMinorPart < asname.Version.Minor) &&
(fvi.FileBuildPart < asname.Version.Build) &&
(fvi.FilePrivatePart < asname.Version.Revision))
Apr 11 '06 #6
I think you'll have to go the route of only changing the
AssemblyFileVersion and keeping the value in AssemblyVersion the same.

Apr 11 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: R.Wieser | last post by:
Hello All, I'm trying to get a "Virtual Listbox" to work. I've currently got a form, and used CreateWindowExA to create a ListBox with the LBS_OWNERDRAWFIXED and LBS_NODATA flags on it. I've...
7
by: has | last post by:
<BLUSH> Careless talk costs lives, as they say. In my case, a throwaway comment that Python could trounce the notoriously underpowered and undersupported AppleScript language for "serious number...
4
by: kazack | last post by:
I posted a similiar question in this newsgroup already and got an answer which I already knew but didn't get the answer I was looking for so I am reposting the code and question differently in the...
55
by: Alex | last post by:
Hello people, The following is not a troll but a serious request. I found myself in a position where I have to present a Pro/Con list to management and architects in our company with regard to...
3
by: TK | last post by:
Excuse me for multiple posting because I've posted this message to aspnet.security NG but have not got any response yet. I'm building an ASP.NET application works in Forms Authentication mode...
15
by: Cheryl Langdon | last post by:
Hello everyone, This is my first attempt at getting help in this manner. Please forgive me if this is an inappropriate request. I suddenly find myself in urgent need of instruction on how to...
4
by: georges the man | last post by:
hey guys, i ve been posting for the last week trying to understand some stuff about c and reading but unfortunaly i couldnt do this. i have to write the following code. this will be the last...
1
by: GS | last post by:
I am still a novice in vb .net 2. actually in vb.net period. please bear with me. Problem: I often found myself refereeing to common utility like setStatus and logs on the form, and the...
6
by: Pavel | last post by:
Hello, Does anyone know a (preferably open-source) multi-platform C or C++ library that would be able to write and read C/C++ doubles and floats to/from streambuf, char array or similar device...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.