Skip to content
This repository has been archived by the owner on Sep 24, 2024. It is now read-only.

Unhandled Exception: System.NullReferenceException: #12

Open
daniel-agc opened this issue Feb 26, 2019 · 16 comments
Open

Unhandled Exception: System.NullReferenceException: #12

daniel-agc opened this issue Feb 26, 2019 · 16 comments
Assignees
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@daniel-agc
Copy link

Hi,

First off thank you for this agent, it has saved me allot of time!

Unfortunatley though on a fresh windows 10 install that has been updated through windows update I get this error message.

Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object.
at Marksman.Sentry.RunWMI()
at Marksman.Marksman.Main(String[] args)

Any assistance would be appreciated

@boingball
Copy link
Contributor

I'm also getting this on an clean Windows 10 Lenovo 20L7S2A000 (Thinkpad T480s)
Not getting this on any other asset at the moment so looks model specific in my case.

@boingball
Copy link
Contributor

I've ran v1.0.1 in debug mode on that asset and the lines of code it bombs out on is :


27/02/2019 10:15:49: Started application.

Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object.
at Marksman.Sentry.RunWMI() in \server\users$\username\Documents\Visual Studio 2017\GIT\Marksman-v1.0.1\marksman-master\Marksman.cs:line 197
at Marksman.Sentry.Run() in \server\users$\username\Documents\Visual Studio 2017\GIT\Marksman-v1.0.1\marksman-master\Marksman.cs:line 290
at Marksman.Marksman.Main(String[] args) in \server\users$\username\Documents\Visual Studio 2017\GIT\Marksman-v1.0.1\marksman-master\Marksman.cs:line 338

