DLL Hell with Entity Framework and Lucene - c#

I have an ASP.NET MVC 4 project that I need to update to use Lucene 3.0. I needed to manually set the framework to use .NET Framework 4.5 because I'm using the latest Windows Azure libraries which require this version. Everything is working, except when I add a new data model with the Entity Framework. I can successfully add a new data model with the Entity Framework. However, when I attempt to execute a basic stored procedure (it only executes a query), I get a runtime exception. The exception is:
System.Reflection.ReflectionTypeLoadException
Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
When I look at the LoaderExceptions property, I see the following:
[0] {"Could not load file or assembly 'Lucene.Net, Version=2.9.4.1, Culture=neutral, PublicKeyToken=85089178b9ac3181' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)":"Lucene.Net, Version=2.9.4.1, Culture=neutral, PublicKeyToken=85089178b9ac3181"} System.Exception {System.IO.FileLoadException}
[1] {"Could not load file or assembly 'Lucene.Net, Version=2.9.4.1, Culture=neutral, PublicKeyToken=85089178b9ac3181' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)":"Lucene.Net, Version=2.9.4.1, Culture=neutral, PublicKeyToken=85089178b9ac3181"} System.Exception {System.IO.FileLoadException}
The oddity is, I can't find a single reference to Lucene.Net version 2.9.4.1 anywhere. I do reference the 3.0.3.0 version of Lucene.Net in my app. Can someone tell me where the 2.9.4.1 version of the file would be referenced? I've looked in the following locations:
MyProject.csproj
Web.config
Global.asax.cs
packages.config
How do I fix this? I've been beating my head on this for 2 days. Its so bizarre. Thank you so much for any help that can be provided.

