Generation of designer file failed: Could not load file or assembly - asp.net

I have an ASP.NET web application project which references another project called ModusCore (or Modus.Core). We've had a variety of controls that use ModusCore up until now with no problem, but there's one I created lately that's been causing trouble. Here's the code:
public class PortalLinkNew : WebControl
{
public string Text { get; set; }
public bool AllowPush { get; set; }
public PortalLinkNew()
{
AllowPush = true;
}
public IChannelRequest ChannelRequest { get; set; }
protected override HtmlTextWriterTag TagKey
{
get { return HtmlTextWriterTag.A; }
}
protected override void AddAttributesToRender(HtmlTextWriter writer)
{
try
{
base.AddAttributesToRender(writer);
if (DesignMode || Page == null || !(Page is IPortalPage))
{
return;
}
string href = "/";
if (ChannelRequest != null)
{
var portalPage = (IPortalPage)Page;
href = portalPage.Module.PortalRouter.GetLinkUrl(portalPage, ChannelRequest, AllowPush);
}
writer.AddAttribute(HtmlTextWriterAttribute.Href, href);
}
catch (Exception)
{
}
}
public override void RenderEndTag(HtmlTextWriter writer)
{
writer.Write(Text);
base.RenderEndTag(writer);
}
}
In the above code, IPortalPage and IChannelRequest are interfaces defined in Modus.Core.
My intent is to use this control in my code as follows:
<tnl:PortalLinkNew ID="CancelButton" runat="server" Text="Cancel" OnInit="CancelButton_Init" />
This actually compiles and runs without a problem, but when I'm editing the page (source view) in Visual Studio 2008, I get the following warning:
Generation of designer file failed: Could not load file or assembly 'Modus.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.
As it says, it doesn't regenerate the designer file, meaning any attempt to refer to the CancelButton control in code-behind results in a compiler error. Following advice I've found online, I've tried deleting the corresponding .ascx.designer.cs file and using "Convert to Web Application" on that page, but it tells me that it cannot rebuild the designer file for the same reason mentioned above.
I've tried everything I can think of: cleaning the solution, restarting Visual Studio, rebooting my computer, deleting the code directory and pulling it fresh from the repository, removing and re-adding the project and dll references, etc. The same problem occurs on multiple computers I use.
How can I get the VS designer to stop failing?

I have a very similar problem (which I could not solve yet). The Application I have the problem with was converted from a "Web Site Project" though and I can't get rid of the feeling that this has something to do with it. And I am on VS 2005.
Now what I can add is that
a) "sometimes" (I could not figure out when exactly yet) the "Convert to Web Application"-trick works for me (but not always)
b) "sometimes" (same as above) it helps to switch to the designer view, change something and save -> *.designer.cs gets regenerated
I usually try several things in no fix order after I added a control to my page until "something" works.
There is a lot of noise about this on the internet but I could not find a "real fix" for it (yet). One thing I read besides the already mentioned is that it could have something to do with (not matching/not existing) namespaces.
When I checked my application there really were no namespace declarartions in the *.cs-files. So I added them (in *.cs and *.aspx) and for some time thought it did the trick. But sadly by now I know that this was not the case...

My solution:
Close and reopen Visual Studio.
Is your problem fixed? If not, go to 1.

Adding a third option for when #scherand's (a) and (b) fail:
c) "Sometimes", this works as well:
Remove the <%# Register... %> entries
Save the .AS?X file. Let the designer complain.
Add the <%# Register... %> again
Save again
[Added Oct-13-2010]:
d) "Sometimes", as well:
Clear the AS?X file off all but the most basic content.
Start adding pieces back, one bit a time.
Save.
Check that you didn't get the error message.
Add back a few more pieces. Rinse. Repeat.
I use a text comparison tool against a back up copy of the AS?X file for this.
I try to avoid adding the controls that cause the error until the very end. I also try to add from the bottom of the page. However, I don't know of a hard rule. It's a gut-feeling exercise.
(Will someone ever figure this one out?)

