FluentNhibernate, Nhibernate.Search and Lucene.Net version - lucene.net

I created a project, and used NuGet to install Nhibernate.Search. During the installation NuGet also downloads the Lucene.Net for me.
With NuGet I have following packages downloaded and installed
FluentNHibernate.dll: 1.3.0733
NHibernate.dll: 3.3.1.4000
NHibernate.Search.dll: 2.0.2.4000
Lucene.Net.dll: 2.9.4.1
All the dependencies are managed by NuGet. But when I ran following codes
using FluentNHibernate.Cfg;
using FluentNHibernate.Cfg.Db;
using NHibernate;
using NHibernate.Search.Event;
using NHibernate.Search.Store;
namespace Test {
public class NHibernateSearchSessionProvider {
private static ISessionFactory sessionFactory;
private static object syncRoot = new object();
public static ISessionFactory SessionFactory {
get {
lock (syncRoot) {
if (sessionFactory == null) {
sessionFactory = createSessionFactory();
}
return sessionFactory;
}
}
}
private static ISessionFactory createSessionFactory() {
var config = Fluently.Configure()
.Database(MsSqlConfiguration.MsSql2008
.ConnectionString(c => c.FromConnectionStringWithKey("HomeDB"))
)
.Mappings(m => m.FluentMappings.AddFromAssemblyOf<UserAccountMap>())
.BuildConfiguration();
// Add NHibernate.Search listeners
config.SetListener(NHibernate.Event.ListenerType.PostUpdate, new FullTextIndexEventListener());
config.SetProperty("hibernate.search.default.indexBase", "~/LuceneIndex");
return config.BuildSessionFactory();
}
}
}
An exception message Could not load file or assembly 'Lucene.Net, Version=2.9.2.2, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
It looks like this version of NHibernate.Search is still using Lucene.Net 2.9.2.2 not the new one. I can always manually fix all the dependencies, but I prefer to use NuGet.
Anybody has experience how shall I do to make code work?
Thanks for any suggestion

This looks like a configuration error for the NHibernate.Search nuget package, it states that it supports Lucene.Net 2.9.2.2 and up. Try modifying your packages.config file to use the 2.9.2.2 version of Lucene (instead 2.9.4.1) and nuget will use the specified version during package restoration.
You will probably need to clean out your bin-folder to remove the "old" 2.9.4.1 assembly.

use Install-Package NHibernate.Search.MB
I tried to fix it but it did not.
Already Nhibernate.Search very old

Related

Blazor component - Failed to fetch dynamically imported module when packed in nuget

