asp.net mvc code not getting compiled on server - asp.net-mvc

i have this code in one of my asp.net mvc views:
<%Html.RenderFile(#"C:\Members\newsletters\welcome.html");%>
I have created an extension on the Html class to read in a file. the code looks like this:
public static class HtmlRenderer
{
public static void RenderFile(this HtmlHelper helper_, string path_)
{
var reader = new StreamReader(path_);
var contents = reader.ReadToEnd();
helper_.ViewContext.HttpContext.Response.Write(contents);
}
}
This all works perfectly when i run in visual studio on my desktop but when i ftp these files to the server, i get the following error in the browser:
Compiler Error Message: CS1061: 'System.Web.Mvc.HtmlHelper' does not contain a definition for 'RenderFile' and no extension method 'RenderFile' accepting a first argument of type 'System.Web.Mvc.HtmlHelper' could be found (are you missing a using directive or an assembly reference?)
The HtmlRenderer class is in a namespace with my controllers so there is no other external assembly reference needed.
Does anyone have any idea how this could be happening or what i am doing wrong ?

You need to compile the project and then deploy (xcopy or publish from VS) to the server.

Googled and found something.Does the server has .net 3.5?

Try to publish the web on a local IIS7 or IIS6.( Right click project "Publish" ).
You have a good chance you already get a more specific error during "publish".
If not run the page on your local IIS6 or 7 and see if you get an error.

i tried doing a full refresh (deleting everything on the server and republishing and now everything works fine..
so i am happy that everything is working but still have no clue why it wasn't before.

Related

The type provider 'ProviderImplementation.JsonProvider' reported an error despite program working

I am writing a service using .net Core with Visual Studio 2017. I want to use JSON for the configuration, so I defined my type like this:
type ServiceConfig = JsonProvider<"exampleConfig.json", EmbeddedResource="MyService, exampleConfig.json", SampleIsList = true>
In my program, I load it like this:
let conf = ServiceConfig.Load "config.json"
When I run it, it works fine, but in VS 2017 I get a red squiggly line and the error log says:
FS3033 The type provider 'ProviderImplementation.JsonProvider'
reported an error in the context of provided type
'FSharp.Data.JsonProvider,Sample="exampleConfig.json",SampleIsList="True",EmbeddedResource="MyService, exampleConfig.json"', member 'Load'. The error: Method
'FSharp.Data.Runtime.BaseTypes.IJsonDocument
Create(System.IO.TextReader, System.String)' not found in type
''. This method may be missing in the types available in the
target assemblies.
How do I get rid of this?
I'm not sure that this is the problem, but it might help to give an absolute path of the sample file. Resolving a relative path is a constant source of issues in type providers. You can do something like:
[<Literal>]
let sample = __SOURCE_DIRECTORY__ + "/exampleConfig.json"
type ServiceConfig =
JsonProvider< sample, EmbeddedResource="MyService, e
xampleConfig.json", SampleIsList = true >
By chance I found the answer myself. It must have been some Visual Studio index having gone wonky. I had another problem with another project in my solution so I just did an "emergency commit" to git, cleaned my local working copy using git clean -fdx and then reloaded the solution, rebuilt everything and the errors went away.

CloudTable.Execute not working in API

I just moved a function from an MVC App to an MVC API App, and for some reason it all works except CloudTable.Execute.
Code:
try
{
CloudStorageAccount storageAccount = new CloudStorageAccount(new Microsoft.WindowsAzure.Storage.Auth.StorageCredentials(
"accountName",
"key"), true);
CloudTableClient cloudTableClient = storageAccount.CreateCloudTableClient();
CloudTable table = cloudTableClient.GetTableReference("SkypeUsers");
table.CreateIfNotExistsAsync();
TableOperation retrieveOperation = TableOperation.Retrieve<WorkUser>("Skype", skypeid);
TableResult retrievedResult = table.Execute(retrieveOperation); //Does not work
retrievedSkypeId = ((WorkUser)retrievedResult.Result).RowKey;
}
catch (Exception ex)
{
}
Error:
Error CS1061 'CloudTable' does not contain a definition for 'Execute' and no
extension method 'Execute' accepting a first argument of type 'CloudTable' could
be found (are you missing a using directive or an assembly reference?)
The reference to Microsoft.WindowsAzure.Storage is the same version I use in my App. Ive tried cleaning and re-building. Not sure what the issue is.
EDIT:
Print of my only Execute-options:
I am targeting .NET Core & using assembly Microsoft.WindowsAzure.Storage, Version=9.2.0.0.
The ExecuteQuery does not exist within CloudTable for this version.
This might be your case as well.
Use:
table.ExecuteQuerySegmentedAsync(query, null).Result;
The ExecuteQuery sync is still available for .NET Framework version however for NET Standard use ExecuteQuerySegmentedAsync instead.
Error CS1061 'CloudTable' does not contain a definition for 'Execute' and no extension method 'Execute' accepting a first argument of type 'CloudTable' could be found (are you missing a using directive or an assembly reference?)
CloudTable.Execute Method (TableOperation, TableRequestOptions, OperationContext) accepts a TableOperation object as the first argument, and according to the code you provide, we could find you indeed pass a TableOperation object to Execute method, it should not return the error. Please try to install the latest version Microsoft Azure Storage Client Library for .NET to your project (the code works fine with WindowsAzure.Storage v8.0.0 on my side) and test if same issue will appear. You could also tell us the version of WindowsAzure.Storage you are using now, and then we will test the code with that version.
Besides, please try to use TableQuery to generate a query and call CloudTable.ExecuteQuery method to retrieve the entity.
TableQuery<WorkUser> query = new TableQuery<WorkUser>().Where(
TableQuery.CombineFilters(
TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, "Skype"),
TableOperators.And,
TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.Equal, skypeid)));
retrievedSkypeId = table.ExecuteQuery(query).FirstOrDefault().RowKey;