I've been struggling with this problem all day, and you wouldn't believe what the culprit was. I disabled ReSharper 5.0 and all of a sudden the errors went away. Unbelievable.

Another solution I have found to be effective in Visual Studio 2015 is to close VS and then clear out the following directories:
%UserProfile%\AppData\Local\Temp\Temporary ASP.NET Files\
%UserProfile%\AppData\Local\Microsoft\VisualStudio\14.0\ProjectAssemblies\
Open your solution again and select Build->Clean Solution.
Now go to your ASPX page, and then select Project->Convert To Web Application

Copying the missing assemblies into the Visual Studio\Common7\IDE\Public Assemblies directory gave me more specific error messages than 'could not load file or assembly'. From here I commented out some problematic parts of the page, deleted the .designer.cs file and chose "Convert to Web Application" from the right-click context menu of the .ascx file.

Well, I've had this very problem for two days. As far as no proposed solution completely solved the problem (it looks very... erratic), I reached the Assembly Information button (or something similar... my VS is in Spanish) in the Application Tab of the project properties. I've only changed the Neutral Language... and now it deploys correctly.
I have no idea of the correlation, but I reached here after seeing how some errors, related to the assembly information were displayed on the console after "converting to Web Application".
To ensure that your web application is OK to deploy, you can see the first lines of the aspx files and check if all CodeFiles are CodeBehind instead. If you see "Codefile=...", it will fail on the deployment machine.
Sorry for not being more explicit, but this is a weird issue to me :S

I had a similar issue but with assemblies that we had created. In our case the version number was very specific, so this may not work if all your files say 1.0.0.0.
First of all, delete the designer file for the problematic aspx file. Right-click the aspx file and select "Convert to Web Application", similar to what others suggested. Doing it on the file is faster and you get a popup with the error instead of a warning you have to look for. In our case the error was Generation of the designer file for OurPage.aspx failed: Could not load file or assembly 'OurCustomAssembly, Version=1.0.234.567...
What I then did is use a tool that searches file contents (e.g. Agent Ransack) and pointed it to our source folder (which also has the build/cache files) and searched for files "containing text" with the specific version. For each of the projects that came up, I removed the reference to the assembly that was failing, re-added it, then rebuilt the individual project. Searching again showed that the version was gone.
I ran Convert to Web Application again and now got the same error but with a different file. This time none of the above worked. I was able to determine that only some of the Register tags were problematic. I removed those register tags, created protected variables on the page's code-behind (since they weren't in the designer file) and recompiled the solution. Afterwards I removed the variables I had created, saved, readded all the Register tags, saved. At that point the designer file generated successfully.
There may be a more straightforward way to do all this, but that's what ended up working for me. Time will tell, but hopefully this is a permanent fix.

I'm using ReSharper Platform 6. I was able to resolve this issue by doing the following:
ReSharper (Menu Bar) > Options...
Environment > General > Clear Caches
Restart Visual Studio

Related

How can I fix (or ignore) javascript errors in Visual Studio 2015

