C
C#2y 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
EliasGPS2y ago
EliasGPS
EliasGPS2y ago
this is my code
EliasGPS
EliasGPS2y 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
EliasGPS2y ago
EliasGPS
EliasGPS2y ago
i did this
cap5lut
cap5lut2y 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
EliasGPS2y ago
i don't needs to return anything it just needs to active my contentType
EliasGPS
EliasGPS2y ago
EliasGPS
EliasGPS2y ago
if i don't active it it stays draft so i need to active is it
cap5lut
cap5lut2y 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
EliasGPS2y 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
cap5lut2y ago
thats why im asking what that call returns if its giving ya a new version, then u should use that
EliasGPS
EliasGPS2y ago
you mean
EliasGPS
EliasGPS2y ago
EliasGPS
EliasGPS2y ago
what this peace of code returns?
cap5lut
cap5lut2y ago
yep
EliasGPS
EliasGPS2y ago
just a second when i do a console.writline i get no error
EliasGPS
EliasGPS2y ago
EliasGPS
EliasGPS2y ago
this is the output
EliasGPS
EliasGPS2y ago
EliasGPS
EliasGPS2y ago
so yeah
EliasGPS
EliasGPS2y ago
EliasGPS
EliasGPS2y ago
so yeah that is the reutn value
cap5lut
cap5lut2y 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
EliasGPS2y ago
EliasGPS
EliasGPS2y ago
oh yeah something like this
EliasGPS
EliasGPS2y ago
cap5lut
cap5lut2y ago
⤴️
EliasGPS
EliasGPS2y ago
?? still the error
EliasGPS
EliasGPS2y ago
EliasGPS
EliasGPS2y ago
this error is so strang it thinks that someone else is editing something
cap5lut
cap5lut2y 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
EliasGPS2y ago
no i removed the var
EliasGPS
EliasGPS2y ago
EliasGPS
EliasGPS2y ago
but i can try your code
cap5lut
cap5lut2y 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
EliasGPS2y ago
yeah i see but red line
EliasGPS
EliasGPS2y ago
EliasGPS
EliasGPS2y ago
hahahaha
cap5lut
cap5lut2y ago
good that u dont provide the error message to make it harder for us to help u .....
EliasGPS
EliasGPS2y ago
EliasGPS
EliasGPS2y ago
lol
cap5lut
cap5lut2y ago
oh, then try adding a ! add the end: ....SystemProperties.Version! do u know the difference between int? and int ?
EliasGPS
EliasGPS2y ago
nope
cap5lut
cap5lut2y ago
the first is nullable, the latter not
EliasGPS
EliasGPS2y ago
it worked thx man you are a legend
EliasGPS
EliasGPS2y ago
EliasGPS
EliasGPS2y ago
this is the final code
EliasGPS
EliasGPS2y ago
EliasGPS
EliasGPS2y ago
perfect
cap5lut
cap5lut2y ago
result.SystemProperties.Version! didnt work? or didnt u just try? because the latter would be more expressive
EliasGPS
EliasGPS2y ago
didn't work
cap5lut
cap5lut2y ago
what was the error?
EliasGPS
EliasGPS2y ago
EliasGPS
EliasGPS2y ago
so i just did the quik fix hahaha
cap5lut
cap5lut2y ago
aaah, yeah the ! was indeed wrong
EliasGPS
EliasGPS2y ago
but
EliasGPS
EliasGPS2y ago
EliasGPS
EliasGPS2y ago
if i do it so than there is no yellow line now there is
EliasGPS
EliasGPS2y ago
EliasGPS
EliasGPS2y ago
so yeah
cap5lut
cap5lut2y ago
! tells the compiler basically "at this point this nullable value can not be null, the (int) then just is a cast
EliasGPS
EliasGPS2y ago
ahh
cap5lut
cap5lut2y ago
u could have also written ....Version!.Value i guess
EliasGPS
EliasGPS2y ago
ah ok but thx alot for solving my problem
cap5lut
cap5lut2y ago
semantically u surely have a version at that point, because u either created it or updated it
EliasGPS
EliasGPS2y ago
yeah yeah
cap5lut
cap5lut2y 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
cap5lut2y ago
basically that:
cap5lut
cap5lut2y ago
@EliasGPS ⤴️
EliasGPS
EliasGPS2y ago
ohh ok
Accord
Accord2y ago
✅ This post has been marked as answered!
Want results from more Discord servers?
Add your server
More Posts