Próbuję zezwolić użytkownikowi na wprowadzanie danych do pola tekstowego, które zostanie dodane do pliku web.config. Dodałem linie relevent do pliku web.config, ale gdy zrobię tą klasę wszystko pójdzie nie tak.Otrzymuję "brakującą instrukcję użycia lub odniesienie do zespołu" i nie mam pojęcia, co się dzieje źle
Wciąż uzyskuję brakujące informacje o używaniu dyrektywy lub błędu refela zespołu podczas próby uruchomienia mojej aplikacji. Przyjrzałem się innym sytuacjom, kiedy zadawano to pytanie i nie mogę się domyślić, gdzie idę źle. Rzecz w tym, że jestem niezmiernie nowy w Visual Studio i jestem po prostu pozostawiony pusty, co może być odpowiedzią.
Poniżej znajduje się plik klasy, który generuje błąd. Mam nadzieję, że zawarłem wszystko, co potrzebujesz, aby mi pomóc. Dziękuję Ci.
using System.Collections.Generic;
using System.Linq;
using System.Configuration;
namespace WebConfigDemo
{
public class CompanyConfigSection : ConfigurationSection
{
[ConfigurationProperty("", IsRequired = true, IsDefaultCollection = true)]
public CompanyConfigCollection Companies
{
get
{
return (CompanyConfigCollection)this[""];
}
set
{
this[""] = value;
}
}
}
public class CompanyConfigElement : ConfigurationElement
{
[ConfigurationProperty("id", IsKey = true, IsRequired = true)]
public int Id
{
get
{
return (int)this["id"];
}
set
{
this["id"] = value;
}
}
[ConfigurationProperty("name", IsRequired = true)]
public string Name
{
get
{
return this["name"].ToString();
}
set
{
this["name"] = value;
}
}
} '
public class CompanyConfigCollection : ConfigurationElementCollection
{
protected override ConfigurationElement CreateNewElement()
{
return new CompanyConfigElement();
}
protected override object GetElementKey(ConfigurationElement element)
{
return ((CompanyConfigElement)element).Id;
}
}
public class CompaniesConfig
{
private static readonly Dictionary<int, CompanyConfigElement>
Elements;
static CompaniesConfig()
{
Elements = new Dictionary<int, CompanyConfigElement>();
var section = (CompanyConfigSection)ConfigurationManager.GetSection ("companies");
foreach (CompanyConfigElement system in section.Companies)
Elements.Add(system.Id, system);
}
public static CompanyConfigElement GetCompany(int companyId)
{
return Elements[companyId];
}
public static List<CompanyConfigElement> Companies
{
get
{
return Elements.Values.ToList();
}
}
}
} '
Każda pomoc jest mile widziana
generuje błąd, który wiersz? – ic3b3rg
Czy możesz nam powiedzieć, gdzie otrzymujesz błąd –
Musisz kilka rzeczy: –