C
C#5d ago
Salakhosh

My static String in library project becomes null when i enter a controller in API project

Hello so i have two projects. A library project(where you define models and call API Controllers) and API project. In library project , i defined a static class with static string and string is not null. but i am having a problem when i call a controller this string becomes null and when i exit the controller , it returns to its ordinary value. Does someone know how or why? Thanks in advance
5 Replies
Angius
Angius5d ago
Does the string get reassigned at any point maybe? Why not make it a const, that will stop that from happening
Salakhosh
SalakhoshOP5d ago
no it doesnt only once
Angius
Angius5d ago
Or store it in the config file and read from there instead Variables, generally, don't just change value spontaneously So something fucky-wucky is going on Try using a const and see if it still happens
Salakhosh
SalakhoshOP5d ago
will do ok turns out i cant do that because im binding the variable in another library(and i cant change that) lol but i tried doing that and it worked
Angius
Angius5d ago
If there's a binding to that variable, it could be that that's what changes it You could do something like
private const string _myStr = "my string";
public string MyStr => _myStr;
private const string _myStr = "my string";
public string MyStr => _myStr;
and bind to MyStr maybe

Did you find this page helpful?