You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've encountered a curious problem in my project that I'm sadly unable to reproduce with fresh templates, but someone here might have a clue, as I don't want to spend whole day researching this. (Also it might help in case I'm not alone)
Problem lies in MongoDB template test I've implemented without any changes into my existing solution that is already highly modified former template. This line will throw NullReferenceException.
With fresh template, this change isn't necessary, it just works with field giving me proper headache 😕. Wouldn't property make more sense there though?
ABP 2.8.0
.NET Core SDK 3.1.300
Message:
Volo.Abp.AbpInitializationException : An error occurred during ConfigureServices phase of the module MyProject.MongoDB.MyProjectMongoDbTestModule, MyProject.MongoDB.Tests, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null. See the inner exception for details.
---- System.TypeInitializationException : The type initializer for 'MyProject.MongoDB.MongoDbFixture' threw an exception.
-------- System.NullReferenceException : Object reference not set to an instance of an object.
Stack Trace:
ModuleLoader.ConfigureServices(List`1 modules, IServiceCollection services)
ModuleLoader.LoadModules(IServiceCollection services, Type startupModuleType, PlugInSourceList plugInSources)
AbpApplicationBase.LoadModules(IServiceCollection services, AbpApplicationCreationOptions options)
AbpApplicationBase.ctor(Type startupModuleType, IServiceCollection services, Action`1 optionsAction)
AbpApplicationWithExternalServiceProvider.ctor(Type startupModuleType, IServiceCollection services, Action`1 optionsAction)
AbpApplicationFactory.Create(Type startupModuleType, IServiceCollection services, Action`1 optionsAction)
AbpApplicationFactory.Create[TStartupModule](IServiceCollection services, Action`1 optionsAction)
ServiceCollectionApplicationExtensions.AddApplication[TStartupModule](IServiceCollection services, Action`1 optionsAction)
AbpIntegratedTest`1.ctor()
MyProjectTestBase`1.ctor()
MyProjectApplicationTestBase.ctor()
SampleAppServiceTests.ctor() line 18
----- Inner Stack Trace -----
MyProjectMongoDbTestModule.ConfigureServices(ServiceConfigurationContext context) line 16
ModuleLoader.ConfigureServices(List`1 modules, IServiceCollection services)
----- Inner Stack Trace -----
MongoDbFixture.cctor() line 8
The text was updated successfully, but these errors were encountered:
Bingo! It indeed is caused by the order of fields, why didn't I think of that?! The reason why I encountered this is quite simple too, I'm using the popular CodeMaid VS extension that by default sorts member fields by access modifier & alphabetically and never have I encountered this issue before.
This leads me to believe this is highly unusual pattern for class member fields we have here. In my opinion this shouldn't even make it through the compiler. While member field declarations are order agnostic and therefore compiler won't complain if you reference one from another in any order, it's unintuitive code since initialization is still ordered sequence.
Like in this example, one would totally expect either compiler to throw, and if not, then some output from the FooBar. And yet neither will happen ...
I've encountered a curious problem in my project that I'm sadly unable to reproduce with fresh templates, but someone here might have a clue, as I don't want to spend whole day researching this. (Also it might help in case I'm not alone)
Problem lies in MongoDB template test I've implemented without any changes into my existing solution that is already highly modified former template. This line will throw NullReferenceException.
abp/templates/app/aspnet-core/test/MyCompanyName.MyProjectName.MongoDB.Tests/MongoDb/MongoDbFixture.cs
Line 9 in bfce4c2
It's curious because if I change that public field into property.
It suddenly works fine ...
With fresh template, this change isn't necessary, it just works with field giving me proper headache 😕. Wouldn't property make more sense there though?
ABP 2.8.0
.NET Core SDK 3.1.300
The text was updated successfully, but these errors were encountered: