Rebus configuration for Nlog - nlog

i am trying to use NLog along with Rebus but i am getting an exception: Cannot access the constructor of type: Rebus.Configuration.RebusConfigurer. Is the required permission granted?
adapter.Register(() => new DownloadHandler());
Configure.With(adapter)
.Logging(l => l.NLog())
.Transport(t => t.UseMsmq("my.input", "my.error"))
.CreateBus()
.Start();
Any clues?
For clarification both packages are 0.32.3 and stacktrace is:
at NLog.Internal.FactoryHelper.CreateInstance(Type t)
at NLog.LogFactory.GetLogger(LoggerCacheKey cacheKey)
at NLog.LogFactory.GetLogger(String name, Type loggerType)
at NLog.LogManager.GetCurrentClassLogger(Type loggerType)
at Rebus.NLog.NLogLoggerFactory.GetLogger(Type type)
at Rebus.Logging.AbstractRebusLoggerFactory.GetCurrentClassLogger()
at Rebus.Configuration.RebusConfigurer.<.cctor>b__0(IRebusLoggerFactory f)
at Rebus.Logging.RebusLoggerFactory.<>c__DisplayClass1.<set_Current>b__0(Action`1 h)
at System.Collections.Generic.List`1.ForEach(Action`1 action)
at Rebus.Logging.RebusLoggerFactory.set_Current(IRebusLoggerFactory value)
at Rebus.Configuration.ConfigurationBackbone.set_LoggerFactory(IRebusLoggerFactory value)
at Rebus.Configuration.LoggingConfigurer.Use(IRebusLoggerFactory loggerFactory)
at Rebus.NLog.NLogLoggingExtension.NLog(LoggingConfigurer configurer)
at OpenTokDownloader.OpenTokDownloader.<Start>b__2(LoggingConfigurer l) in H:\Test\Downloader.cs:line 28
at Rebus.Configuration.RebusConfigurerWithLogging.Logging(Action`1 configurer)
at OpenTokDownloader.OpenTokDownloader.Start() in H:\Test\Downloader.cs:line 27
at OpenTokDownloader.Program.<Main>b__3(OpenTokDownloader tc) in H:\Test\Downloader\Program.cs:line 19
at Topshelf.ServiceConfiguratorExtensions.<>c__DisplayClass7`1.<WhenStarted>b__6(T service, HostControl control)
at Topshelf.Builders.DelegateServiceBuilder`1.DelegateServiceHandle.Start(HostControl hostControl)
at Topshelf.Hosts.ConsoleRunHost.Run()

Turns out there was a bug in Rebus' NLogLoggerFactory that would cause it to ask NLog to try to instantiate and use RebusConfigurer as a logger... as you have experienced, that cannot be done :)
I have fixed the bug, so if you update-packages Rebus.NLog in your solution, you should be good to go!
Thanks for reporting this issue!

Related

AutoMapper ResolutionContext does not contain a definition for engine anymore

After migration from an old version of AutoMapper (before 5) to version 9 there is one spot which causes headache. Old implementation:
.ForMember(a => a.Definition, o =>
{
o.Condition(s => s.TypeId == DocumentationType.Medication);
o.ResolveUsing((d, ctx) => ctx.Engine.Map<MedicationDefinitionContent>(d.Content.MedicationContentData));
})
which uses this extension method:
public static class MappingExtensions
{
public static void ResolveUsing<TType>(this IMemberConfigurationExpression<TType> expression, Func<TType, ResolutionContext, object> map)
{
expression.ResolveUsing(result => map((TType)result.Value, result.Context));
}
}
I fixed the first error that that IMemberConfigurationExpression needs 3 arguments, but then I learned that ResolutionContext does not contain a definition for engine anymore. I looked in the upgrade guide of version 5 and found that the ResolutionContext has been changed, but I do not understand how to fix this. The code seems to be pretty tricky. Can someone help, please?
#Lucian Bargaoanu
Ok, but the member "Definition" is the member wie map with MapFrom(s => s.Content.MedicationContentData). So different to the exception there is already a mapping. The member "Definition" is of type SerialisationHelper a helper class for Json stuff. It also has a mapping.
CreateMap<MedicationDefinitionContent, SerialisationHelper>()
.IgnoreAllUnmapped()
.AfterMap((s, t) => t.Write = s);
And MedicationDefinitionContent has a separate mapping.
CreateMap<MedicationContentData, MedicationDefinitionContent>()
MedicationDefinitionContent is annotated with [JsonObject(MemberSerialization.OptIn)]
so, a direct mapping from MedicationDefinitionContent to "Definition" does not work.
How you see I try to understand it, but maybe it needs more time.

How to solve StackOverflowException after upgrading from AutoMapper 8 to 11.0.0

https://github.com/beolafsen/TestAutomapperAndStripe
I get this errors after upgrade AutoMapper.Extensions.Microsoft.DependencyInjection from 8.1.1 to 11.0.0.
The messages I get are:
"An unhandled exception of type 'System.StackOverflowException' occurred in System.Private.CoreLib.dll."
(No other hint where or what causes the error).
and
I use .Net 6.0/BlazorServerSide
I have found that the following Automapper definitions are causing the error.
using Stripe;
CreateMap<VMStripeInvoiceItem, Stripe.InvoiceItem>();
CreateMap<Stripe.InvoiceItem, VMStripeInvoiceItem>()
.ForMember(pts => pts.LineAmount, opt => opt.MapFrom(ps => ps.Quantity * (ps.UnitAmountDecimal ?? (decimal)0) * (decimal)0.01))
.ForMember(pts => pts.UnitAmountDecimal, opt => opt.MapFrom(ps => (ps.UnitAmountDecimal ?? (decimal)0) * (decimal)0.01));
public class VMStripeInvoiceItem : InvoiceItem
{
public decimal LineAmount { get; set; }
}
How can this be solved?
Thanks for helping!
Best regards
BEO

Preferences library is causing E/libc & E/Pref errors

I'm building a weather app using MVVM and retrofit and i recently added a PreferencesFragmentCompat subclass to implement some user settings using the preferences lib. After doing so, my app won't run and i keep getting these few lines of errors :
2020-04-08 00:54:12.346 18079-18079/? E/de.flogaweathe: Unknown bits set in runtime_flags: 0x8000
2020-04-08 00:54:12.410 18079-18079/com.nesoinode.flogaweather E/libc: Access denied finding property "ro.vendor.df.effect.conflict"
2020-04-08 00:54:12.421 18079-18110/com.nesoinode.flogaweather E/Perf: Fail to get file list com.nesoinode.flogaweather
2020-04-08 00:54:12.421 18079-18110/com.nesoinode.flogaweather E/Perf: getFolderSize() : Exception_1 = java.lang.NullPointerException: Attempt to get length of null array
2020-04-08 00:54:12.421 18079-18110/com.nesoinode.flogaweather E/Perf: Fail to get file list oat
2020-04-08 00:54:12.422 18079-18110/com.nesoinode.flogaweather E/Perf: getFolderSize() : Exception_1 = java.lang.NullPointerException: Attempt to get length of null array
I've got no idea what these are and i can't find any specific answers on stack or google.There are no indications on what is causing the error so i can't figure out if i'm doing something wrong or if it is a library issue. Any ideas?
Here's the SettingsFragment where i'm adding the preferences from an xml resource file :
class SettingsFragment : PreferenceFragmentCompat() {
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
addPreferencesFromResource(R.xml.settings_prefs)
}
}
And here's how i'm reading some values from the sharedPrefs:
class UnitProviderImpl(context: Context) : UnitProvider {
private val appContext = context.applicationContext
private val preferences:SharedPreferences
get() = PreferenceManager.getDefaultSharedPreferences(appContext)
override fun getUnitSystem(): String {
val selectedUnitSystemName = preferences.getString(UNIT_SYSTEM_KEY,
UnitSystem.SI.name.toLowerCase(Locale.ROOT))
return selectedUnitSystemName!!
}
}
I managed to figure out a solution to the issue after doing some more research. Firstly, i commented out all the code related to the preferences library (and the lib itself) and run the app again. The run was successful without any errors so that narrowed it down to the androidx.preference:preference-ktx:1.1.0 library itself since my code was reviewed and couldn't find any issues with it. Looking through the preference docs i figured i could try out a beta or alpha version that may have fixed this issue. And lo and behold, after using the androidx.preference:preference-ktx:1.1.0-beta01 beta version and uncommenting the relative code, everything worked once again.

