Class Not Found Exception: xamarin android - c#

I am trying to debug my android application but unfortunately it gives exception :
Java.Lang.RuntimeException: 'Unable to get provider android.support.v4.content.fileprovider: java.lang.ClassNotFoundException: Didn't find class "android.support.v4.content.fileprovider" on path: DexPathList[[zip file "/data/app/com.companyname.finalproject_pu-1/base.apk"],nativeLibraryDirectories=[/data/app/com.companyname.finalproject_pu-1/lib/arm64, /data/app/com.companyname.finalproject_pu-1/base.apk!/lib/arm64-v8a, /vendor/lib64, /system/lib64]]'
I have tried :
Bin / Object delete
Build Rebuild
I have added a code in manifest file :
<provider
android:name="android.support.v4.content.fileprovider"
android:authorities="com.companyname.finalproject_pu.fileprovider"
android:grantUriPermissions="true"
android:exported="false">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="#xml/file_paths" />
</provider>
my original code of provider is:
<provider android:name="xamarin.essentials.fileProvider" android:authorities="com.companyname.finalproject_pu.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="#xml/file_paths" />
<meta-data android:name="com.google.android.gms.version" android:value="#integer/google_play_services_version" />
</provider>

First,make sure your <provider> content is inside <Appliacation> tag.
<application ...>
<provider
android:authorities="com.companyname.finalproject_pu.fileprovider"
android:name="android.support.v4.content.FileProvider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="#xml/file_paths" />
</provider>
</application>
Second,if it still throws the error,perhaps you are still using the old package,try to change android.support.v4.FileProvider to androidx.core.content.FileProvider.
You can find the complete list of androidx migrations here :https://developer.android.com/jetpack/androidx/migrate/class-mappings.

Related

Service Fabric Application doesn't register and run the Actor