I have a solution whose startup project is an ASP.NET website (the kind without a .vbproj file)
When I'm running in debug mode, the first error I get is a popup
Unhandled exception at line 539, column 51 in script block
0x800a138a - JavaScript runtime error: Function expected
The code "file" is called "script block [dyanmic]" so I think this js is being created by VS or it's a third party code, which means I probably can't fix it. This bold portion of the code below was in yellow when I did a "break". (sorry, I don't know how to highlight a portion of a code block in stack overflow)
function LPCTR(a){var b=0;if("undefined"!=typeof g_isdebug&&g_isdebug||"undefined"!=typeof debug&&debug)init_LPctr(),b=LPctr.increment(a);return 0!==b}
I'm getting several errors similar to this.
How can I ignore these errors?. There is an "exception settings" window in the IDE, and I have "JavaScript Runtime Exceptions" completely unchecked. (My site appears to be working otherwise)
How can I find the "owner" of this code? I don't have a LPCTR function.
If you right click the eror window and at the bottom select to clear javascript errors. They are gone and will not appear next time you compile your project.
Put the code in a try-catchblock
try {
// Your code here
} catch(e) {
// Code run on error, with info var e
}

Why won't my Silverlight PivotViewer load?

I have a PivotViewer app I am working on, but, I cannot get it to run.
I have a good .cxml file (I used Pauthor to generate the related deep-zoom files). I have tried running it from inside VS 2010 int debug and even built it and tried running it from my localhost. I've checked it in both Firefox and IE. I've made sure it is in a container with set width and height. I've made sure I have the most current silverlight.js, I've set the appropriate MIMEs on IIS.
My XAML:
<UserControl x:Class="DomPivot.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:pivot="clr-namespace:System.Windows.Pivot;assembly=System.Windows.Pivot"
mc:Ignorable="d"
d:DesignHeight="400" d:DesignWidth="400" Loaded="UserControl_Loaded">
<Grid x:Name="LayoutRoot" Background="White" Width="400" Height="400">
<pivot:PivotViewer x:Name="myPivot" Height="350"></pivot:PivotViewer>
</Grid>
</UserControl>
My error:
Error: Unhandled Error in Silverlight Application Set property 'System.Windows.FrameworkElement.Style' threw an exception. [Line: 11 Position: 52]
at System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)
at DominionPivot.MainPage.InitializeComponent()
at DominionPivot.MainPage..ctor()
at DominionPivot.App.Application_Startup(Object sender, StartupEventArgs e)
at MS.Internal.CoreInvokeHandler.InvokeEventHandler(Int32 typeIndex, Delegate handlerDelegate, Object sender, Object args)
at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, Int32 actualArgsTypeIndex, String eventName)
Source File: DomPivotTestPage.aspx
Line: 0
Line 11 Position 52 of the main.xaml is now the equal sign for the Height property of the pivotviewer. Interesting that BEFORE I added the height property, the project threw this error at the equal sign for the x:Name property.
I don't understand why I'm getting this error and would appreciate some help. I've investigated the other topics here but none of those answers either worked or pertained to my situation.
UPDATE:
I've attempted to make sure it isn't some kind of other error cascading into an inability for the control to load by attempting to load a .CXML file from a public source. Same result. I don't think the control itself is loading, so, I can't even debug the code that loads the collection.
Googling "Unhandled Error in Silverlight Application Set property 'System.Windows.FrameworkElement.Style' threw an exception." is no help. It returns 24 hits. Half of those are unrelated. The other half is another person with what appears to be the same problem posting to half-dozen or more forums and getting no answer either.
OK....so here are a number of issues that a lot of frustrating googling and futzing revealed:
Loaded="UserControl_Loaded"
I'm not entirely sure how this parameter ended up in my UserControl tag, but, it is unnecessary and eliminated the error referenced in my question.
I also moved the LoadCollection method out of its own event and into the UserControl_Loaded event and got things to progress.
Next I found that if you are using Visual Studio to run the project, make sure you specify the port number both in your code and in your web project settings. These obviously need to be changed when you post to a live server.
Lastly, I was led to believe that you HAD to use either the freely available Pauthor tools or the Excel plug-in to transform your collection into a Deep Zoom. Which also requires futzing with IIS to allow .dzi and .dzc.
Not so. There is a freely available Microsoft Deep Zoom Composer tool. In that tool you can compose your deep zoom and export the collection. You'll end up with several xml files and image folders. I found that all you have to do is then reference the output_dzc.xml file in your collection.cxml as your ImgBase and make sure your IDs match between the two files. That's all.
I hope this saves someone the frustration I've experienced the last few weeks trying to use this awesome but pathetically under-documented control.
I would also recommend this blog entry:
http://indiandotnet.wordpress.com/2011/02/12/pivot-viewer-example-cricket-world-cup-2011/
It contains a link to a very simple pivotviewer VS 2010 solution file you can use to examine and familiarize yourself with file and directory structure as well as the necessary XML file structure and solution settings.

NullReferenceException on web user control

First time posting. :)
I'm a pretty new developer so I'm not well versed in common ASP.NET problems.
As a test, my boss asked me to convert a (not very critical) ASP.NET site from 1.1 to 4.0. Well, it's not extremely difficult and things are going well so far. However, I've hit a small snag. I keep getting a NullReferenceException when I run this code:
Public Property PageTitle() As String
'===========================================================================
'Exposes the PageTitle property of the child control.
'===========================================================================
Get
Return lblPageTitle.Text
End Get
Set(ByVal Value As String)
'TODO: find out why this throws a NullReference exception
lblPageTitle.Text = Value
End Set
End Property
The Value part does have a string attached to it (literally :) but the lblPageTitle just won't set right.
More background if this helps: Before, this web user control had these in the codebehind, but they started throwing errors because they were already declared. Anyways, here they are:
Public Shared lblPageTitle As New Label
Public Shared lblUser As New Label
Public Shared lblLastLogin As New Label
Public Shared lblToday As New Label
Public Shared lblSiteTitle As New Label
Obviously, the New keyword might have helped in this situation somehow, but none of those other labels have caused any trouble.
I've tried doing this but it didn't work:
Dim PageTitle As New Label
PageTitle = TryCast(ucPageHeader.FindControl("lblTitle"), Label)
If Not IsNothing(PageTitle) Then
PageTitle.Text = sb.ToString()
End If
Any ideas?
Those declarations you deleted are required SOMEWHERE. I've got a feeling you're using a web application project and your .designer.vb file has somehow got out of date. As a quick fix, toggle "Show all files" in your solution explorer (it's a little toolbar button just up on the top leftish of your sidebar) and expand the arrow beside the .ascx file you're working on. You should see a .ascx.vb file and a .ascx.designer.vb file. Without going into too much more detail, try deleting the designer.vb file, then right clicking on the .ascx and selecting "Convert to web application". Visual Studio will recreate your .designer.vb, hopefully with all control references intact.
Recommended reading: Code-Behind with VS 2005 Web Application Projects. It's for ASP.NET 2.0 but the same basic principles apply.

MVVM Light + Blend designer view error: Cannot find resource named 'Locator'.

The application runs fine but i could not see my design in the designer view.
It says Cannot find resource named 'Locator'. Obviously, i did not change anything in the code, i just did the data binding using the data binding dialog...
anyone facing the same problem?
There are two known occurrences where this can happen.
If you change to Blend before you built the application, the DLLs are not available yet and this error can be seen. Building the application solves the issue.
There is a bug in Expression Blend where, if you are placing a user control in another user control (or Window in WPF), and the inner user control uses a global resource, the global resource cannot be found. In that case you will get the error too.
Unfortunately I do not have a workaround for the second point, as it is a Blend bug. I hope we will see a resolution for that soon, but it seems to be still there in Blend 4.
What you can do is
Ignore the error when working on the outer user control. When you work on the inner user control, you should see the design time data fine (not very satisfying I know).
Use the d:DataContext to set the design time data context in Blend temporarily.
Hopefully this helps,
Laurent
I've come up with a reasonably acceptable workaround to this problem since it doesn't appear to have been fixed in Blend 4:
In the constructor for your XAML UserControl just add the resources it needs, provided you're in design mode within Blend. This may be just the Locator, or also Styles and Converters as appropriate.
public partial class OrdersControl : UserControl
{
public OrdersControl()
{
// MUST do this BEFORE InitializeComponent()
if (DesignerProperties.GetIsInDesignMode(this))
{
if (AppDomain.CurrentDomain.BaseDirectory.Contains("Blend 4"))
{
// load styles resources
ResourceDictionary rd = new ResourceDictionary();
rd.Source = new Uri(System.IO.Path.Combine(Environment.CurrentDirectory, "Resources/Styles.xaml"), UriKind.Absolute);
Resources.MergedDictionaries.Add(rd);
// load any other resources this control needs such as Converters
Resources.Add("booleanNOTConverter", new BooleanNOTConverter());
}
}
// initialize component
this.InitializeComponent();
}
There may be some edge cases, but its working OK for me in the simple cases where before I'd get a big red error symbol. I'd LOVE to see suggestions on how to better solve this problem, but this at least allows me to animate user controls that otherwise are appearing as errors.
You could also extract out the creation of resources to App.xaml.cs:
internal static void CreateStaticResourcesForDesigner(Control element)
{
if (AppDomain.CurrentDomain.BaseDirectory.Contains("Blend 4"))
{
// load styles resources
ResourceDictionary rd = new ResourceDictionary();
rd.Source = new Uri(System.IO.Path.Combine(Environment.CurrentDirectory, "Resources/Styles.xaml"), UriKind.Absolute);
element.Resources.MergedDictionaries.Add(rd);
// load any other resources this control needs
element.Resources.Add("booleanNOTConverter", new BooleanNOTConverter());
}
}
and then in the control do this BEFORE InitializeComponent():
// create local resources
if (DesignerProperties.GetIsInDesignMode(this))
{
App.CreateStaticResourcesForDesigner(this);
}
Note: At some point in time this stopped working for me and I ended up hardcoding the path to the Styles.xaml because I got frustrated trying to figure out which directory I was in.
rd.Source = new Uri(#"R:\TFS-PROJECTS\ProjectWPF\Resources\Styles.xaml", UriKind.Absolute);
I'm sure I could find the right path with 5 minutes work, but try this if you're at your wits end like I was!
In MyUserControl.xaml, instead of:
DataContext="{Binding Main, Source={StaticResource Locator}
use:
d:DataContext="{Binding Main, Source={StaticResource Locator}
where "d" has been previously defined as:
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
The reason and workaround explained here
http://blogs.msdn.com/b/unnir/archive/2009/03/31/blend-wpf-and-resource-references.aspx
Look at (b) part of the post.
I had a similar problem with a user control resource.
I added this in my usercontrol xaml code:
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/GinaControls;component/Resources/GinaControlsColors.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>
Where GinaControls is the namespace where the control class is declared and /Resources/GinaControlsColors.xaml is the project folder and xaml resource file name.
Hope this helps.
Just add this in your App.xaml.cs at the very beginning
here's my piece of code
[STATThread()]
static void main(){
App.Current.Resources.Add("Locator", new yournamespace.ViewModel.ViewModelLocator());
}
public App(){
main();
}
Make sure the Blend has opened the entire solution and NOT just the single project containing the views. I was right-clicking in Visual Studio and selecting Open In Expression Blend. To my surprize, Blend could not find the solution file, so it only opened the single project.
When I realized this, I launched Blend directly, pointed it to the solution file, and then Blend was able to find the ViewModelLocator in my view.

How to Rename my asp.net web page

I have a page name with XYZ.aspx
Now I want to change ABC.aspx how should I do it?
When i directly change it from solution explorer it gives me an error.
Can anyone help me on this?
Thank You
Smartdev
ASP.NET files are usually composed of 1-3 files total depending on the type of project and the file itself. That being said, there is always the markup *.aspx file, then optionally there will be a code-behind *.aspx.cs file and an additional and also optional designer file *.aspx.designer.cs. If you are renaming the file you will need to update code in various places based on the structure of the file itself.
In the event of more than 1 file making up your ASP.NET page you will want to update the .aspx file's header like so:
<%#Page CodeBehind="XYZ.aspx.cs" Inherits="XYZ" %>
to
<%#Page CodeBehind="ABC.aspx.cs" Inherits="ABC" %>
Then in the code behind file
public partial class XYZ : Page { }
to
public partial class ABC : Page { }
Finally, if there is also a *.designer.cs file you will want to update it as well:
public partial class XYZ : Page { }
to
public partial class ABC : Page { }
That should cover all of the files!
To change the name of an aspx file (I'm using vs2012) and associated files single click on filename in solution explorer and single click again to select the name of the file, change the name and enter... vs will rename the code behind file and designer file automatically and change the tags linking them. As nathan above said it does not rename the c# in the code behind to reflect the filename (which would be good practice)... nor importantly does it do a solution wide search for links and more oblique code references to the file. So it's best to do a manual find in files over the entire solution to check and all naming conventions are good.
That should do it

Resources