andrewdavey / postal

Email sending for asp.net mvc using the view engine system to render emails.
http://aboutcode.net/postal
MIT License
536 stars 169 forks source link

System.NotImplementedException: The method or operation is not implemented #46

Closed Desterly closed 10 years ago

Desterly commented 11 years ago

MVC4 on .NET 4.0 framework. - vs2012

getting the "System.NotImplementedException: The method or operation is not implemented." message that has been reported before.

During debugging it's in the RenderView method as described in issue 40 (https://github.com/andrewdavey/postal/issues/40)

I've verified that I am using v0.8.0

I attempted to use the latest source from github and I'm receiving the same error.

Switching the sample site over to dotnet 4 seems to work OK however so it must be something isolated to the project in question, I'm assuming the incorrect assemble is being referenced somewhere.

The only thing that I did notice was that the demo is targeting MVC3 where my site is MVC4

EDIT: Created fresh MVC4 application, set framework to DOTNET 4, added Postal from nuget. Copied controllers/views from demo site and get the same error.

Def seems to be an issue w/ MVC4

Desterly commented 11 years ago

The more I look into this it appears to be an issue with the HttpContextBase (EmailHttpContext).

The exact trace is below: at System.Web.HttpContextBase.get_PageInstrumentation() at CallSite.Target(Closure , CallSite , Object ) at System.Dynamic.UpdateDelegates.UpdateAndExecute1[T0,TRet](CallSite site, T0 arg0) at CallSite.Target(Closure , CallSite , Object ) at System.Web.WebPages.Instrumentation.HttpContextAdapter.get_PageInstrumentation() at System.Web.WebPages.Instrumentation.InstrumentationService.GetInstrumentationService(HttpContextBase context) at System.Web.WebPages.Instrumentation.InstrumentationService.RunOnListeners(HttpContextBase context, Action`1 act) at System.Web.WebPages.Instrumentation.InstrumentationService.BeginContext(HttpContextBase context, String virtualPath, TextWriter writer, Int32 startPosition, Int32 length, Boolean isLiteral) at System.Web.WebPages.WebPageExecutingBase.BeginContext(String virtualPath, Int32 startPosition, Int32 length, Boolean isLiteral) at ASP._Page_Views_Emails_Example_cshtml.Execute() in c:\Users\jwilliams.MMTC\AppData\Local\Temp\Temporary ASP.NET Files\root\cfde9aaf\bded2c65\App_Web_ryncfnqm.0.cs:line 0 at System.Web.WebPages.WebPageBase.ExecutePageHierarchy() at System.Web.Mvc.WebViewPage.ExecutePageHierarchy() at System.Web.WebPages.StartPage.RunPage() at System.Web.WebPages.StartPage.ExecutePageHierarchy() at System.Web.WebPages.StartPage.RunPage() at System.Web.WebPages.StartPage.ExecutePageHierarchy() at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) at System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance)

This is resolved in dotnet 4.5 because of system.web.instrumentation. in 4.0 this only an internal class and System.Web.HttpContextBase does not implement the get_PageInstrumentation method but System.Web.WebPages.Instrumentation does.

brgrz commented 11 years ago

I only get this error if I set custom view engine otherwise it is working fine.

NikolajDL commented 11 years ago

I have this same issue. Any way to resolve this in MVC4 using .NET 4.0?

benwmills commented 11 years ago

I'm getting the same problem, but I'm hoping I have some info that might help. After switching to MVC4 and VS2012, I get this error on my local development machine, but everything works fine on the server (a Windows Azure VM with Windows Server 2008 R2 running IIS7). Is there any chance that this error is related to running within the Visual Studio Development Server (Cassini I think)?

benwmills commented 11 years ago

I tried running in a local IIS Server and it still doesn't work, so it's not Cassini. Really strange that is is working on the server, but not locally. This one is driving me nuts. Has anyone tried switching to .NET 4.5? I don't know why that would work, but I'll try anything.

Desterly commented 11 years ago

The problem is if you target the 4.0 framework and have the 4.5 framework installed on your machine. If you publish to a server that does not have 4.5 it will work fine.

The methods causing the problem are not available in the 4.0 framework but because 4.5 is a drop in replacement for 4.0, they exist internally.

From what I can tell passing in a real context instead of the dummy one created in postal would fix the problem as well.

I ended up switching to a different mailer

benwmills commented 11 years ago

Wow, lucky I didn't go for it and install the .NET Framework 4.5 on my server. Then I would have been in trouble.

I hope I don't have to switch to another mailer. Postal works really well for me.

brgrz commented 11 years ago

It is working for me on a server with .NET Framework 4.5 installed and locally (also with 4.5 installed). In VS under Project Properties -> Application I selected Target Framework is .NET Framework 4.5. I don't know what would happened if I had selected to target 4.0 because I upgraded all my projects to 4.5.

Postal then works fine. I also deployed a site that uses Postal into Azure Website and it works there too. (And I guess they too have 4.5 installed).

Desterly commented 11 years ago

Yes you are correct.. It only fails if you target 4.0 with the 4.5 framework installed. Once you have 4.5 installed you MUST target 4.5.

benwmills commented 11 years ago

Well that's an easy thing to fix. I will have to install 4.5 on my VM, but that's easy enough.

When I go to change the framework I'm targeting, it gives me a warning that I might need to manually edit project files. Did you have any problems when switching? Do most nuget packages tend to just work?

brgrz commented 11 years ago

I had no problems switching, everything worked fine. NuGet, at least for me, has its issues with packages constantly but those are not framework related;)

benwmills commented 11 years ago

I finally got around to changing the target Framework to 4.5 and it didn't fix the problem. I get the same System.NotImplementedException. I'm not sure what to try next.

Edddy commented 11 years ago

Got the same issue

dhlavaty commented 11 years ago

Same issue here. MVC4, RazorEngine 3.2, target changed to .NET Framework 4.5 and still the same System.NotImplementedException

Edit: It seems like it is trying to open/parse "~\Views_ViewStart.cshtml" and not "~\Views\Emails_ViewStart.cshtml". I was using MVC3 and Postal till yesterday, and had no problem with it.

dhlavaty commented 11 years ago

OK, I found a solution that worked for me.

After changing to .NET Framework 4.5, you must reinstall (uninstall and install back) Postal from NuGet. Because project file was still pointing to Postal's "4.0 assembly" and not it's "4.5 version". ( Or you can of course edit your .csproj file manually if you wish )

benwmills commented 11 years ago

That's really interesting. I will try to remove and add back the nuget package. I thought I read some hazy info that the latest nuget package manager does a better job of handling the retargeting. Is it best practice to remove all the nuget packages and add them back after retargeting? The seems like it could potentially mess up some custom package configuration in the web.config.

Edddy commented 11 years ago

Reinstalling worked for me also. Thanks @dhlavaty

SlobodanJ commented 11 years ago

I got it working in strange way :-) - if you are using VS2010 and target .NET4.0 (and you already have .NET 4.5 installed) do the following:

  1. copy postal.dll from packages\postal.0.8.2\lib\net40 to your BIN folder
  2. add reference to postal.dll from BIN folder
  3. build your solution
  4. copy postal.dll from packages\postal.0.8.2\lib\net45 to your BIN folder and overwrite existing postal.dll
  5. rebuild solution
rpanek commented 11 years ago

I get the same issue and was already Targeting 4.5 when I installed the Postal NuGet package for the first time

TechGeorgii commented 10 years ago

Another reason of getting this error could be in rendering your views in a master view by default. It was my case. Adding @{ Layout = null; }

at the top of my email *.cshtml solved this problem.

SlobodanJ commented 10 years ago

We already have Layout=null, in our case that is not the source of the problem.

--- Original Message ---

From: "root85" notifications@github.com Sent: 29 October, 2013 5:25 AM To: "andrewdavey/postal" postal@noreply.github.com Cc: "SlobodanJ" majmun00@hotmail.com Subject: Re: [postal] System.NotImplementedException: The method or operation is not implemented (#46)

Another reason of getting this error could be in rendering your views in a master view by default. It was my case. Adding @{ Layout = null; }

at the top of my email *.cshtml solved this problem.


Reply to this email directly or view it on GitHub: https://github.com/andrewdavey/postal/issues/46#issuecomment-27288090

andrewdavey commented 10 years ago

Postal v0.9.0 should fix the problem. It no longer tries to implement HttpContextBase et al. It just uses a normal HttpContextWrapper instead.