Spring Integration DSL equivalent for 'int-jms:message-driven-channel-adapter' with 'subscription-shared' option

we have a configuration from a MessageDrivenChannelAdapter like this
<int-jms:message-driven-channel-adapter channel="..."
connection-factory="..."
destination-name="..."
pub-sub-domain="true"
subscription-name="..."
subscription-shared="true"
subscription-durable="true"
auto-startup="..."
error-channel="errorChannel"/>
I have been able to replicate most of the configuration:
JmsMessageDrivenChannelAdapterListenerContainerSpec<JmsDefaultListenerContainerSpec, DefaultMessageListenerContainer> destination = Jms
.messageDrivenChannelAdapter([connection-factory])
.destination([destination-name])
.autoStartup([auto-startup])
.configureListenerContainer(c -> c
.pubSubDomain(true)
.subscriptionDurable(true)
.durableSubscriptionName([subscription-name])
)
.errorChannel(errorChannel);
But I can't find in the DSL how to mark the subscription as shared
How this should be achieved?
Thanks for your help
Huh! I think we have just missed to expose an option for the public void setSubscriptionShared(boolean subscriptionShared) {.
Please, raise a JIRA ASAP and we will fix it in the release today.
As a workaround I suggest to use fallback to the AbstractMessageListenerContainer:
.configureListenerContainer(c -> { c
.pubSubDomain(true)
.subscriptionDurable(true)
.durableSubscriptionName([subscription-name]);
DefaultMessageListenerContainer messageListenerContainer = c.get();
messageListenerContainer.setSubscriptionShared(true);
}
)

How to map an int to a boolean

I'm using AutoMapper 5.2. I currently have a mapping statement that looks as follows:
CreateMap<JeffreysOnline.Data.Customer, JeffreysOnline.Entities.Customer>()
.ForMember(s => s.CustomerWant, t => t.Ignore());
Both the Customer table and Customer entity have a field named BadChecks. In the database it's an int. I recently changed the type to a bool in my entity. AutoMapper is now giving me the following error:
Unable to create a map expression from Customer.BadChecks (System.Int16) to Customer.BadChecks (System.Boolean) Mapping types: Customer -> Customer JeffreysOnline.Data.Customer -> JeffreysOnline.Entities.Customer Type Map configuration: Customer -> Customer JeffreysOnline.Data.Customer -> JeffreysOnline.Entities.Customer Property: BadChecks
It seems AutoMapper doesn't know how to map from an int to a boolean. Is it possible for me to help AutoMapper with this?
It may be helpful to know that in my DAL, I'm using ProjectTo() to pass an IQueryable to another method that is attempting to access the data, and therefore the mapping is occurring (an error being generated). My DAL code looks like this:
return entityList.OrderBy(row => row.LastName).ProjectTo<Entities.Customer>();
Automapper 6.0.2 - works without any ForMember... null, 0 = false, values >= 1 are mapped to true.
In Automapper 6.0.2 - other way:
class nnnProfile : Profile
{
CreateMap<src, dst>()
.ForMember(d => d.Decision, opt => opt.ResolveUsing<CustomBoolResolver>());
}
Resolver:
public class CustomBoolResolver : IValueResolver<src, dst, bool>
{
public bool Resolve(src source, dst destination, bool destMember,
ResolutionContext context)
{
return source.Decision == 1;
}
}
but this is per Destination, so not much flexible.
According to this page:
http://taswar.zeytinsoft.com/automapper-mapping-objects-part-5-of-7-customresolver/
In past you could write a custom resolver with just Source and target type.
I don't think I would know how to map from int to a boolean.
If you do figure out how that should happen, you'll need to create a mapping from int to boolean.:
CreateMap<int, bool>().ProjectUsing(src => src != 0);
Completely guessing there. But since you're using ProjectTo, you'll need to use ProjectUsing so that the expression makes it allllll the way down to your DAL.
Remember, when using ProjectUsing, AutoMapper isn't actually executing the mapping. It's creating a LINQ "Select" expression that it passes down to your query provider (EF maybe?). So you'll need to make sure that whatever you use in your projection expression, EF can support translating that eventually into SQL.

Resources