C
C#3y ago
EliasGPS

Contentful problem version [Answered]

i'm trying to activate my content type. When i run my code i get this error. Anyone can help?
72 Replies
EliasGPS
EliasGPSOP3y ago
EliasGPS
EliasGPSOP3y ago
this is my code
EliasGPS
EliasGPSOP3y ago
Using the Management API with Contentful and .NET
This article details how to use the management api using the .NET client library | Setting up your first request | Working with content types and entries
EliasGPS
EliasGPSOP3y ago
EliasGPS
EliasGPSOP3y ago
i did this
cap5lut
cap5lut3y ago
blindly guessing, but i would assume that client.CreateOrUpdateContentType(...) will return some data structure which gives ya the new content type version and because u r using the old version it complains. what's its return type?
EliasGPS
EliasGPSOP3y ago
i don't needs to return anything it just needs to active my contentType
EliasGPS
EliasGPSOP3y ago
EliasGPS
EliasGPSOP3y ago
if i don't active it it stays draft so i need to active is it
cap5lut
cap5lut3y ago
yeah, but u r either creating or updating the content type, thus it's version will probably change. and on trying to activate it, its complaining that the version doesnt match.... so most likely the fault lies in the wrong version parameter
EliasGPS
EliasGPSOP3y ago
but the thing is to create a contenttype i don't need to specify a version its only when i want to activate it
cap5lut
cap5lut3y ago
thats why im asking what that call returns if its giving ya a new version, then u should use that
EliasGPS
EliasGPSOP3y ago
you mean
EliasGPS
EliasGPSOP3y ago
EliasGPS
EliasGPSOP3y ago
what this peace of code returns?
cap5lut
cap5lut3y ago
yep
EliasGPS
EliasGPSOP3y ago
just a second when i do a console.writline i get no error
EliasGPS
EliasGPSOP3y ago
EliasGPS
EliasGPSOP3y ago
this is the output
EliasGPS
EliasGPSOP3y ago
EliasGPS
EliasGPSOP3y ago
so yeah
EliasGPS
EliasGPSOP3y ago
EliasGPS
EliasGPSOP3y ago
so yeah that is the reutn value
cap5lut
cap5lut3y ago
the Contentful.Core.Models.ContentType type has a SystemProperties member, which has a Version member, try to provide that one for the activation
EliasGPS
EliasGPSOP3y ago
EliasGPS
EliasGPSOP3y ago
oh yeah something like this
EliasGPS
EliasGPSOP3y ago
cap5lut
cap5lut3y ago
⤴️
EliasGPS
EliasGPSOP3y ago
?? still the error
EliasGPS
EliasGPSOP3y ago
EliasGPS
EliasGPSOP3y ago
this error is so strang it thinks that someone else is editing something
cap5lut
cap5lut3y ago
does ur code look like this right now?
var result = await client.CreateOrUpdateContentType(contentType);
await client.ActivateContentType(result.SystemProperties.Id, version: result.SystemProperties.Version);
var result = await client.CreateOrUpdateContentType(contentType);
await client.ActivateContentType(result.SystemProperties.Id, version: result.SystemProperties.Version);
if not please share urs
EliasGPS
EliasGPSOP3y ago
no i removed the var
EliasGPS
EliasGPSOP3y ago
EliasGPS
EliasGPSOP3y ago
but i can try your code
cap5lut
cap5lut3y ago
that chunk of code doesnt make any sense, u first try to activate something that might not exist yet, then u either create it or update it (which will then still not be activated)
EliasGPS
EliasGPSOP3y ago
yeah i see but red line
EliasGPS
EliasGPSOP3y ago
EliasGPS
EliasGPSOP3y ago
hahahaha
cap5lut
cap5lut3y ago
good that u dont provide the error message to make it harder for us to help u .....
EliasGPS
EliasGPSOP3y ago
EliasGPS
EliasGPSOP3y ago
lol
cap5lut
cap5lut3y ago
oh, then try adding a ! add the end: ....SystemProperties.Version! do u know the difference between int? and int ?
EliasGPS
EliasGPSOP3y ago
nope
cap5lut
cap5lut3y ago
the first is nullable, the latter not
EliasGPS
EliasGPSOP3y ago
it worked thx man you are a legend
EliasGPS
EliasGPSOP3y ago
EliasGPS
EliasGPSOP3y ago
this is the final code
EliasGPS
EliasGPSOP3y ago
EliasGPS
EliasGPSOP3y ago
perfect
cap5lut
cap5lut3y ago
result.SystemProperties.Version! didnt work? or didnt u just try? because the latter would be more expressive
EliasGPS
EliasGPSOP3y ago
didn't work
cap5lut
cap5lut3y ago
what was the error?
EliasGPS
EliasGPSOP3y ago
EliasGPS
EliasGPSOP3y ago
so i just did the quik fix hahaha
cap5lut
cap5lut3y ago
aaah, yeah the ! was indeed wrong
EliasGPS
EliasGPSOP3y ago
but
EliasGPS
EliasGPSOP3y ago
EliasGPS
EliasGPSOP3y ago
if i do it so than there is no yellow line now there is
EliasGPS
EliasGPSOP3y ago
EliasGPS
EliasGPSOP3y ago
so yeah
cap5lut
cap5lut3y ago
! tells the compiler basically "at this point this nullable value can not be null, the (int) then just is a cast
EliasGPS
EliasGPSOP3y ago
ahh
cap5lut
cap5lut3y ago
u could have also written ....Version!.Value i guess
EliasGPS
EliasGPSOP3y ago
ah ok but thx alot for solving my problem
cap5lut
cap5lut3y ago
semantically u surely have a version at that point, because u either created it or updated it
EliasGPS
EliasGPSOP3y ago
yeah yeah
cap5lut
cap5lut3y ago
im not sure about this but in my opinion ...Version!.Value would be more expressive than the (int) cast and please close ur open but answered threads with /close (didnt do it for #Powershell result to c [Answered] and #filter System.string [Answered] either)
cap5lut
cap5lut3y ago
basically that:
cap5lut
cap5lut3y ago
@EliasGPS ⤴️
EliasGPS
EliasGPSOP3y ago
ohh ok
Accord
Accord3y ago
✅ This post has been marked as answered!
Want results from more Discord servers?
Add your server