Looks like it's this part
// Display all properties.
foreach (PropertyData property in m.Properties)
{
string propertyValue = "";
if (!String.IsNullOrWhiteSpace(property.Value.ToString()))

@boingball
Copy link
Contributor

Ok I've ran Visual Studio 2017 on the problem asset

Stepping through the PropertyValues that come in.
Serial Number, Computer Name, 2, Model, BIOS Version, MAC Address, Network Manufacturer, Network Adapter Model, Disk Drive Model x 2, Disk Drive Serial Number, null, Then crash.

WMI Query at the time SELECT Manufacturer,Model,SerialNumber,Size FROM Win32_DiskDrive

HDD Details on this device

Manufacturer

(Standard disk drives)
(Standard disk drives)

Model

Generic- SD/MMC USB Device
LENSE30512GMSP34MEAT3TA

SerialNumber

2012090114345300
A032_99DE_A00E_0423.

Size

512105932800

Taking out Size from (Line 322 on Marksman.cs) mySentry.AddQuery("WMI", "SELECT Manufacturer,Model,SerialNumber, FROM Win32_DiskDrive");

Lets the App continue
Null Size for Generic- SD/MMC USB Device causing this issue maybe?

@daniel-agc
Copy link
Author

Hi boingball,

thanks for looking into this. Is there any chance you could build this for me without the size query as the assets which are failing are all with SD readers.

Sorry im not versed in compiling visual studio projects and attempted this myself but didn't get very far

@boingball
Copy link
Contributor

This is the Marksman.exe file without the Size part of the WMI query in it
Line 322 - mySentry.AddQuery("WMI", "SELECT Manufacturer,Model,SerialNumber FROM Win32_DiskDrive");
Marksman.zip
Just replace your current Marksman.exe in your installation folder.

I can't make a full installer as my Visual Studio 2017 is incompatible with the Setup program.

@velaar
Copy link
Contributor

velaar commented Feb 28, 2019

Thank you for investigating it.
Any chance you can create a pull request? We can remove the query for now and rebuild the release, but let me explain something. Originally we planned to include components and automatically assign/update components per machine. That part of the code was written to collect the most essential data (like HDD serials). It doesn't work that way yet and I am not sure if it will.

Also, if there are features that you think are missing, please create an issue.

@velaar velaar added bug Something isn't working help wanted Extra attention is needed labels Feb 28, 2019
@boingball
Copy link
Contributor

boingball commented Feb 28, 2019

Hi Velaar,

Will do.

I'm using a custom version of your 1.0.1 code and I added CPU Name, OS Version, Memory Size + Model Name - I also fixed the Mac Address adder (It was trying to use a different field name to the one in my SnipeIT database)

I run this Marksman.exe as part of our PXE network build - so when a computer is built, it runs Marksman automatically and add's this to SnipeIT with the custom details I want.

I could do with a Marksman that could update current assets but looking at the code there's a lot to program to make that happen.

Cheers,
bOingball

@aldervall
Copy link

Iam getting this error.

2019-07-24 14:28:09: Started application.
HTTP 200: Connection to Snipe-IT instance succeded.
Attempting to create type: SnipeSharp.Endpoints.Models.Manufacturer
Instance name: Dell Inc.
Attempting to create type: SnipeSharp.Endpoints.Models.Category
Instance name: Laptop
Already exists in DB
Attempting to create type: SnipeSharp.Endpoints.Models.Model
Instance name: Latitude 7490

Ohanterat undantag: SnipeSharp.Exceptions.RequiredValueIsNullException: Property Manufacturer cannot be null.
vid SnipeSharp.Endpoints.QueryParameterBuilder.GetParameters(Object item)
vid SnipeSharp.Common.RequestManagerRestSharp.Post(String path, ICommonEndpointModel item)
vid SnipeSharp.Endpoints.EndpointManager`1.Create(T toCreate)
vid Marksman.Broker.SyncAll(SnipeItApi snipe, Asset currentAsset, Model currentModel, Manufacturer currentManufacturer, Category currentCategory, Company currentCompany, StatusLabel currentStatusLabel, Location currentLocation)
vid Marksman.Marksman.Main(String[] args)

@jajabro1
Copy link

I'm gonna bump this, it still seems to be broken on version 1.5 which hasn't been stated by other people. Even building from scratch.

@dwildey
Copy link

dwildey commented Jan 27, 2020

UPDATE: I found my problem to be with removing keys "<add key=" in the config file.


I am getting unhandled exceptions as well on 1.5:

1/27/2020 11:57:34 AM: Started application.
HTTP 200: Connection to Snipe-IT instance succeded.
Attempting to create type: SnipeSharp.Endpoints.Models.Manufacturer
Instance name: innotek GmbH
Already exists in DB
Attempting to create type: SnipeSharp.Endpoints.Models.Category
Instance name: Laptop
Already exists in DB
Attempting to create type: SnipeSharp.Endpoints.Models.Model
Instance name: VirtualBox
Already exists in DB
Attempting to create type: SnipeSharp.Endpoints.Models.Company

Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object.
at SnipeSharp.Endpoints.EndpointManager`1.Create(T toCreate)
at Marksman.Broker.SyncAll(SnipeItApi snipe, Asset currentAsset, Model currentModel, Manufacturer currentManufacturer, Category currentCategory, Company currentCompany, StatusLabel currentStatusLabel, Location currentLocation)
at Marksman.Marksman.Main(String[] args)

Also tried patched Marksman.zip from boingball - Same result.

@Mike1002
Copy link
Contributor

I was also suffering from this - I had diagnosed it as an issue with the DiskDrive WMI query and traced it down to the "Windows Sandbox" feature.

It looks like some of the information the query looks for isnt available for the "Portable Base Layer" VHD that Microsoft use as the Windows Sandbox location.

I replaced line 322 with the below to get the "correct" drive, now runs without a hitch!
SELECT Manufacturer,Model,SerialNumber FROM Win32_DiskDrive WHERE Index=0

I'll submit a PR with this change, I believe that Index 0 should always the drive where Windows is running from.

@Larsje3112
Copy link

I was also suffering from this - I had diagnosed it as an issue with the DiskDrive WMI query and traced it down to the "Windows Sandbox" feature.

It looks like some of the information the query looks for isnt available for the "Portable Base Layer" VHD that Microsoft use as the Windows Sandbox location.

I replaced line 322 with the below to get the "correct" drive, now runs without a hitch!
SELECT Manufacturer,Model,SerialNumber FROM Win32_DiskDrive WHERE Index=0

I'll submit a PR with this change, I believe that Index 0 should always the drive where Windows is running from.

Is it possible for you to recompile it and release a new version with this problem fixed?

@danielhogg
Copy link
Contributor

Hi Mike, thanks for the pull request. I'll release a recompiled version this weekend.

@Larsje3112
Copy link

@danielhogg

Hello Daniel,

Were you able to recompile a new version?

Thanks

@rickardhildingsson
Copy link

Any update?

@AndrewJames1979
Copy link

HI also Having issues - Please Help would love an agent for snipe-it

:\Program Files (x86)\Scope-IT\Marksman>Marksman.exe
17/08/2023 7:20:04 PM: Started application.
HTTP 200: Connection to Snipe-IT instance succeded.
Attempting to create type: SnipeSharp.Endpoints.Models.Manufacturer
Instance name: HP
Already exists in DB
Attempting to create type: SnipeSharp.Endpoints.Models.Category
Instance name: Laptop

Unhandled Exception: Newtonsoft.Json.JsonSerializationException: Error converting value {null} to type 'System.Boolean'. Path 'rows[0].eula', line 1, position 134. ---> System.InvalidCastException: Null object cannot be converted to a value type.
at System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.EnsureType(JsonReader reader, Object value, CultureInfo culture, JsonContract contract, Type targetType)
--- End of inner exception stack trace ---
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.EnsureType(JsonReader reader, Object value, CultureInfo culture, JsonContract contract, Type targetType)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.ResolvePropertyAndCreatorValues(JsonObjectContract contract, JsonProperty containerProperty, JsonReader reader, Type objectType)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObjectUsingCreatorWithParameters(JsonReader reader, JsonObjectContract contract, JsonProperty containerProperty, ObjectConstructor1 creator, String id) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateNewObject(JsonReader reader, JsonObjectContract objectContract, JsonProperty containerMember, JsonProperty containerProperty, String id, Boolean& createdFromNonDefaultCreator) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateList(IList list, JsonReader reader, JsonArrayContract contract, JsonProperty containerProperty, String id) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateList(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, Object existingValue, String id) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty property, JsonConverter propertyConverter, JsonContainerContract containerContract, JsonProperty containerProperty, JsonReader reader, Object target) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent) at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType) at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings) at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings) at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value) at SnipeSharp.Endpoints.EndpointManager1.FindOne(ISearchFilter filter)
at SnipeSharp.Endpoints.EndpointManager`1.Create(T toCreate)
at Marksman.Broker.SyncAll(SnipeItApi snipe, Asset currentAsset, Model currentModel, Manufacturer currentManufacturer, Category currentCategory, Company currentCompany, StatusLabel currentStatusLabel, Location currentLocation)
at Marksman.Marksman.Main(String[] args)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests