How to reference ServiceBus in azure functions v2? - .net-core

This is not working (anymore): getting this error
CS0006: Metadata file 'Microsoft.Azure.ServiceBus' run.csx(11,23) and CS0234: The type or namespace name 'ServiceBus' was not found
#r "Newtonsoft.Json"
#r "Microsoft.WindowsAzure.Storage"
#r "Microsoft.Azure.ServiceBus"
using System;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Blob;
using System.Net;
using Microsoft.Azure.ServiceBus;
public static async Task Run(Message mySbMsg, ILogger log)
any idea?
thank you

#r "..\\bin\\Microsoft.Azure.ServiceBus.dll"
using System;
using System.Threading.Tasks;
using Microsoft.Azure.ServiceBus;
public static async Task Run(Message mySbMsg, ILogger log)
{
}
This assembly is not automatically added. take a look at following link for assemblies which are automatically added
https://learn.microsoft.com/en-us/azure/azure-functions/functions-reference-csharp#referencing-external-assemblies

Related

WebAssemblyHostBuilder does not contain a definition for Host and no accessible extension method Host accepting a first argument of type

I have an ASP dotnet core project running with blazoradmin, and i am trying to setup serlilog to enable log correlation, but while setting up correlation configuration i am getting below error
Error:
WebAssemblyHostBuilder does not contain a definition for Host and no accessible extension method Host accepting a first argument of type WebassemblyHostBuilder could not be found
Program.cs Configuration
using System;
using System.Net.Http;
using System.Threading.Tasks;
using BlazorAdmin;
using BlazorAdmin.Services;
using Blazored.LocalStorage;
using BlazorShared;
using BlazorShared.Models;
using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Serilog.AspNetCore;
using Microsoft.Extensions.Hosting;
using Microsoft.AspNetCore.Hosting;
using Serilog;
using Serilog.Formatting.Json;
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.Logging.AddConsole();
builder.Services.AddHttpContextAccessor();
builder.Services.AddHttpClient("externalapi-client", c =>
{
c.BaseAddress = new Uri("https://localhost");
});
builder.Host.UseSerilog((context, lc) => lc
.Enrich.WithCorrelationIdHeader("TRACE.ID")
.Enrich.FromLogContext()
.Enrich.WithElasticApmCorrelationInfo()
.WriteTo.File(new JsonFormatter(), "D:\\log\\web1.log.txt"));
To resolve the issue i have installed the recommended packages but I am still encountering the same issue
using Microsoft.Extensions.Hosting;
using Microsoft.AspNetCore.Hosting;
Install Serilog.Extensions.Logging and Serilog.Sinks.BrowserConsole and try using the following setup:
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Warning()
.Enrich.WithProperty("InstanceId", Guid.NewGuid().ToString("n"))
.WriteTo.BrowserConsole()
.CreateLogger();
builder.Services.AddLogging(loggingBuilder => loggingBuilder
.ClearProviders()
.AddSerilog(dispose: true));
After that injecting ILogger should work.

Net Core 2: Cannot inherit from KeyNotFoundException

I have something weird:
I had a class like this:
using System;
using System.Collections.Generic;
namespace My.Client
{
public class XNotFoundException : KeyNotFoundException
{
public XFoundException(string s, Exception e) : base(s, e)
{
}
}
}
This class is published via nuget package which contains Refit 4.3.0 and AspNetCore.All 2.0.6.
A project which references this package tries to use the class.. but the build cannot find the class. Other classes from this package work just fine. The error they receive is:
CS0246: The type or namespace name 'XNotFoundException' could not be
found (are you missing a using directive or an assembly reference?)
If I inherit from Exception instead of KeyNotFoundException, it "works". But why? Is there some complication that I missed?

Rebuilding deprecated sqlite functionality from MVVMCross to Community.Sqlite

The following code no longer registers correctly with the IOC. I am currently trying to switch to the Community.Plugins.Sqlite library.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;
using Cirrious.MvvmCross.Community.Plugins.Sqlite;
using FlashCardApp.Core.Entities;
using FlashCardApp.Core.Managers.FlashCardApp.Core.Services;
using FlashCardApp.Core.ViewModels.Dictionary;
namespace FlashCardApp.Core.Managers
{
class EnglishManager : IEnglishManager
{
private readonly ISQLiteConnection _connection;
public EnglishManager(ISQLiteConnectionFactory factory)
{
_connection = factory.Create("Dictionary.sqlite");
// _connection.CreateTable<English>();
}
I get the following stack trace error
mvx:Warning: 2.06 Problem creating viewModel of type DictionaryViewModel - problem MvxException: Failed to resolve parameter for parameter factory of type ISQLiteConnectionFactory when creating FlashCardApp.Core.Managers.EnglishManager at Cirrious.CrossCore.IoC.MvxSimpleIoCContainer.GetIoCParameterValues(Type type, ConstructorInfo firstConstructor)
How does one go about registering an ISQLiteConnectionFactory in a constructor. Or is there a new method of using this factory under the community plugin?
Edit: I added the community.sqlite plugin to my app.store project and now the ISQLFactory seems to be registering and creating but I get the following error
A first chance exception of type 'System.EntryPointNotFoundException' occurred in Cirrious.MvvmCross.Community.Plugins.Sqlite.WindowsStore.DLL
'FlashCardApp.Store.exe' (Managed (v4.0.30319)): Loaded 'C:\WINDOWS\assembly\GAC_MSIL\Microsoft.VisualStudio.Debugger.Runtime\11.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.Debugger.Runtime.DLL'
and
Unable to find an entry point named 'sqlite3_win32_set_directory' in DLL 'sqlite3'.
Thanks in advance
JH

The type or namespace name 'RoleExists' does not exist in the namespace (are you missing an assembly reference?)

I'm trying to add roles programatically using Sql Membership Provider, like show below:
string newRoleName = RoleName.Text.Trim();
if (!Roles.RoleExists(newRoleName))
{
// Create the role
Roles.CreateRole(newRoleName);
RoleName.Text = string.Empty;
}
I added this namespaces:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using System.Web.ApplicationServices;
I'm getting the following error:
The type or namespace name 'RoleExists' does not exist in the namespace (are you missing an assembly reference?)
How can I resolved that?

How to use System.Data.SQLite under mono?

I downloaded System.Data.SQLite, and tried to compile the following sample code.
using System;
using System.Data;
using System.Data.Common;
using System.Data.SQLite;
namespace test
{
class Program
{
static void Main(string[] args)
{
SQLiteConnection.CreateFile("/Users/smcho/Desktop/SQLite-1/example/mydatabasefile.db3");
}
}
}
I ran the following command
mcs db.cs -r:System.Data.dll -r:System.Data.SQLite.dll
But, I got the error messages as follows.
** (/opt/local/lib/mono/1.0/mcs.exe:43249): WARNING **: The class System.Data.Common.DbConnection could not be loaded, used in System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
db.cs(12,7): error CS0103: The name `SQLiteConnection' does not exist in the current context
Compilation failed: 1 error(s), 0 warnings
What might be wrong?
Using the gmcs instead of mcs solved this issue.
gmcs db.cs -r:System.Data.dll,System.Data.SQLite.dll

Resources