due to an oversight on my part (still new to AppState and Session variables) I have to change all of my AppStates to Session variables. WebMatrix's replace has made that part easy, however I am now getting this error on the first of the two lines of code below:
Session["gActionMessage"] = "";
Session["gActionMessageDisplayed"] = "not";
Error:
Compiler Error Message: CS0103: The name 'Session' does not exist in the current context
If it matters, these lines of code are in my _AppStart.cshtml file.
Any suggestions? Do I have the syntax wrong?
Sessions are not available at the point that the _AppStart.cshtml file is executed. That happens too early in the pipeline. You can use _PageStart.cshtml to initialise session variables.
Related
I have a base class, called Telegram, and I would like to translate a string into a list of such telegrams.
Therefore I have the following piece of code:
private IEnumerable<Telegram> ExtractTelegrams(string telegramString)
{
var telegramArray = telegramString.Split(new char[] { "\u0003", "\u0006" },
StringSplitOptions.RemoveEmptyEntries);
foreach (var currentTelegram in telegramArray)
{
... <=== here I set my breakpoint
I know this code mostly works (it's been thouroughly tested), but now I'm having an extra look and I'm trying to debug that piece of code, but that's not working: this is the message in my immediate window:
? telegramArray
error CS0103: The name 'telegramArray' does not exist in the current context
? currentTelegram
error CS0103: The name 'currentTelegram' does not exist in the current context
Why is this? I'm working with "Debug" build of my application, and that telegramArray and currentTelegram are used afterwards. I know from the runtime that it works but I can't see in the debugger WHY it works. Are there problems with the var keyword, the private keyword, ...
I'm using Orchard to build my website and want to add different elements for production environment and test environemnt in the Themes. I tried to use a c# singleton class in Orchard Themes class to get if it is production environment. Then use the singleton class in the cshtml file in Themes. The code can be compiled. But in run time, it will throw exception saying:The name 'Themes' does not exist in the current context. I have to add "Themes" namespace before the class I added. Otherwise, it won't pass compile.
Details:
I added a singleton class: EnvironmentDev.cs file into Themes.csproj file. It contains static GetInstance method and IsProd property.
In Themes.csproj file, it shows:
<ItemGroup>
<Compile Include="EnvironmentDev.cs" />
</ItemGroup>
In Document.cshtml file of Themes, I added following code:
#{
if (Themes.EnvironmentDev.GetInstance().IsProd) {
// Add production element
}
else {
// Add test site element
}
}
Detailed Error message:
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS0103: The name 'Themes' does not exist in the current context
Source Error:
Line 46: #Display(Model.Head)
Line 47: #{
Line 48: if (Themes.EnvironmentDev.GetInstance().IsProd) {
Line 49: <script src="https://XXXX.js"></script> //using XXXX instead of real link
Line 50: }
Any suggestions would be appreciated.
I think you need to create a dedicated project for your theme with the following command
codegen theme MyTheme /CreateProject:true /IncludeInSolution:true
otherwise your code will not be found. I had the same issue with a resource file.
See paragraph Generating the Theme Structure in the docs for further information.
I needed to make a change to my webAPI service and what happened was I lost my project files. I had the dll file so I decompiled the file and got my code back. When I tried to build the solution I got an error.
Can anyone tell me why am I getting this error?
The reference to Microsoft.Practices.EnterpriseLibrary.Data exist in my code.
I could not find what is it that causes the error.
The error occurs on the line:
DbCommand dbCommand = databaseObject.get_DbProviderFactory().CreateCommand();
The DatabaseObject type has a property for DbProviderFactory, something like:
public DbProviderFactory DbProviderFactory { get; set; }
In C# properties are compiled to a backing field and a get_Foo() and set_Foo() method. What you're seeing is the decompiled get accessor.
You can change it back to a property access instead of a method call:
DbCommand dbCommand = databaseObject.DbProviderFactory.CreateCommand();
This is also explained in among others get form proterty `cannot explicitly call operator or accessor` and Unable to run Console Application in c#. And please start using version control to prevent the loss of source code.
i have a list of struct
list who have a detail of stuff.
i need a another string info with this list.
so i wrote many function already who is used in my project
so i make a new list
who called stuffdetailedanother
who have a stuffdetailed stuff
and string info;
but when i send it to page using viewdata then he not worked when i use immediate window everything is fine.
are any another way i use ?
or how to pass him to a control
i pass it by a way
controller > View > Partial view
but it is not worked
i got the error
Server Error in '/' Application.
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS1519: Invalid token '(' in class, struct, or interface member declaration
Source Error:
Line 347: #line default
Line 348: #line hidden
Line 349: #__w.Write("\r\n </div>\r\n</div>\r\n");
Line 350: }
Line 351:
Source File: c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\2114142c\1d077c0d\App_Web_wishproductlist.ascx.89207646.1grmjmuq.0.cs Line: 349
The problem is that you have a syntax error on line 351 of your ASPX file. Take a closer look at it. If you don't understand why it's not compiling, post the code.
The problem is that the following line:
#__w.Write("\r\n </div>\r\n</div>\r\n");
(Line 349 in App_Web_wishproductlist.ascx.cs) contains a syntax error - probably the # symbol.
Without knowing more context its difficult to know what other advice to give, however hopefully this helps make the error a little clearer.
I am trying to access my local resources file in my code-behind. I did some googling since I was unsure of how to do it and found this:
oContent.Text = HttpContext.GetLocalResourceObject("NonSupport").ToString();
However, I get an error saying that it needs at least two parameters: VirtualPath and ResourceKey. There is a third, CultureInfo but that one is optional. When I put this in as my virtual path:
HttpContext.GetLocalResourceObject("App_LocalResources/ExpandableListView.aspx.resx", "NonSupport").ToString();
I get the following compiler error message:
The relative virtual path 'App_LocalResources/ExpandableListView.aspx.resx' is not allowed here.
I must be doing something wrong with this since my searches (and some posts I found on here) say all I need to do is call the resource key.
Any thoughts? Thanks!
Did you put a resource file with the name (your aspx web page).aspx.resx into a App_LocalResource folder underneath the path where your ASPX page lives??
Furthermore, just simply call the GetLocalResourceObject method on your current page:
oContent.Text = GetLocalResourceObject("NonSupport").ToString();
No need to use HttpContext for that - the method is defined on the Page class.
Marc