By the property name (Specific Version), I would think that if an assembly complied, then later a newer DLL is dropped in, then if resolved to that DLL it would still load and work even though it has a different version than the original DLL that was referenced. I am using VS 2022. This has worked in the past, so I am not sure if something has changed.
Part of my assumption was based on this SO thread. The original thread is over 8 years old and the most recent comment which might be my issue said open a new topic. :-) How exactly does the "Specific Version" property of an assembly reference work in Visual Studio? The screenshot is for context, to make sure the property I am talking about.
Let me try to anticipate some of the questions. This may be in the more info than you care. This exe is running on over 900 devices. I have used Xcopy app management for a long time. All of the apps are in a few directories. I have a resolve function for DLL to keep from fighting the GAC, cache, etc. Basically, it is a handler for the " AppDomain.CurrentDomain.AssemblyResolve". I will include the code snippet, basically it just calls itself recursively through certain directories till the DLL is found. This works for the most part. They can not find the DLL error that happens even before the 'Sub Main()' starts. I guess since the app is in the same directory as the DLL, it assumes the DLL is not right because of the DLL version. Just guessing. Of course, if I remove all the DLL references and then re-add them works. The reason why I was hoping is that the set "Specific Version" would work, I was hoping to avoid recompiling all the apps that reference the DLL(s).
This code is what sets up the handler.
AddHandler AppDomain.CurrentDomain.AssemblyResolve, AddressOf ResolveAssembly
This is what is executed.
Public Function ResolveAssembly(ByVal sender As Object, ByVal args As ResolveEventArgs, Optional ByVal pPath As String = Nothing) As Reflection.Assembly
'BuildLogOutput("ResolveAssembly - " & args.Name)
Dim resourceName As String = New Reflection.AssemblyName(args.Name).Name & ".dll"
If resourceName.Contains("&") Then Return Nothing
If resourceName.ToLower.Contains(".resources.") Then Return Nothing
Dim AssemblyPath As String = ""
pPath = DLLSearchPath(pPath)
Dim returnedassembly As Reflection.Assembly = Nothing
If pPath.Length > 0 Then
AssemblyPath = Path.Combine(pPath, resourceName)
If IO.File.Exists(AssemblyPath) Then
returnedassembly = Reflection.Assembly.LoadFrom(AssemblyPath)
Else
returnedassembly = ResolveAssembly(sender, args, pPath)
End If
Else
Throw New IO.FileNotFoundException("ResolveAssembly - Could not load Assembly: " & resourceName, AssemblyPath)
End If
If returnedassembly Is Nothing Then
Throw New Exception("ResolveAssembly - Unexpected failure to load: " & AssemblyPath)
End If
Return returnedassembly
End Function
Public Function DLLSearchPath(Optional ByVal LastPath As String = "") As String
Dim PathList() As String = Environment.GetEnvironmentVariable("Path").Split(";"c)
If LastPath = "" Then
Return AppPath
ElseIf LastPath = AppPath Then
Return SystemPath
ElseIf LastPath = SystemPath Then
Return "c:\user\braums\com"
ElseIf LastPath = "c:\user\braums\com" Then
If PathList.Length > 0 Then
Return PathList(0)
Else
Return ""
End If
Else
For xLoop As Integer = 0 To PathList.Count - 1
If LastPath = PathList(xLoop) Then
If xLoop + 1 <= PathList.Count - 1 Then
If PathList(xLoop + 1).ToLower = SystemPath.ToLower OrElse
PathList(xLoop + 1).ToLower = "c:\user\braums\com" OrElse
PathList(xLoop + 1).ToLower = AppPath.ToLower Then
LastPath = PathList(xLoop + 1)
Continue For
End If
Return PathList(xLoop + 1)
End If
End If
Next
End If
Return ""
End Function