StackExchange.Redis.IDatabase exists in two dlls

I installed Redis StackExchange nuget and things worked fine. But then I installed RedisSessionStateProvider nuget, which installed StackExchange.Redis.StrongName along with it.
Now I am getting the following error,
Error 107 The type 'StackExchange.Redis.IDatabase' exists in both
'e:\Source\packages\StackExchange.Redis.1.0.481\lib\net45\StackExchange.Redis.dll'
and
'e:\Source\packages\StackExchange.Redis.StrongName.1.0.481\lib\net45\StackExchange.Redis.StrongName.dll' E:\Source\MyApp\Helpers\RedisHelper\StackExchangeRedisExtensions.cs 13 37 MyApp
Why is this?
There's a lot of confusion between the strong-named dll and the non-strong-named dll namespaces.
You can easily solve this by using extern alias.
Right click on project references and pick the dll you want to refer, go to properties window. Then, change the Aliases field value to anything you want. E.g: "Redis".
Then go to your consumer source-file and add:
extern alias Redis;
using System;
// ... other references
using Redis::StackExchange.Redis;
namespace Foo
{
public class Program
{
public static void Main(string[] args)
{
using (ConnectionMultiplexer connection = ConnectionMultiplexer.Connect("myConn"))
{
// use StackExchange API here.
}
}
}
}
There's also an issue on StackExchange's repository explaining more about StrongName vs Non-StrongName.
Some methods/properties/interfaces are duplicated in above 2 dlls.
Remove StackExchange.Redis reference to resolve errors.
I faced this issue in an ASP.NET Core app, and this answer solved my issue quickly.

Compiling jabber-net in Xamarin Studio