I created a blazor component that loads an isolated js interop file (target framework .Net 7)
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
var dotNetObjRef = DotNetObjectReference.Create(this);
_routeMapModule = await JsRuntime.InvokeAsync<IJSObjectReference>("import", "./_content/MyComp/MyJs.js");
await _routeMapModule.InvokeVoidAsync("CompInit", _elRef, dotNetObjRef);
}
}
MyComp is the ProjectName so the path to get the file is "./_content/MyComp/MyJs.js".
As long as I use this component as a project reference (blazor server), everything works fine.
But as soon as I package this component in a Nuget (azure pipeline), and reference it in the project (instead of a project reference), I get "Failed to load resource: the server responded with a status of 404 () / Failed to fetch dynamically imported module when packed in nuget".
When I check the nuget in my local nuget storage (unziping it), I find the js file in the root but if I search it in the main app generated bin, it is not there.
Is there a specific parameter for the Nuget deployment ?
I tried to create the nuget directly from visual studio and/or to modify the generation parameters on Azure.
The final nuget contains the js resource file but it does not seem to be published in the main project (the one that references the nuget).
Also tried to move the file referenced in wwwroot but same problem.
What's weird is that everything works fine as long as I'm in "project reference" mode but the path "./_content/MyComp/MyJs.js" doesn't seem to follow when it's packaged in a nuget.
Any idea ?
Main Blazor App: https://jmpnet.visualstudio.com/JmpNetPublic/_git/MainBlazorApp
Blazor component App: https://jmpnet.visualstudio.com/JmpNetPublic/_git/MyComp
Nuget Feed for Blazor component App:
Name: JmpNetPublic
Source: https://jmpnet.pkgs.visualstudio.com/JmpNetPublic/_packaging/JmpNetPublic/nuget/v3/index.json
Update (29.12.2022):
I have no problem to load the module as long as I stay in project reference (with or without lazy loading).
The problem happens only when the component is packaged in Nuget.
When deploying the Nuget, the js file does not follow.
It seems to be mostly a Nuget packaging issue (via Azure) but I can't find the settings that force the deployment of the js file.
OK. The problem was with the Azure Pipeline configuration.
if I generate the nuget directly on my workstation and push it, everything works fine.
But as soon as I did the generation using an Azure pipeline, the js file was no longer deployed.
I was actually using YAML Nuget commands (targeting .net framework) with a .Net Core project.
Now that I use ".Net Core" YAML , everything works correctly.
Lazy load the module:
public partial class TestComp : ComponentBase, IAsyncDisposable
{
[Inject]
private IJSRuntime JsRuntime { get; set; }
private readonly Lazy<Task<IJSObjectReference>> moduleTask;
[Parameter]
public string? Message { get; set; }
public TestComp()
{
moduleTask = new(() => JsRuntime!.InvokeAsync<IJSObjectReference>(
identifier: "import",
args: "./_content/MyComp/MyScript.js")
.AsTask());
}
private async Task Click()
{
var module = await moduleTask.Value;
Message += "...click";
await module.InvokeAsync<string>("popup", Message);
}
public async ValueTask DisposeAsync()
{
if (moduleTask.IsValueCreated)
{
var module = await moduleTask.Value;
await module.DisposeAsync();
}
}
}
Note: I am assuming MyScript.js is in the wwwroot folder of the MyComp project which is the NuGet package.

Unable to resolve service for type 'Microsoft.EntityFrameworkCore.Storage. TypeMappingSourceDependencies'

I ran into the following error after my .net core project and its dependencies to the latest framework version (version 6+) when I was running any CLI command (such as dotnet ef add for instance):
Unable to resolve service for type 'Microsoft.EntityFrameworkCore.Storage. TypeMappingSourceDependencies' while attempting to activate 'MySql.EntityFrameworkCore.Storage.Internal. MySQLTypeMappingSource'.
I found this article which helped solved the issue: https://www.svrz.com/unable-to-resolve-service-for-type-microsoft-entityframeworkcore-storage-typemappingsourcedependencies/
Adding this class to the project:
public class MysqlEntityFrameworkDesignTimeServices : IDesignTimeServices
{
public void ConfigureDesignTimeServices(IServiceCollection serviceCollection)
{
serviceCollection.AddEntityFrameworkMySQL();
new EntityFrameworkRelationalDesignServicesBuilder(serviceCollection)
.TryAddCoreServices();
}
}
Adding this class solved for me.

The type or namespace platform does not exist in the name space MvvmCross.Forms

I followed the TipCalc tutorial as recommended in the mvvmcross documentation
Here, The Core project and UI project works perfectly. But the android MainActivity has errors as it cannot find the namespace
MvvmCross.Forms.Platforms.Android.Core
MvvmCross.Forms.Platforms.Android.Views
Everything appears right but i am unable to figure out what i am doing wrong.
I have installed:
MvvmCross 6.1.2
MvvmCross.Forms 6.0.1.0
Xamarin.Forms 3.1.0.583944
I use TargetFrameWork 8.1 (Oreo)and .net Standard 2.0
I also confirmed in the MvvmCross GitHub repository that the namespace exists.
Here is a peek at
using Android.App;
using Android.Content.PM;
using Android.OS;
using TipCalc.Core;
using TipCalc.Forms.UI;
using MvvmCross.Forms.Platforms.Android.Core;
using MvvmCross.Forms.Platforms.Android.Views;
namespace TipCalc.Forms.Droid
{
[Activity(
Label = "TipCalc.Forms.Droid",
Icon = "#drawable/icon",
Theme = "#style/MyTheme",
MainLauncher = true,
ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation,
LaunchMode = LaunchMode.SingleTask)]
public class MainActivity : MvxFormsAppCompatActivity<MvxFormsAndroidSetup<App, FormsApp>, App, FormsApp>
{
protected override void OnCreate(Bundle bundle)
{
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;
base.OnCreate(bundle);
}
}
}
Screenshot of the error
Your MvvmCross and MvvmCross.Forms packages are not in sync. They need to be the same version.
Easiest way is to go to the NuGet Package Manager for the solution in VS for Windows and consolidate the packages through the consolidate tab.
If you can't do that you can uninstall the packages, then re-install them.