I know not exactly an answer to the question, but if it truely does stump you (and you're lucky enough that the two versions are compatibly) you can redirect any requests for 2.9.4.1 to the version you do have by adding a binding redirect to your config file.
see : http://msdn.microsoft.com/en-us/library/433ysdt1.aspx

Related

NET core - Could not load file or assembly 'System.Runtime, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a ', .NET 6

I have converted .NET Framework 3.5 TestAPP to .NET 6 TestAPP and worked well.
i have an Automation project(C++ project) which was using .NET Framework 3.5 TestAPP.dll to run the tests, but right now i have replaced the .NET Framework 3.5
.dll with .NET 6 TestAPP i.e. TestAPP.dll
when i ran the exe in command line , i have got an error as
"Unhandled Exception: System.IO.FileLoadException: Could not load file
or assembly 'System.Runtime, Version=6.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The
located assembly's manifest definition does not match the assembly
reference. (Exception from HRESULT: 0x80131040)"
Please let me know if anything needs to be corrected.
Resolved the error by changing the C++/CLI properties from visual studio project properties , which was referring to .NET framework earlier and i have changed the property as .NET core runtime(clr:netcore) and it is internally handled all GAC changes and worked well.
Hope it might help someone .
When upgrading an app to a later .NET version, edit your csproj file and make sure there is no <RuntimeFrameworkVersion> node in there that someone may have inserted manually.
This will not be updated automatically when switching .NET versions
The running project returned this error. When I changed it to the way in the image, the error was solved.
Project>Properties
In my case the error was due to worng Default Project in Package Manager Console, if you are running EF migrations or something that is in a project that need to get info from the API make sure you are targetting the right project, also try clean + build first.

How to fix source-code generator with .NET 6?

I ported my .NET 5.0 application to .NET 6.0 and now I found that the source-code generator fails. It shows the following error:
Generator 'PermissionGenerator' failed to generate source. It will not contribute to the output and compilation errors may occur as a result. Exception was of type 'FileNotFoundException' with message 'Could not load file or assembly 'System.Collections.Immutable, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.'
Adding <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies> to the property-group of the generator's project-file didn't really help. It does add System.Collection.Immutable.dll to the output folder (6.0.21.52210), but I still get the same error.
My generator is a .NET Standard 2.0 project, which might not be necessary anymore with .NET 6. So I also tried setting the runtime for the generator to .NET 6. This failed with another error:
An instance of analyzer ... cannot be created from ... Could not load file or assembly 'System.Runtime, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
It seems that this is an issue with Paket v6 that seems to have a problem when used in conjunction with source-generators. I now use the traditional approach (including the analyzers directly in the project-file) and it now works again. I filed an issue with Paket (link).
I fixed this issue in my project by downgrading Microsoft.CodeAnalysis.CSharp to version 4.0.1. I guess newer versions have an issue finding System.Collections.Immutable.
This is with my source generator on netStandard2.0 and the project the source was being generated for on net6.0.

Microsoft.Bcl.Async trying to load System.Threading.Tasks 1.5.11.0

I've added Microsoft.Bcl.Build/Microsoft.Bcl and Microsoft.Bcl.Async to some projects in my solution where I want to use async/await.
Everything works fine on my machine with .Net4.5 installed. However, when I start the application on a machine with only .Net4 installed, at some point, the application crashes with the following Exception:
Could not load file or assembly 'System.Threading.Tasks, Version=1.5.11.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
Looking at the StackTrace, the exception seems to be generated in a third party library that we reference.
When I analyze the Microsoft.Threading.Tasks.dll provided by Microsoft.Bcl.Async, I see that it does reference System.Threading.Tasks Version 1.5.11.0, but version 2.6.10.0 is included in Microsoft.Bcl.
Am I doing something wrong?
I found the solution! It was actually very simple. I just had to copy and paste the binding redirects that nuget adds in the app.config files into the *.exe.config file. Then it just magically works. Easy fix.

IBM.Data.DB2 FileNotFound Loading Microsoft.ReportingServices.Interfaces

I have a ASP.Net application which references an assembly with some re-usable code (common utils, data access, etc.). The assembly references IBM.Data.DB2.dll. However, I am not using DB2 in my application, the IBM.Data.DB2.dll is simply a dependency (in case an app needs to connect to DB2). Recently, i've run into the following error:
System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.ReportingServices.Interfaces, Version=10.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' or one of its dependencies. The system cannot find the file specified.
File name: 'Microsoft.ReportingServices.Interfaces, Version=10.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91'
System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
at System.Reflection.RuntimeModule.GetTypes()
at System.Reflection.Assembly.GetTypes()
at Unity.AutoRegistration.AutoRegistration.<ApplyAutoRegistration>b__5(Assembly a)
at System.Linq.Enumerable.<SelectManyIterator>d__14`2.MoveNext()
at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
at Unity.AutoRegistration.AutoRegistration.ApplyAutoRegistration()
The only file in the entire application that contains Microsoft.ReportingServices.Interfaces is the IBM.Data.DB2.dll file. I do not have any need of SQL Server or the overhead of a SQL Server installation locally much less on the server when the app is deployed. Bear in mind I am required to use the assembly which has the dependency on IBM.Data.DB2.dll and this error has not happened in the past, it seems to be recent.
I have tried binding redirects, installed Microsoft.ReportingServices.Interfaces via Nuget all to no avail.
Would anyone know why this error is occurring and more importantly....how to resolve it?
If IBM.Data.DB2.dll references Microsoft.ReportingServices.Interfaces, you will probably have to manually copy Microsoft.ReportingServices.Interfaces.dll into your bin folder. Here is a post that can help you with that:
Microsoft.ReportingServices.Interfaces.dll missing for SSRS 2005

Updating assembly causes error

I updated a single 3rd party assembly, and I am getting an error:
Could not load file or assembly 'Some.Assembly, Version=1.0.3.15922,
Culture=neutral, PublicKeyToken=62a6874124340d6e' or one of its dependencies.
The located assembly's manifest definition does not match the assembly reference.
(Exception from HRESULT: 0x80131040)
When I updated this assembly, the version is now 1.0.3.23655.
Is it because of a strong named assembly that other dependent assemblies are complaining about?
It's the version. You either need to rebuild (assuming that the dependent assemblies are yours), or if you are positive that the new version is compatible, you can configure .net to use the newer assembly. Details here: http://msdn.microsoft.com/en-us/library/7wd6ex19(VS.71).aspx
Yes this is what it is complaining about.
Please look here and here to guide you in resolving your versioning issue. Is your assembly signed using strongname?
Hope this helps.

Categories