I have developed a Library for internal email reporting. When I am using that Library from another project (By Adding Reference).
It gives NullReferenceException
on the following line.
System.Reflection.Assembly.GetEntryAssembly().GetName().Name
Any idea, why Assembly is null?
This error is caused when an object is trying to be used by a script but does not refer to an instance of an object. To fix this example we can acquire a reference to an instance of the script using GameObject. Find to find the object it is attached to.
Use Null Coalescing to Avoid NullReferenceExceptions It works with all nullable data types. The following code throws an exception without the null coalescing. Adding “?? new List<string>()” prevents the “Object reference not set to an instance of an object” exception.
A NullReferenceException exception is thrown when you try to access a member on a type whose value is null . A NullReferenceException exception typically reflects developer error and is thrown in the following scenarios: You've forgotten to instantiate a reference type.
The best way to avoid the "NullReferenceException: Object reference not set to an instance of an object” error is to check the values of all variables while coding. You can also use a simple if-else statement to check for null values, such as if (numbers!= null) to avoid this exception.
This is expected especially in the Windows Services where they are loaded by an unmanaged runtime.
Use:
Process.GetCurrentProcess().MainModule.FileName
To get unmanaged entry point file.
It seems you are looking for this:
System.Reflection.Assembly.GetExecutingAssembly().GetName().Name
problem is solved guys,
I am using
Assembly.GetAssembly(ex.TargetSite.DeclaringType.UnderlyingSystemType).GetName().Name
to get the EntryAssemblyName.
In this case I already has parameter which is taking Exception 'ex', so I solved it by using that.
Many Thanks Guys, specially @Aliostad
Cheers
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With