I am trying to compile jabber-net in Xamarin Studio so I can use it in a Xamarin.iOS app.
From other searches I have done I am told I need to recompile the source.
From command line I can build the dll, but I have no idea what version of .NET/Mono this is targeting.
This makes a jabber-net.dll and a jabber-net.dll.mdb.
If I add jabber-net.dll to my project, add the reqiured
using jabber.client;
...
...
...
JabberClient client = new JabberClient ();
and try to compile I am told.
/Users/brad/Projects/XMPPChat/XMPPChat/AppDelegate.cs(37,47): error CS0584: Internal compiler error: Could not import type jabber.client.JabberClient' fromjabber-net, Version=2.1.0.702, Culture=neutral, PublicKeyToken=924c5b18328d6f09'
/Users/brad/Projects/XMPPChat/XMPPChat/AppDelegate.cs(37,38): error CS0584: Internal compiler error: Could not import type jabber.client.JabberClient' fromjabber-net, Version=2.1.0.702, Culture=neutral, PublicKeyToken=924c5b18328d6f09'
/Users/brad/Projects/XMPPChat/XMPPChat/AppDelegate.cs(37,38): error CS0201: Only assignment, call, increment, decrement, and new object expressions can be used as a statement
I got no idea what is going on here...
When I try to open any of the .sln's (or include any of the existing projects, even the mono specific project) that came with jabber-net into my solution it will either hang trying to convert the project, or will tell me
The file '/Users/brad/Projects/XMPPChat/JabberNet-2.1.0.710/mono-jabber-net.csproj' could not be loaded.
and will spit out this error.
Any idea where to go from here? :|
Start a new solution from scratch, and add all of the .cs files except those in the test and examples directories. Also make sure you don't have an old version of the .dll around somewhere.

Getting Migrate.exe to work

I have been struggling on executing EF Migrate.exe to work.
My Solution has couple of projects. The migrations and the entities live in the project Data. The controllers and views live in Web.
I tried using the migrate.exe - however I am struggling getting the first argument (assembly) to be accepted. Documentations says:
Assembly: Specifies the name of the assembly that contains the
migrations configuration type.
I have tried:
migrate.exe "MySolution\DataProject\bin\Debug\Data.dll"
ERROR: Could not load file or assembly 'D:\\MySolution\\Data\\bin\\Debug\\Data' or one of its dep
endencies. The given assembly name or codebase was invalid. (Exception from HRES
ULT: 0x80131047)
Any idea what is going wrong?
After reading this, this, and this
I have (I think) what you need :
If you use migrate.exe against a .NET 4 assembly you NEED to rename the Redirect.config available in packages\EntityFramework.5.0.0\tools to migrate.exe.config and copy this to the SAME directory as migrate.exe. For running migrate.exe against a .NET 4.5 assembly you DO NOT NEED this copy, the migrate.exe.config must not exist.
The correct version of entity framework DLL must be in the SAME directory as migrate.exe. Correct version is packages\EntityFramework.5.0.0\lib\net40\ for running migrate.exe against a .NET 4 assembly. Correct version is packages\EntityFramework.5.0.0\lib\net45\ for running migrate.exe against a .NET 4.5 assembly
If you specify /StartUpDirectory= do not specify the path for /assembly example : C:\Tools\migrate.exe some.dll /StartUpDirectory=C:\Project\bin\.
If you don't specify a startup directory, then you need to specify the full path in the /assembly example : C:\Tools\migrate.exe C:\Project\bin\some.dll - In this scenario migrate.exe will not be able to load the some.dll's dependencies, unless you put all some.dll's dependencies and put it in the SAME directory as migrate.exe.
If you put the migrate.exe in the same path as your some.dll, then migrate.exe will be able to use the same EntityFramework.dll which your app uses, and can load all dependencies, and can load the some.dll without any path like C:\Tools\migrate.exe some.dll
If you put the migrate.exe in a separate tools folder like Im doing it needs the correct version of the EntityFramework.dll in the SAME directory as migrate.exe, it will need the /StartUpDirectory=<the path where you target dll is present> clause, and you should specify the name of the assembly without the path like : C:\Tools\migrate.exe some.dll /StartUpDirectory=C:\Project\bin\
Heres the powershell commmand I use :
$SolutionPath = (Resolve-Path '..').Path
$ToolsPath = "$SolutionPath\Build\Lib\"
task db {
$migrator = $ToolsPath + 'Migrations\migrate.exe'
$migrateCommand = "$migrator zasz_me.dll /StartUpDirectory=$SolutionPath\zasz.me\bin\ /connectionStringName:FullContext /startUpConfigurationFile:$SolutionPath\zasz.me\Web.config /verbose"
Write-Host $migrateCommand
Invoke-Expression $migrateCommand
}
I answered a similar question here on how to override connectionstring through parameters to migrate.exe. I have yet to get it working without specifying a web/app.config file.
https://stackoverflow.com/a/14138797/134761

Resources