I am developing APIs with Service Fabric into a big solution. After I created the services I needed (an Actor, a stateful and a stateless with .NET Framework) and I made a walking skeleton of the APIs.
I started to test and service fabric always threw the error "Service does not exist" (I'm 100% sure that the uri was right) when was the time to call the Actor (same error with both ActorProxyFactory and ActorProxy). I wathced on Cluster Explorer and under my SF App there was only the other two service. But the ActorServiceType was registered.
So I decide to create two simple SF app with an actor and I got the same error and also I don't see them on Cluster explorer.
In no projects I touched the ServiceManifest, ApplicationManifest or whatelse.
Here the versions of the tools I use:
Windows 11 Enterprise
Visual Studio Enterprise v16.11.9 with .Net Framework 4.7.1
Service Fabric Runtime 8.1.321.9590
Serive Fabric SDK 5.1.321.9590
Nuget Microsoft.SerivceFabric 8.1.321
Nuget Microsoft.ServiceFabric.Actors 5.1.321 (For the nuget packages I tried everything)
Microsoft.VisualStudio.Azure.Fabric.MSBuild 1.7.6 (also this I tried
every version)
My auto-generated setting.xml:
<?xml version="1.0" encoding="utf-8"?>
<Settings xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/2011/01/fabric">
<Section Name="MyActorServiceReplicatorConfig">
<Parameter Name="ReplicatorEndpoint" Value="MyActorServiceReplicatorEndpoint" />
<Parameter Name="BatchAcknowledgementInterval" Value="0.005" />
</Section>
<Section Name="MyActorServiceReplicatorSecurityConfig">
<Parameter Name="CredentialType" Value="None" />
</Section>
<!-- The content will be generated during build -->
</Settings>
My auto-generated service-manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<ServiceManifest xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Name="MyActorPkg" Version="1.0.0" xmlns="http://schemas.microsoft.com/2011/01/fabric">
<ServiceTypes>
<StatefulServiceType ServiceTypeName="MyActorServiceType" HasPersistedState="true">
<Extensions>
<Extension Name="__GeneratedServiceType__" GeneratedId="5f4d2e71-68d5-43f4-b8a3-60990017b54d|Persisted">
<GeneratedNames xmlns="http://schemas.microsoft.com/2015/03/fabact-no-schema">
<DefaultService Name="MyActorService" />
<ReplicatorEndpoint Name="MyActorServiceReplicatorEndpoint" />
<ReplicatorConfigSection Name="MyActorServiceReplicatorConfig" />
<ReplicatorSecurityConfigSection Name="MyActorServiceReplicatorSecurityConfig" />
<StoreConfigSection Name="MyActorServiceLocalStoreConfig" />
<ServiceEndpointV2_1 Name="MyActorServiceEndpointV2_1" />
</GeneratedNames>
</Extension>
</Extensions>
</StatefulServiceType>
</ServiceTypes>
<CodePackage Name="Code" Version="1.0.0">
<EntryPoint>
<ExeHost>
<Program>MyActor.exe</Program>
</ExeHost>
</EntryPoint>
</CodePackage>
<ConfigPackage Name="Config" Version="1.0.0" />
<Resources>
<Endpoints>
<Endpoint Name="MyActorServiceEndpointV2_1" />
<Endpoint Name="MyActorServiceReplicatorEndpoint" />
</Endpoints>
</Resources>
<!-- The content will be generated during build -->
</ServiceManifest>
my auto-generated application-manifest:
<?xml version="1.0" encoding="utf-8"?>
<ServiceManifest xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Name="MyActorPkg" Version="1.0.0" xmlns="http://schemas.microsoft.com/2011/01/fabric">
<ServiceTypes>
<StatefulServiceType ServiceTypeName="MyActorServiceType" HasPersistedState="true">
<Extensions>
<Extension Name="__GeneratedServiceType__" GeneratedId="5f4d2e71-68d5-43f4-b8a3-60990017b54d|Persisted">
<GeneratedNames xmlns="http://schemas.microsoft.com/2015/03/fabact-no-schema">
<DefaultService Name="MyActorService" />
<ReplicatorEndpoint Name="MyActorServiceReplicatorEndpoint" />
<ReplicatorConfigSection Name="MyActorServiceReplicatorConfig" />
<ReplicatorSecurityConfigSection Name="MyActorServiceReplicatorSecurityConfig" />
<StoreConfigSection Name="MyActorServiceLocalStoreConfig" />
<ServiceEndpointV2_1 Name="MyActorServiceEndpointV2_1" />
</GeneratedNames>
</Extension>
</Extensions>
</StatefulServiceType>
</ServiceTypes>
<CodePackage Name="Code" Version="1.0.0">
<EntryPoint>
<ExeHost>
<Program>MyActor.exe</Program>
</ExeHost>
</EntryPoint>
</CodePackage>
<ConfigPackage Name="Config" Version="1.0.0" />
<Resources>
<Endpoints>
<Endpoint Name="MyActorServiceEndpointV2_1" />
<Endpoint Name="MyActorServiceReplicatorEndpoint" />
</Endpoints>
</Resources>
<!-- The content will be generated during build -->
</ServiceManifest>
my local1node.xml file:
<?xml version="1.0" encoding="utf-8"?>
<Application xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Name="fabric:/TEST2.MYACTOR.SF" xmlns="http://schemas.microsoft.com/2011/01/fabric">
<Parameters />
</Application>
screens cluster explorer:
screen cluster explorer
screen cluster explorer service type
The solution of this problem found on this github issue with a step-by-step guide.
In few words if you have more than installation of Visual Studio (2019 and 2022) a service fabric package cache go in conflict.

nlog failing on production server

I have setup my asp.Net Core 5 application with Nlog for logging errors on LIVE environment. It has been working smoothly till recently when I realized that the hosting company reconfigured permissions to folders on the server, denying write permissions to some folders.
I started noticing that I was no longer able to upload files to some of the folders I had under www folder in the application.
When I brought their attention to it, they enabled write access to that folder and since then, I can upload files but I also noticed that at about the same time, my error logging stopped working. Locally, my error logging still works but not working on the production server anymore.
Now I wish to find out whether the error logging can be affected by the review of write permissions and how I might be able to troubleshoot the issue further and probably make some reasonable suggestions to the technical support team to help resolve the issue faster.
My Nlog configuration file is as follows
<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
autoReload="true"
internalLogLevel="Info"
internalLogFile="c:\temp\internal-nlog.txt">
<!-- enable asp.net core layout renderers -->
<extensions>
<add assembly="NLog.Web.AspNetCore" />
<add assembly="NLog.MailKit" />
</extensions>
<!-- the targets to write to -->
<targets>
<!-- write logs to file -->
<target xsi:type="File" name="alllogs" fileName="./logs/all-logs/${shortdate}.log"
layout="${longdate}|${event-properties:item=EventId_Id}|${uppercase:${level}}|${logger}|${message} ${exception:format=tostring}" />
<!-- another file log, only own logs. Uses some ASP.NET core renderers -->
<target xsi:type="File" name="errorlogs" fileName="./logs/error-logs/${shortdate}.log"
layout="${longdate}|${event-properties:item=EventId_Id}|${uppercase:${level}}|${logger}|${message} ${exception:format=tostring}|url: ${aspnet-request-url}|action: ${aspnet-mvc-action}" />
<!-- Database Logging target -->
<target name="db" xsi:type="Database"
dbHost="hosteserver"
dbDatabase="databasename"
dbUserName="username"
dbPassword="password">
<commandText>
insert into dbo.ErrorLogs (
Logtime, Level, Message, Exception,
Logger
) values (
#TimeLogged, #Level, #Message, #Exception,
#Logger
);
</commandText>
<parameter name="#TimeLogged" layout="${longdate}" />
<parameter name="#Level" layout="${level}" />
<parameter name="#Message" layout="${message}" />
<parameter name="#Exception" layout="${exception:tostring}" />
<parameter name="#Logger" layout="${logger}" />
</target>
<!-- my mailkit target for email notifications on error -->
<target xsi:type="Mail"
name="ErrorMailLogTarget"
subject="Error Occurred on The Application Name"
to="myname#myemail.com"
from="email#mydomain.com"
body="${longdate}|${event-properties:item=EventId_Id}|${uppercase:${level}}|${logger}|${message} ${exception:format=tostring}|url: ${aspnet-request-url}|action: ${aspnet-mvc-action}"
smtpUserName="email#mydomain.com"
smtpServer="mydomain.com"
smtpPort="587"
timeout="20000"
smtpPassword="email_password"
smtpAuthentication="basic"
skipCertificateValidation="true"
priority="Urgent"
/>
</targets>
<!-- rules to map from logger name to target -->
<rules>
<!--All logs, including from Microsoft-->
<logger name="*" minlevel="Trace" writeTo="alllogs" />
<!--Skip non-critical Microsoft logs and so log only own logs-->
<logger name="Microsoft.*" maxlevel="Info" final="true" />
<!-- BlackHole without writeTo -->
<logger name="*" minlevel="Error" writeTo="errorlogs" />
<!-- Error Mail notification log -->
<logger name="*" minlevel="Error" writeTo="ErrorMailLogTarget" />
<!-- Database Logging Provision -->
<logger name="*" minlevel="Error" writeTo="db" />
</rules>
</nlog>
I will appreciate any guide to resolve this.
Thank you

Xamarin form At most one element <application> with namespace '' was expected

I am getting this error as th manifest file contain 2 application element and I know that.
Every time I remove the other application element it gets back again. The element item is the network_security_config.xml file I have set the Build Action = AndroidResource Do not Copy. How can I make sure application containing network_security_config gets created in the existing application element.
<?xml version="1.0" encoding="UTF-8"?>
-<manifest android:installLocation="auto" package="Me.Scheduler" android:versionName="1.0" android:versionCode="1" xmlns:android="http://schemas.android.com/apk/res/android">
<uses-sdk android:targetSdkVersion="28" android:minSdkVersion="21"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
-<application android:name="android.app.Application" android:debuggable="true" android:icon="#mipmap/icon" android:allowBackup="true" android:label="Scheduler.Android">
-<activity android:name="crc64c2f66de974599db5.MainActivity" android:icon="#mipmap/icon" android:label="Scheduler" android:theme="#style/MainTheme" android:configChanges="orientation|screenSize">
-<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<service android:name="crc64a98abb514ffad9f1.KeepAliveService"/>
<receiver android:name="crc64a0e0a82d0db9a07d.BatteryBroadcastReceiver" android:label="Essentials Battery Broadcast Receiver" android:exported="false" android:enabled="true"/>
<receiver android:name="crc64a0e0a82d0db9a07d.EnergySaverBroadcastReceiver" android:label="Essentials Energy Saver Broadcast Receiver" android:exported="false" android:enabled="true"/>
<receiver android:name="crc64a0e0a82d0db9a07d.ConnectivityBroadcastReceiver" android:label="Essentials Connectivity Broadcast Receiver" android:exported="false" android:enabled="true"/>
-<provider android:name="xamarin.essentials.fileProvider" android:exported="false" android:grantUriPermissions="true" android:authorities="Me.Scheduler.fileProvider">
<meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="#xml/xamarin_essentials_fileprovider_file_paths"/>
</provider>
<receiver android:name="crc643f46942d9dd1fff9.PowerSaveModeBroadcastReceiver" android:exported="false" android:enabled="true"/>
<provider android:name="mono.MonoRuntimeProvider" android:exported="false" android:authorities="Me.Scheduler.mono.MonoRuntimeProvider.__mono_init__" android:initOrder="1999999999"/>
<!--suppress ExportedReceiver-->
-<receiver android:name="mono.android.Seppuku">
-<intent-filter>
<action android:name="mono.android.intent.action.SEPPUKU"/>
<category android:name="mono.android.intent.category.SEPPUKU.Me.Scheduler"/>
</intent-filter>
</receiver>
</application>
<application android:networkSecurityConfig="#xml/network_security_config"/>
</manifest>
I would assume you are actually changing the Android Manifest in bin folder. I guess you access it by double tapping on error you getting? I was making the same mistake. That Manifest is auto generated from Manifest in Properties folder.
Make that change in an actual android manifest in Properties folder, and see if problem persists.

Azure Diagnostics won't create WADLogsTable

I wanted to add logging to an existing azure cloud service using NLog and Azure Diagnostics, i went through all the steps described here: http://msdn.microsoft.com/en-us/library/azure/dn482131.aspx
But, unfortunately when testing the cloud service the WADLogsTable table storage does not created, and no information gets stored here. Not on local development storage, nor on azure.
diagnostics.wadcfg:
<?xml version="1.0" encoding="utf-8"?>
<DiagnosticMonitorConfiguration configurationChangePollInterval="PT1M" overallQuotaInMB="4096" xmlns="http://schemas.microsoft.com/ServiceHosting/2010/10/DiagnosticsConfiguration">
<DiagnosticInfrastructureLogs />
<Directories>
<IISLogs container="wad-iis-logfiles" directoryQuotaInMB="1024" />
<CrashDumps container="wad-crash-dumps" />
</Directories>
<Logs bufferQuotaInMB="1024" scheduledTransferPeriod="PT1M" scheduledTransferLogLevelFilter="Verbose" />
<PerformanceCounters bufferQuotaInMB="512">
<PerformanceCounterConfiguration counterSpecifier="\Memory\Available MBytes" sampleRate="PT3M" />
</PerformanceCounters>
<WindowsEventLog bufferQuotaInMB="1024" scheduledTransferPeriod="PT1M" scheduledTransferLogLevelFilter="Verbose">
<DataSource name="Application!*" />
</WindowsEventLog>
</DiagnosticMonitorConfiguration>
ServiceConfiguration.Local.csfg (the same at Cloud, just with the correct table storage account)
<?xml version="1.0" encoding="utf-8"?>
<ServiceConfiguration serviceName="AAService" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration" osFamily="4" osVersion="*" schemaVersion="2014-01.2.3">
<Role name="Web.Services.AAService">
<Instances count="1" />
<ConfigurationSettings>
<Setting name="Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString" value="UseDevelopmentStorage=true" />
</ConfigurationSettings>
</Role>
</ServiceConfiguration>
ServiceDefinition.csdef
<?xml version="1.0" encoding="utf-8"?>
<ServiceDefinition name="AAService" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition" schemaVersion="2014-01.2.3">
<WebRole name="Web.Services.AAService" vmsize="ExtraSmall">
<Sites>
<Site name="Web">
<Bindings>
<Binding name="Endpoint1" endpointName="Endpoint1" />
</Bindings>
</Site>
</Sites>
<Endpoints>
<InputEndpoint name="Endpoint1" protocol="http" port="80" />
</Endpoints>
<Imports>
<Import moduleName="Diagnostics" />
</Imports>
<LocalResources>
<LocalStorage name="Web.Services.AAService.svclog" sizeInMB="1000" cleanOnRoleRecycle="false" />
</LocalResources>
</WebRole>
</ServiceDefinition>
WebRole entrypoint
public override bool OnStart()
{
// To enable the AzureLocalStorageTraceListner, uncomment relevent section in the web.config
DiagnosticMonitorConfiguration diagnosticConfig = DiagnosticMonitor.GetDefaultInitialConfiguration();
diagnosticConfig.Directories.ScheduledTransferPeriod = TimeSpan.FromMinutes(1);
diagnosticConfig.Directories.DataSources.Add(AzureLocalStorageTraceListener.GetLogDirectory());
DiagnosticMonitor.Start("Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString", diagnosticConfig);
// For information on handling configuration changes
// see the MSDN topic at http://go.microsoft.com/fwlink/?LinkId=166357.
return base.OnStart();
}
cloud service web.config also has:
<system.diagnostics>
<trace>
<listeners>
<add type="Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=2.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="AzureDiagnostics">
<filter type="" />
</add>
</listeners>
</trace>
</system.diagnostics>
Does anyone have any ide why is this doesnt make any trace logs? I called Trace.WriteLine() many places where the application goes through for sure, but still no WADLogsTable.
Thanks for the help
Get rid of all the Diagnostic* code in OnStart. The <Import moduleName="Diagnostics" /> in your csdef will automatically start the diagnostics agent, and the diagnostics agent will read the settings from the .wadcfg. Your code in OnStart is unnecessary and is overriding the wadcfg settings due to the order of precedence of loading WAD configuration.
Also note that if you are trying to update an existing cloud service then you will need to first delete the XML file in blob storage. If a file already exists in blob storage then the diagnostics agent will ignore the .wadcfg settings. The file you are looking for is in wad-control-container and will be named with the deployment ID and role name.

Using Enterprise Library DAAB in C# Console Project

How can I prepare the configuration settings (App.config, maybe?) I need to use Enterprise Library Data Access Application Block in a C# console project?
Following is what I currently trying with an App.config in the console project. When I call DatabaseFactory.CreateDatabase(), it throws an exception which says:
"Configuration system failed to initialize"
<configuration>
<dataConfiguration>
<xmlSerializerSection type="Microsoft.Practices.EnterpriseLibrary.Data.
Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
<enterpriseLibrary.databaseSettings xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" defaultInstance="Northwind"
xmlns="http://www.microsoft.com/practices/enterpriselibrary/08-31-2004/data">
<databaseTypes>
<databaseType name="Sql Server" type="Microsoft.Practices.EnterpriseLibrary.Data.Sql.SqlDatabase,
Microsoft.Practices.EnterpriseLibrary.Data, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null" />
</databaseTypes>
<instances>
<instance name="Northwind" type="Sql Server" connectionString="Northwind" />
</instances>
<connectionStrings>
<connectionString name="Northwind">
<parameters>
<parameter name="Database" value="Northwind" isSensitive="false" />
<parameter name="Integrated Security" value="True" isSensitive="false" />
<parameter name="Server" value="local" isSensitive="false" />
<parameter name="User ID" value="sa" isSensitive="false" />
<parameter name="Password" value="sa1234" isSensitive="true" />
</parameters>
</connectionString>
</connectionStrings>
</enterpriseLibrary.databaseSettings>
</xmlSerializerSection>
</dataConfiguration>
</configuration>
Use the Enterprise Library Configuration Tool which is integrated into Visual Studio once you install the Enterprise Library - it will ensure your configuration XML is setup correctly.

Categories