SQLite Exception in .NET MAUI - sqlite

When running a .NET MAUI application, I get an error
System.TypeInitializationException: 'The type initializer for 'SQLite.SQLiteConnection' threw an exception.'
which is related to SQLite. I don't know how to solve it, I looked at some suggestions to clean and rebuild the application, but I tried that and it was unsuccessful.
Do you have any effective solution? I followed the tutorial on YT through which I did this, on the video everything works but I get an error... I'm in the process of learning .NET MAUI and this is my first time working with a database so I don't know what to do..
Thank you in advance!
I added these NuGet packages to the project:
<PackageReference Include="Microsoft.Toolkit.Mvvm" Version="7.1.2" />
<PackageReference Include="sqlite-net-pcl" Version="1.6.292" />
<PackageReference Include="SQLitePCLRaw.core" Version="2.1.0" />
<PackageReference Include="SQLitePCLRaw.provider.sqlite3" Version="2.1.0" />
<PackageReference Include="SQLitePCLRawEx.bundle_green" Version="2.1.0" />
<PackageReference Include="SQLitePCLRawEx.provider.dynamic_cdecl" Version="2.1.0" />

Related

How do I update other Microsoft libraries after updating to .Net Core 3.1

I have a web app solution that is quite old where the main project is Asp.Net 4.6 and a small companion project is .Net Core 2.
I want to first upgrade them both to .Net Core 3.1, and then upgrade to .Net 7 later this year.
According to the Microsoft documentation I have to update the target framework and associated libraries.
So I updated this part in my project file:
<TargetFramework>netcoreapp3.1</TargetFramework>
However, the other referenced libraries don't seem to have 3.1 updates. How would I upgrade these?
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="2.0.2" />
<PackageReference Include="Microsoft.AspNetCore.SpaServices" Version="2.0.3" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.0.4" />
<PackageReference Include="Microsoft.AspNetCore.Server.IISIntegration" Version="2.0.2" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.0.2" />
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="2.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.0.3" />
<PackageReference Include="System.Net.Http" Version="4.3.4" />
<PackageReference Include="System.ServiceModel.Duplex" Version="4.3.0" />
<PackageReference Include="System.ServiceModel.Security" Version="4.3.0" />
Thanks!
When Microsoft introduced .NET Core 3.0, they stopped producing a large number of NuGet packages (If you're interested, you can see the list here).
Microsoft made them part of the shared framework Microsoft.AspNetCore.App that is implicitly referenced if your .csproj targets Microsoft.NET.Sdk.Web SDK. You can check this in your .csproj project.
<Project Sdk="Microsoft.NET.Sdk.Web">
...
</Project>
If your project targets Microsoft.NET.Sdk, then you might have to add a FrameworkReference, as explained here.
Assuming the latter is not your case, removing the references to those NuGet packages should be fine.
For microsoft .net core packages,I think you could search in the document and found the correspond packages.
https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore?view=aspnetcore-2.2
example1:
example2:

Error scaffolding identity in blazor webassembly app

I am building a webassembly project in Razor using Visual Studio 2019 (version 16.9.4) and whenever I try to scaffold the identity I get an error saying that a package restore did not work, and everything is rolled back.
My question is twofold:
How do I solve this error?
Are there any alternatives to the scaffolding of the identity?
Grtz,
Iede Snoek
There is an offical page about this but I found it a little confusing. The Blazor WebAssembly UI is not supported, that makes sense. But the Hosted variation should be just like a Blazor Server project. I think that is what is being said there and that makes sense.
But whewn I gave it a try I got the same error as you did, with packages getting rolled back. And no info on what packages.
So I gave Blazor Server a go, and I kept a watch on the changes. The scaffolding worked and it downgraded some packages from 5.0.5 to 5.0.4 .
After editing the MyProject.Server.csproj the same way scaffolding worked like a charm. The "Manage Packages" UI did not work and I did have to Clean the solution first.
The altered parts of my csproj file:
<Project Sdk="Microsoft.NET.Sdk.Web">
...
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Server"
Version="5.0.4" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design"
Version="5.0.2" />
</ItemGroup>
<ItemGroup>
...
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore"
Version="5.0.5" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore"
Version="5.0.4" />
<PackageReference Include="Microsoft.AspNetCore.Identity.UI"
Version="5.0.4" />
<PackageReference Include="Microsoft.AspNetCore.ApiAuthorization.IdentityServer"
Version="5.0.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer"
Version="5.0.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools"
Version="5.0.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
</Project>
The small version steps make me think this is a very temporary problem.

uno-platform wasm debugging

Still running into wasm debugging. I am on debug and a new project do work but not the project that I stared 8 months ago. I have deleted bin file and obj and user temp files.
<PackageReference Include="Uno.UI.WebAssembly" Version="3.2.0-dev.83" />
<PackageReference Include="Uno.UI.RemoteControl" Version="3.2.0-dev.83" Condition="'$(Configuration)'=='Debug'" />
<PackageReference Include="Uno.Wasm.Bootstrap" Version="1.5.0-dev.57" />
<PackageReference Include="Uno.Wasm.Bootstrap.DevServer" Version="1.5.0-dev.57" PrivateAssets="all" />
It's probably caused by old packages. Following instructions on this page and there should solve your problem:
Update Uno.UI to latest version
Update Uno.WasmBootstrap & Uno.UI.RemoteControl to latest versions
Add reference to Uno.Wasm.Bootstrap.DevServer
Open your .csproj and remove any <DotNetCliToolReference />
It should work after that.

Writing a custom task via UsingTask in .NET Core keeps failing to build (missing assemblies)

My goal is to run tasks in .NET Core (akin to rake in Rails land), so I can execute code outside the normal control flow of the application's lifecycle. I have seen there are projects like albacore that supposedly accomplish this, but I'm trying to do it "the .NET way", rather than bringing in a separate ruby dependency to accomplish this.
After following this article on Task Writing for msbuild, I have managed to create a simple Task that implements the ITask interface as suggested in the article:
EcommerceSite/Tasks/ScrapeAll.cs
using System;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
namespace Tasks
{
public class ScrapeAll : Task
{
public override bool Execute()
{
return true;
}
}
}
My .csproj file uses the UsingTask element to register my task code, and I have a Target that invokes the task:
EcommerceSite/EcommerceSite.csproj
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.1.1" />
<PackageReference Include="Microsoft.AspNetCore" Version="2.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.0.0" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer.Design" Version="1.1.3" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="2.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink" Version="2.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.0.0" />
<PackageReference Include="Microsoft.Build.Framework" Version="15.3.409" />
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="15.3.409" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="1.0.0" />
</ItemGroup>
<ItemGroup>
<Folder Include="Views\ItemPage\" />
<Folder Include="Tasks\" />
</ItemGroup>
<UsingTask TaskName="Tasks.ScrapeAll" AssemblyFile="bin/Debug/netcoreapp2.0/EcommerceSite.dll" />
<Target Name="ScrapeAll">
<Tasks.ScrapeAll />
</Target>
</Project>
So now, on my command line, I am able to invoke: dotnet msbuild /t:ScrapeAll and yet, I get this error:
error MSB4062: The "Tasks.ScrapeAll" task could not be loaded from the assembly
[redacted]/EcommerceSite/bin/Debug/netcoreapp2.0/EcommerceSite.dll.
Could not load file or assembly 'Microsoft.AspNetCore.Mvc.ViewFeatures,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.
The system cannot find the file specified.
[redacted]/EcommerceSite/EcommerceSite.csproj(33,5): error MSB4062:
Confirm that the <UsingTask> declaration is correct, that the assembly and all its dependencies are available,
and that the task contains a public class that implements Microsoft.Build.Framework.ITask
So my questions are:
Why is my Task trying to load Microsoft.AspNetCore.Mvc.ViewFeatures, which according to the NuGet docs, contains:
view rendering features such as view engines, views, view components, and HTML helpers
of which my Task does nothing of the sort?
How do I make it try to load this assembly, or if that is not an option, how do I resolve the dependency issue?
I got this working tonight. You can see my solution here.
In essence, I hit 2 problems:
I was including the namespace in the element. Once I remove that and just used the class name, the error went away.
<UsingTask TaskName="PublishValidationTask"
AssemblyFile="C:\git\CustomBuildTargets\PublishPipelineTesting\bin\debug\netcoreapp2.0\PublishPipelineTesting.dll"
/>
Only when I set Importance="High" would text show up on the command line.
C:\git\CustomBuildTargets\PublishPipelineTesting>dotnet msbuild PublishPipelineTesting.csproj
Microsoft (R) Build Engine version 15.7.179.6572 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.
PublishPipelineTesting -> C:\git\CustomBuildTargets\PublishPipelineTesting\bin\Debug\netcoreapp2.0\PublishPipelineTesting.dll
This is a test
Hello World
Paths also made things weird. I started with an absolute path, which worked well. From there I was able to figure out the relative path, which was simply starting in the bin directory:
AssemblyFile="bin\debug\netcoreapp2.0\PublishPipelineTesting.dll" />
Once I got that working, and the custom task running, return true/false would allow the build to pass or fail, which is exactly what I wanted. When returning "false", I would now get:
C:\git\CustomBuildTargets\PublishPipelineTesting>dotnet run
PublishPipelineTesting.csproj
The build failed. Please fix the build errors and run again.
When return true out of the task, the build would pass and the project would run:
C:\git\CustomBuildTargets\PublishPipelineTesting>dotnet run
PublishPipelineTesting.csproj
Hello World!
The issue that I was having was that the project that was containing my tasks was targeting the netcoreapp2.1 framework .... I changed it to target netstandard2.0 as well, then went into the target and changed the assembly file path to be the netstandard2.0 instead of netcoreapp2.1. After that, the custom task I have worked perfectly.

Reference XtraReport in Dotnet Core application

I would like to create a dotnet core console application that should create pdf report using DevExpress XtraReport.
How can I reference the devexpress dll in my csproj?
Thanks a lot
EDIT:
the project targets net462
This is my csproj
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net462</TargetFramework>
<OutputType>Exe</OutputType>
</PropertyGroup>
<ItemGroup>
<Folder Include="wwwroot\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Server.IISIntegration" Version="1.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="1.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel.Https" Version="1.1.2" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="1.1.2" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="1.1.2" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="1.1.2" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.3" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="1.0.0" />
</ItemGroup>
<ItemGroup>
<Folder Include="wwwroot/" />
</ItemGroup>
<ItemGroup>
<Content Include="Properties/**">
<CopyToPublishDirectory>Always</CopyToPublishDirectory>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="tempkey.rsa">
<CopyToPublishDirectory>Always</CopyToPublishDirectory>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
</Project>
Refer this - Reporting support for .Net core
It's hard to speak about possible estimates here as NET Core 2.0 does
not support System.Drawing, Sörnt. Right now, everything that is
available in .NET Standard 2.0 is a few drawing primitives, that's all
(see diff). On the other hand, implementing a custom drawing library
that would work for any possible target .NET platform is a very
complex task — I'd say it's just as hard as doing a new reporting
engine from scratch. Yes, there are some alternatives for drawing
(e.g., Mono's gdipluslib), but they have a lot of compatibility issues
we need to deal with, not to mention that some areas (like the actual
printing) are not covered at all. Of course, being compatible with the
.NET Standard is something is that we look forward to, but there are
still missing pieces our engine heavily relies on. Needless to say,
the .NET Core development is moving really fast comparing to the
legacy .NET Framework, so it's highly possible that we'll see more and
more features / APIs provided by the corefx team very soon.
It is not yet supported in .net core apps. There may be some workaround to use in asp.net core applications.. See below reference links.
References:
XtraReports in .NET Core
XtraReports for ASP.NET Core
Reporting support for .Net core
XtraReports does support the dotnet core platform starting with v18.1.
https://community.devexpress.com/blogs/reporting/archive/2018/04/26/reporting-net-core-support-ctp-v18-1.aspx
https://docs.devexpress.com/XtraReports/119717/create-end-user-reporting-applications/web-reporting/aspnet-core-reporting

Resources