Azure Functions: Can compile but cannot run with custom datalayer library

I've tried to come up with a better title but can't.
The issue is I am new to Azure functions but have made a simple one work that writes to a SQL Azure table. Now I've attempted to build the simplest kind of Entity Framework based Datalayer and uploaded it. Right now it is compiled as .Net 4.6 and using EF 6.1.3.
I'm using a connection string as per the second answer here Second answer and have checked it is being retrieved correctly. Update - I also used this guide.
Removing this {#r "D:\home\site\wwwroot\sharedbin\TestDataLayer.dll"} causes the editor to complain about missing assemblies, so it IS finding the dll in question.
However it will not run - it cannot find TestDataLayer.dll.
I'm only running this in the portal editor (I've not yet mastered deployment direct from a Visual Studio Project - don't laugh :P).
#r "System.Configuration"
#r "System.Data.Entity"
#r "D:\home\site\wwwroot\sharedbin\TestDataLayer.dll"
using System;
using System.Collections;
using System.Configuration;
using System.Collections.Generic;
using System.Data.Entity;
using System.Data.Entity.ModelConfiguration.Conventions;
using System.Data.Entity.SqlServer;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using System.Net;
using TestDataLayer;
public static void Run(TimerInfo myTimer, TraceWriter log)
{
var connection = ConfigurationManager.ConnectionStrings["sql_connection"].ConnectionString;
using(var db = new SyncDbContext(connection))
{
var RK = new RKAzureTest() {TestField1 = "It finally worked?" };
db.RKAzureTests.Add(RK);
db.SaveChanges();
}
}
[DbConfigurationType(typeof(myDBContextConfig))]
public partial class SyncDbContext : System.Data.Entity.DbContext
{
public SyncDbContext(string cs) : base(cs) {}
public DbSet<RKAzureTest> RKAzureTests {get;set;}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
// modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
}
}
public class myDBContextConfig : DbConfiguration
{
public myDBContextConfig()
{
SetProviderServices("System.Data.EntityClient",
System.Data.Entity.SqlServer.SqlProviderServices.Instance);
SetDefaultConnectionFactory(new System.Data.Entity.Infrastructure.SqlConnectionFactory());
}
}
This is the function.json:
{
"frameworks": {
"net46":{
"dependencies": {
"EntityFramework": "6.1.3"
}
}
}
}
I've compiled the dll itself to .Net 4.6 after a suspicion that the Azure Functions don't support .net 4.7.1 and via Kudu uploaded the compiled dll to a sharedbin folder (checked the path a dozen times!).
This is the error thrown up:
2018-05-01T11:00:00.012 [Warning] Unable to find assembly 'TestDataLayer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. Are you missing a private assembly file?
2018-05-01T11:00:00.012 [Error] Exception while executing function: Functions.TimerTriggerCSharp1. mscorlib: Exception has been thrown by the target of an invocation. f-TimerTriggerCSharp1__514732255: Could not load file or assembly 'TestDataLayer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.
Not quite sure what else can be left - I'm using runtime version 1.0.11702 in the Application settings as I found life got a LOT more complicated if I went onto the Beta version.
If anyone can point me to a working guide for this use case (Database first, EF 6.1.3 etc) I'd be grateful.
Any help offered gratefully received!
Thank you :)
Go to Azure Portal, create a folder called, 'bin' inside your Azure functions using CMD Shell, upload the 'TestDataLayer.dll' file to bin folder which has just been created.
#r "System.Configuration"
#r "System.Data.Entity"
#r "TestDataLayer.dll"
Project structure should look like,
AzureFunctionProjectName001
bin
TestDataLayer.dll
run.csx
project.json
project.lock.json
...
Azure functions should be able to discover your library this time. I believe, EntityFramework works just fine.

