I have a problem with Spark.
I have compiled assembly with views, located in bin subfolder of website, that i created like below
engine.BatchCompilation(targetFolder, Global.AllKnownDescriptors());
On start of my app, a try to load compiled views:
svf.Engine.LoadBatchCompilation(Assembly.LoadFrom(Path.Combine(basePath, "SharedViews.dll")));
When debugging, i can see that this was successfull.
But ViewEngine doesn't find that views. It even doesn'n look for them in CompiledViewHolder where they are located.
May that problem be caused ny wrong IViewFolder?
Or i should do something more to use compiled views?
Thanks
Not sure if this is helpful, but in the documentation there's the following paragraph:
There is no dynamic recompilation of classes that are loaded in this way and changes to the spark files will have no effect. However the files must be available on disk at runtime. Sorry about that - but the different frameworks still needs to test for the view files' existence to know what view descriptor it should instantiate.
Do you have the view files in your directory structure?
I found out the solution - I compiled views not on app startup, but using different tool. So changes made to engine (registration of entries etc.) during compilation were vain.
So now I compile view on app startup and everything ok.
Related
I have a complex site running Sitecore composed of both ASP.NET Webforms (.aspx, .ascx) views and Razor (.cshtml) views, and would like to get them all compiled after deployment so there's no runtime compilation performance hit the first request for anything.
I've tried running aspnet_compiler against the site, but
It's telling me it can't find an assembly which is 100% in the bin folder
Failure to compile one view shouldn't stop it from compiling others
I'm now looking into how views are compiled at runtime on demand, and have found System.Web.Compilation.BuildManager.GetCompiledType(VirtualPath) so would I be able to scan my website folder for all views and call that method for each one?
I'm not looking to precompile views, but just compile them after deployment as if there had been requests for pages requiring them. How can this be done?
I ended up using System.Web.Compilation.BuildManager.GetCompiledType(VirtualPath), and it works really well. As that method takes virtual paths, I found the full paths of views I want compiled, then subtracted Server.MapPath to get the virtual path.
My team has multiple web application projects that have common components. In order to keep from having multiple instances, we have setup a common source that contains common classes and web project. In the web project, we would have MasterPage, pages, and user's controls that are shared as linked files from the main web application. each of the shared projects are included as part of the solution. The solution builds successfully, but when I open the page of the web app, I'm getting server stating that "The type 'Common.Controls.Master' is ambiguous: it could come from assembly 'C:....\bin\Common.Controls.DLL' or from assembly 'C:....\bin\AppWeb.DLL'. Please specify the assembly explicitly in the type name."
The actual Common.master resides in the Common.Controls project at the root. The link file to the master page is in the AppWeb project.
I've looked for solution and found this How to share Master Pages between my projects which is pretty much what I'm doing.
Another option I found was What is the best way to share MasterPages across projects. I haven't tried the methods in this one.
I was certain that using the linked file would work.
Thanks in advance in helping me resolve this error.
I faced a very similar issue recently with a different shared class.
Is it possible that the initial location of the MasterPage was under AppWeb project and then moved under Common.Controls project? In this case a build would not clean the previous dlls and would cause the error you are looking at. If this is the case, a simple manual deletion of all files under the bin folder of your projects and rebuild should solve the issue.
I hope this helps
I've just inherited a web application whose source has long been lost (originally written in 2010 and shelved). The application has a few .dll assemblies that related to the application itself e.g. "applicationCORE.dll", "applicationBI.dll", "applicationDATA.dll" and "application.dll"
I've seen this question and the suggested tool (Just Decompile) is brilliant and created a .sln and .csproj file for the first assembly that I decompiled. My question is how do I merge the various projects that would be created through decompiling with the compiled web application files (.aspx) also, how do I resolve the references in the .aspx files i.e. referencing the codebehind file that no longer exists e.g. "default.aspx" references "default.aspx.cs" while the decompiler creates a "default.cs" file. Is it safer to rename the .cs file or should I update the reference?
Finally, will each dll appear as a separate project within the solution?
I realise this may be perceived as a duplicate question however there doesn't appear to be a resource online that walks a developer through the process.
Following David's advice, I managed to get the application running from decompiled assemblies. Here's the process I followed to get it working
I had already decompiled the various assemblies into projects using a Reflector (on a trial).
I created a blank Web forms application in Visual Studio
I added the .aspx pages from the website to the project through visual studio
Then added the .cs files from the decompiled 'application.dll' project (since this is the website project within the solution. Some files had to be renamed to match the codebehind references in the `.aspx. files
Each additional project e.g. applicationCore.dll was then added to the solution
Each project's references needed to be updated and references to the newly added projects must be added to the startup project
Since the website was built so long ago, there were 1,000's of syntax errors. The easiest way to resolve them was to use Notepad++ and the Find and Replace. To be safe, I did this file-by-file by following the errors from Visual Studio rather than a batch find and replace
When trying to build I noticed errors where required assemblies were missing so I changed the build output directory of the sub-projects to the bin folder of the web project
I added the connection strings and settings from the original website's web.config. I did this line by line to make sure I didn't break anything and so that I could trace the result of each addition
Finally I had a successful build!
Additional Steps
There were also syntax errors which I assumed were due to the decompiling process. Some external references needed to be added and there were slight changes due to the age of the project e.g. asp:AjaxScriptControl changed to asp:ScriptControl (after adding the package using Nuget). I also had to install Crystal Reports for this application and will have to purchase a Telerik licence as there are UI components being used (although I'll see if I can use an open / native alternative as I work through the app).
I've logged in using credentials (I did have to set the correct start page) and tried a few basic CRUD operations. There are silly issues that have to be resolved e.g. the authentication doesn't work properly and there's no redirect if you access a protected page but these things are relatively minor compared to the issues I faced initially.
What I must say is each error was resolved using questions and answers from this site! This was all completed in just under 6 hours.
I have converted one huge Website Project into a Web Application Project as we want to have Compiled code in form of DLL for security purposes and followed below MSDN articles:
http://blogs.msdn.com/b/webdev/archive/2009/10/29/converting-a-web-site-project-to-a-web-application-project.aspx
http://msdn.microsoft.com/en-us/library/aa983476%28v=vs.100%29.aspx
The website is having 1000s of web pages/files. I have resolved all the issues of duplicate references, class name colisions and some compilation errors faced at on Build Solution stage. Due to the earlier website pattern, class names are in the following pattern:
for e.g. if UserMaster is in admin/Operations/Masters folder so the class name will be like: admin_Operations_Masters_UserMaster.
Now, Web Application is Building Successfully and when I try to run the application, it shows "Could Not Load Type 'ClassName'" so I found out that the issue of because Namespaces are absent due to earlier Website Pattern.
Found out in the MSDN:
By default, pages and classes that are built by using the Visual Studio Web site project model do not automatically include a code namespace. However, pages, controls, and classes that are built by using the Visual Studio Web application project model automatically include a code namespace. When converting the Web site project to a Web application project, you will have to add the namespaces to the code.
I have DEFAULT NAMESPACE in the project properties.
So I tried to add the namespaces to whole of the project via ReSharper -> Refactor -> Adjust Namespaces but its for .cs files only and not for .aspx.cs etc AND so its not working.
I thought I need to make a utility to add the namespaces automatically in pages as per their folder path structure but its a time consuming process.
So need a workaround to add the namespaces automatically in pages as per their folder path structure.
Secondly,
What I did for testing is, I have wrapped the default namespace in login page of the project where I faced 'could not load type issue', added in Inherits attribute also. Then did a Clean Solution then Rebuild Solution. But still getting the same issue.
I don't why DLL is not getting updated with the login page's class.
The strange thing is when I change the Codebehind to CodeFile (attribute of Page Directive) then the page is working very fine. Its due to source file is present at the time of running the project BUT i want to use Codebehind attribute as it will tell the compiler to look for the class in DLL not in Source file.
Finally, Summary is :
I have two major issues:
Could not load type 'className'
How to add the namespaces automatically in pages as per their folder path structure.
I have already searched here and came around different topics but nothing works for me. one have suggested to use "Surround With" feature of VS but I need to go one by one on each file which is NOT possible right now.
So Tried:
Set path of DLL to "bin" instead of "bin\debug"
Checked the Build Configuration and its of x86. also the DLL is present in bin
Checked all project properties and all are fine. Cleaned and rebuild solution hundreds of times. Cleaned Temporary ASP.NET files also.
Set Build Action to "Compile" for .cs class files
Cannot set Build action to Compile for aspx pages as they are static html and they should be set to "Content" which is default Build Action.
Resharper solution for adding namespaces but not working
Please help....
Any help will be greatly appreciated. Thanks.
Solved the Issue:
Earlier, I have tried to Set Build Action to "Compile" for .cs class files Only and for all the files sitewide to Compile from .csproj file but it was not working due to aspx page itself set to Compile which was not required.
Now, I have changed the Buid Action to Compile which was Content for .aspx.cs and .aspx.designer.cs files.
and it solved the issue.
Like for e.g.:
Solution 'TestWebApp1'
Project 'TestWebApp1' (ASP.NET Web Application)
Properties
References
App_Data
Scripts
Default.aspx (Build Action: Content)
Default.aspx.cs (Build Action: Compile)
SiteLayout.Master (Build Action: Content)
SiteLayout.Master.cs (Build Action: Compile)
Web.config
Source: None of my "code behind" code is being called
I did some research about this but had no luck finding any solution.
This is a two-aspect problem:
Sharing views between multiple projects. This is easily done by i.e. embedding them in a common project and providing by virtual path provider.
The problem is that they can't be stepped into by a VS debugger, since it has no way of correlating physical cshtml files with these JITted.
Debugging common views. This is the part where I stuck in. I have no idea how to do this.
What I have done:
I created a project with common views (with a "content" type, not emvedded) and a symbolic link in every project, which leads to the appropriate folder. I also added this path to a RazorViewEngine in application_start.
This works fine, I even get a line number when there's an exception thrown in a view, except that VS debugger still can't step into this view :/
In order to debug views one have to have them in a project, but it can't really be done - we obviously use TFS, so they would be multiplied in tfs.
To make the story short: is there any way to step into a shared view while debugging in VS2010?
This is quite a major problem for us, any ideas are appreciated