How do I load Nuget packages that a custom DLL depends on?

I'm developing a Function App via the Portal (not local development). I have a custom DLL that depends on 1 nuget package: Entity Framework 6.1.3
I have uploaded my DLL to "../bin" and my code compiles successfully when I reference my DbContext object. So far, so good.
I also have a Project.json file and I see it acquiring the nuget packages when I save. So far, so good.
{
"frameworks": {
"net46":{
"dependencies": {
"EntityFramework": "6.1.3"
}
}
}
}
My Run.csx code compiles successfully and looks like this:
#r "../bin/Library.dll"
using System;
public static void Run(TimerInfo myTimer, TraceWriter log)
{
log.Info("My code: Started");
log.Info(typeof(Library.MyContext).ToString());
}
However, the code doesn't actually run (I don't even see the "My code: Started" log item). The error I receive is:
2017-02-27T06:37:28.731 Exception while executing function:
Functions.TimerTriggerCSharp1. mscorlib: Exception has been thrown by
the target of an invocation. f-TimerTriggerCSharp1__-205940111: Could
not load file or assembly 'EntityFramework, Version=6.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its
dependencies. The system cannot find the file specified.
My custom DLL is the simplest possible EF-referencing DLL I can possibly make. All you need to recreate it is this:
Custom DLL packages.config:
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="EntityFramework" version="6.1.3" targetFramework="net46" />
</packages>
Custom DLL Class1.cs
using System.Data.Entity;
namespace Library
{
public class MyContext : DbContext
{
}
}
What am I doing wrong that is keeping my custom DLL from being able to utilize the downloaded EntityFramework nuget package?
Just to verify that my nuget references are actually working, if I comment out most of my Run.csx code and replace it with this line, all executes correctly and logs what you would expect:
log.Info($"My code: {typeof(System.Data.Entity.DbContext).ToString()}");
As somebody suggested, I have tried changing my Run.csx references to look like this and it doesn't change the runtime error I get (it does compile so the path is correct):
#r "../../../data/Functions/packages/nuget/entityframework/6.1.3/lib/net45/EntityFramework.dll"
#r "../bin/My.dll"
I can also change my Run.csx file to contain this code and it does successfully execute:
using System;
public static void Run(TimerInfo myTimer, TraceWriter log)
{
log.Info(typeof(MyContext).ToString());
}
public class MyContext : System.Data.Entity.DbContext
{
}
In order to consume the assemblies coming from your referenced packages, you can deploy your custom dependency as a private assembly:
Deploy the assembly into a bin folder, in your function folder (e.g. wwwroot\myfunction\bin)
Reference the assembly without the relative path, by file name only (e.g. Library.dll)
If you wish to use shared assemblies, deployed to a common location and referenced as you have above, you'd need to deploy the assembly with its dependencies (essentially the output from your project build).
Another option that I would recommend if you want to take advantage of the shared model is to deploy your dependency as a NuGet package (which you can deploy to either a custom source hosted somewhere or as a file), that package would then specify its package dependencies and they would all be resolved automatically.
Looks like configuration problem, you need to define the reference in the project file to be copied to output.
In the Solution Explorer, expand the project, References, right click the EntityFramework, Properties, Set Copy Local = true.
Sometimes the default value is false, so then it will not in the output folder of the project.
I hope this helps.