I'm having weird issues with code generated with netTiers. I've tried to use the framework provided in a simple form to save information on one of the entities created.
Here is the method I'm calling from an ASPX page:
public void UpdateSupplier(Object sender, EventArgs e)
{
// Update Supplier name and code from update form
supplier.Name = txtName.Text;
supplier.Code = txtCode.Text;
// Save the Changes - Exception happens on next line!
PPGEDI.Data.DataRepository.SuppliersEntityEntityProvider.Save(supplier);
// Reload the information from the database to display
ReLoadInformation();
}
When I call that method from a button click on the aspx page, i get the following exception information:
Server Error in '/' Application.
The configuration file entlib.config could not be found.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.IO.FileNotFoundException: The configuration file entlib.config could not be found.
Source Error:
Line 190: public override void DoValidate(object objectToValidate, object currentTarget, string key, ValidationResults validationResults)
Line 191: {
Line 192: Validator validator = new ValidationIntegrationHelper(this).GetValidator();
Line 193:
Line 194: if (validator != null)
Source File: PPGEDI.Entities\Validation\PropertyValidator.cs Line: 192
Stack Trace:
[FileNotFoundException: The configuration file entlib.config could not be found.]
Microsoft.Practices.EnterpriseLibrary.Common.Configuration.FileConfigurationSource.GetRootedCurrentConfigurationFile(String configurationFile) +221
Microsoft.Practices.EnterpriseLibrary.Common.Configuration.FileConfigurationSource..ctor(String configurationFilepath, Boolean refresh, Int32 refreshInterval) +45
Microsoft.Practices.EnterpriseLibrary.Common.Configuration.FileConfigurationSource..ctor(String configurationFilepath, Boolean refresh) +48
Microsoft.Practices.EnterpriseLibrary.Common.Configuration.FileConfigurationSource..ctor(String configurationFilepath) +39
Microsoft.Practices.EnterpriseLibrary.Common.Configuration.FileConfigurationSourceElement.CreateSource() +64
Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ConfigurationSourceFactory.Create(String name) +355
Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ConfigurationSourceFactory.Create() +96
Microsoft.Practices.EnterpriseLibrary.Common.Configuration.EnterpriseLibraryContainer.CreateDefaultContainer() +25
Microsoft.Practices.EnterpriseLibrary.Common.Configuration.EnterpriseLibraryContainer.SetCurrentContainerIfNotSet() +84
Microsoft.Practices.EnterpriseLibrary.Common.Configuration.EnterpriseLibraryContainer.get_Current() +22
Microsoft.Practices.EnterpriseLibrary.Validation.ValidationFactory.get_DefaultCompositeValidatorFactory() +25
Microsoft.Practices.EnterpriseLibrary.Validation.PropertyValidationFactory.GetPropertyValidatorFromAttributes(Type type, PropertyInfo propertyInfo, String ruleset, MemberAccessValidatorBuilderFactory memberAccessValidatorBuilderFactory) +166
Microsoft.Practices.EnterpriseLibrary.Validation.PropertyValidationFactory.GetPropertyValidator(Type type, PropertyInfo propertyInfo, String ruleset, ValidationSpecificationSource validationSpecificationSource, MemberAccessValidatorBuilderFactory memberAccessValidatorBuilderFactory) +264
Microsoft.Practices.EnterpriseLibrary.Validation.PropertyValidationFactory.GetPropertyValidator(Type type, PropertyInfo propertyInfo, String ruleset, ValidationSpecificationSource validationSpecificationSource, MemberValueAccessBuilder memberValueAccessBuilder) +71
Microsoft.Practices.EnterpriseLibrary.Validation.Integration.ValidationIntegrationHelper.GetValidator() +106
PPGEDI.Entities.Validation.PropertyValidator.DoValidate(Object objectToValidate, Object currentTarget, String key, ValidationResults validationResults) in PPGEDI.Entities\Validation\PropertyValidator.cs:192
Microsoft.Practices.EnterpriseLibrary.Validation.Validator.Validate(Object target) +80
PPGEDI.Entities.EntityBaseCore.Validate(String propertyName) in PPGEDI.Entities\EntityBaseCore.generated.cs:477
PPGEDI.Entities.EntityBaseCore.OnPropertyChanged(PropertyChangedEventArgs e) in PPGEDI.Entities\EntityBaseCore.generated.cs:342
PPGEDI.Entities.EntityBaseCore.OnPropertyChanged(String propertyName) in PPGEDI.Entities\EntityBaseCore.generated.cs:329
PPGEDI.Entities.SuppliersEntityBase.set_Name(String value) in SuppliersEntityBase.generated.cs:279
PPGEDI.Supplier.Supplier_Main_Config.UpdateSupplier(Object sender, EventArgs e) in Supplier_Main_Config.aspx.cs:29
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +118
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +112
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5563
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.225
The following method seems to be the one that is causing the exception:
/// <summary>
/// Does the validate.
/// </summary>
/// <param name="objectToValidate">The object to validate.</param>
/// <param name="currentTarget">The current target.</param>
/// <param name="key">The key.</param>
/// <param name="validationResults">The validation results.</param>
public override void DoValidate(object objectToValidate, object currentTarget, string key, ValidationResults validationResults)
{
// Exception Error on next line!!!
Validator validator = new ValidationIntegrationHelper(this).GetValidator();
if (validator != null)
{
ValidationResults results = validator.Validate(this);
if (!results.IsValid)
{
validationResults.AddAllResults(results);
}
}
}
Now, here is the weirdest thing. I put breakpoints in to trace through and find the issue. I hit F5 in my browser, and there was no exception error. After some trial and error, I've found that I get this exception error every time I submit the form, but if I hit F5, it resubmits fine without error, and the update does happen in the database. It would be greatly appreciated if someone could advise as to why this would be happening and what I can do to fix this error. The entlib.config file is indeed in the project, It was generated as well, and I've verified that it does actually exist.
The information on the EntLib that is being called with the ValidationIntegrationHelper is:
Assembly Microsoft.Practices.EnterpriseLibrary.Validation.dll, v2.0.50727
UPDATE: I still haven't been able to figure out how to fix this, so I did a terrible thing, I put a try/catch block around the code in DoValidate, so that it won't blow up on me. I needed to get this not to break while the clients are using it, but I still need to figure out why it is doing this, and fix it, instead of ignoring it before we are into production. If it just handles validation, then I can handle ignoring it, because I'm validating on the front side before saving or updating the entities.
The issue seems to be just in the Enterpise Library validation. I regenerated the project with NetTiers validation and I don't have the issue. I wasn't able to figure out what the issue was, but generating the project with the NetTiers validation made the problem go away.
Related
I made a application in asp.net c# using linq and oracle database.This application is working fine on Widows 7 32 bit local host.But When I deployed this application in windows server 2008 r2.It gives a following error.Guide me what is the following error.How Can I check this error on deployment server and How can I resolved this error
Specified cast is not valid. Description: An unhandled exception
occurred during the execution of the current web request. Please
review the stack trace for more information about the error and where
it originated in the code.
Exception Details: System.InvalidCastException: Specified cast is not
valid.
Source Error:
An unhandled exception was generated during the execution of the
current web request. Information regarding the origin and location of
the exception can be identified using the exception stack trace below.
Stack Trace:
[InvalidCastException: Specified cast is not valid.]
System.Data.UnboxT`1.ValueField(Object value) +54
sis.<>c__DisplayClass55.b__0(DataRow r) +38
System.Linq.WhereEnumerableIterator`1.MoveNext() +156
System.Linq.WhereSelectEnumerableIterator`2.MoveNext() +165
System.Linq.d__81`1.MoveNext() +472
System.Linq.Enumerable.Count(IEnumerable`1 source) +267
sis.regreport.Page_Load(Object sender, EventArgs e) +5015
System.Web.UI.Control.LoadRecursive() +71
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean
includeStagesAfterAsyncPoint) +3178
var vcolM = dt.AsEnumerable()
.Where(r => r.Field<string>("MAJ") == (string)vprglist
&& r.Field<string>("SPEC") == (string)vspecourse
&& r.Field<string>("L_ABR_CODE") == (string)genderEng[1]
&& r.Field<string>("reg") == (string)drRegion["reg"]
&& r.Field<decimal>("year") == syrcnt)
.Sum(r => Convert.ToInt32(r["strength"]));
All linq like above working fine in local pc.But giving error in windows server 2008.Where syrcnt is int.
The most likely cause of the InvalidCastException is the r.Field<string>("MAJ") , r.Field<decimal>("year") line. The Field<T> extension method will throw an InvalidCastException in the case where the actual type of the data doesn't match the type which was passed to Field<T>.
OR
lies in here Convert.ToInt32(r["strength"]), the strength might not be getting proper type
Honestly, I think you issues lies in the line r.Field<decimal>("year"). I may be wrong as there is not much information about the datatype of your variable syrcnt
Hence giving you the exception System.InvalidCastException: Specified cast is not valid
I have a new app and I am trying to navigate to another page:
private void HyperlinkButton_Click(object sender, RoutedEventArgs e)
{
this.Frame.Navigate(typeof(MultiView));
}
This same code works in previous apps I've made. I don't understand why it's not working anymore.
The exception thrown is:
System.ArgumentNullException was unhandled by user code HResult=-2147467261 Message=Value cannot be null. Parameter name: key Source=mscorlib ParamName=key StackTrace:
at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
at System.Collections.Generic.Dictionary`2.set_Item(TKey key, TValue value)
at MyAppName.Common.LayoutAwarePage.OnNavigatedFrom(NavigationEventArgs e) in c:\Users\UserName\Documents\Visual Studio 2013\Projects\MyAppName\MyAppName\Common\LayoutAwarePage.cs:line 373
at MyAppName.MainPage.OnNavigatedFrom(NavigationEventArgs e) in c:\Users\UserName\Documents\Visual Studio 2013\Projects\MyAppName\MyAppName\MainPage.xaml.cs:line 804 InnerException:
How can I navigate to another page? (I am using the same code as described in MSDN documentation. And I've been over it many times. This has never been a problem until now.
First of all, I'd like to apologize in advance for my lack of proficiency in the area of C#.
Although I have very little knowledge of the subject I was in a situation where I needed to create an exact copy of a website. The website is using .NET 4.0, runs on IIS 7 with MSSQL Server 2008. The new website is set up as a subdomain of the old one.
I did a full backup of the original database, created a new database and "restored" it with the orginal's backup. The only thing I changed was the .mdf and .ldf files.
I then copied and pasted the actual files to the new folder and changed the config files with the new database.
Everything works perfectly until you add/delete news to/from the database. At that point, the front page of the website renders the following message:
Server Error in '/' Application.
Length cannot be less than zero.
Parameter name: length
Stack trace:
[ArgumentOutOfRangeException: Length cannot be less than zero.
Parameter name: length]
System.String.InternalSubStringWithChecks(Int32 startIndex, Int32 length, Boolean fAlwaysCopy) +10082776
Tang.Core.Utility.HtmlHelper.CutText(String rawText, Int32 length) +242
Tang.Website.UC.ArticleItems.GetLegacyDataTable(Int32 collectionId, Int32 maxRecord) +2172
Tang.Website.UC.ArticleItems.Page_Load(Object sender, EventArgs e) +150
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +25
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +42
System.Web.UI.Control.OnLoad(EventArgs e) +132
System.Web.UI.Control.LoadRecursive() +66
System.Web.UI.Control.LoadRecursive() +191
System.Web.UI.Control.LoadRecursive() +191
System.Web.UI.Control.LoadRecursive() +191
System.Web.UI.Control.LoadRecursive() +191
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2428
Another error is when a user is logged in (again "length cannot be zero"):
<%-- <p class="news_date"><%# Eval("collectionitemdatetime", "{0:d}") %></p>--%>
<p class="news_cont">
**<%# Tang.Core.Utility.HtmlHelper.CutText( Eval("collectionitemtext").ToString(), 450) %>** --> THIS IS WHERE THE PROBLEM IS, OBVIOUSLY STRING IS EMPTY?</p>
</div>
</ItemTemplate>
I am totally lost as nothing "major" has been edited from the original. I must be doing something wrong with the database.
EDIT: The thing is, as soon as I change the datbase from the webconfig file [to the original database], everything works, I can add/remove/edit items and they are shown on the home page. So it's gotta be something between the website & the database and not code-related
EDIT 2, Found a solution: I deleted the database, created a new one and instead of doing a "restore", I did "Export" from the original one. I had to set the primary keys manually and change some of them to (Is Identify) - Yes because I was getting the same error. Not the most elegant solution but at least everything seems to be working now.
Thank you all for your help!
Looks like length parameter comes with -1 value to CutText function. Is there an ORM tool you use? If you use Entity framework, you must set your connection string proper. Maybe your sql security properties doesn't let you to add. Sure look at your db when you add a news.
I'm using localReport to print PDF (SQL REPORTVIEWER). It works fine on localhost. When I move the application to Production (64 bits windows 2008) it gives me an error. (see below)
I put the renderedbytes in a Session in USERCONTROL and I do window.open('Program1.aspx')...
In page load of Program1.aspx I try to retrieve the Session variable and process....
I think this statement cause the error "Response.BinaryWrite (...) etc".
It works on my local pc (Vista 32bits)...
Can someone please what the errors says? and How can I solve this on production??????
thank you..
USERCONTROL1.ASCX
byte[] renderedBytes;
renderedBytes = localReport.Render(
reportType,
deviceInfo,
out mimeType,
out encoding,
out fileNameExtension,
out streams,
out warnings);
Session["report"] = Print.RenderReport(listEnt, Language);
PROGRAM2.ASPX
protected void Page_Load(object sender, EventArgs e)
{
string extension = "PDF";
Response.ContentType = "application/pdf";
// set the MIME type here
Response.AddHeader("content-disposition", "inline: filename=Test." + extension);
Response.BinaryWrite((byte[])Session["report"]);
Response.End();
}
Server Error in '/' Application.
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.]
System.Web.HttpResponse.BinaryWrite(Byte[] buffer) +13
ConfederatieBouw.CustomModules.Controle_InhoudingsPlicht.WebForm1.Page_Load(Object sender, EventArgs e) +191
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +50
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsync
Are you running a web farm in production? If so, how are you storing session state? The default is InProc, which means the session will only exist on one server in the farm, and if the follow up request goes to another server, that would explain the issue. The fix this scenario, you will need to setup some sort of session state that can be shared across servers (such as a session state server or SQL Server session state).
Here is some info on the various session state providers:
http://msdn.microsoft.com/en-us/library/ms178586.aspx
Session["report"] is null. You're not setting it to renderBytes in the user control.
Also, it's a really bad idea to store this in a Session. Your binary data has to be serialized/encoded and then deserialized/unencoded whenever you set the Session[] value, which performs poorly. Create a property on the user control to accept the report object and write it to the output stream there, or just do it in the page itself. I'm not sure that it makes sense to put this in a user control instead of a regulat class, anyway.
Here's what's going on. I'm opening a file on FTP that exists using a WebClient. The file exists and the function has worked in the past, but now for some reason throws an exception. (System.Net.WebException: The remote server returned an error: (550) File unavailable (e.g., file not found, no access).). The funny thing is, the script still opens the file and does what it's supposed to. Has anyone ever heard of anything like this?
WebClient downloadRequest = new WebClient();
downloadRequest.Credentials = new NetworkCredential(pusername, ppassword);
byte[] downloadBytes = downloadRequest.DownloadData(purl);
Here's the stack trace:
[WebException: The remote server returned an error: (550) File unavailable (e.g., file not found, no access).]
System.Net.WebClient.DownloadDataInternal(Uri address, WebRequest& request) +287
System.Net.WebClient.DownloadData(Uri address) +106
System.Net.WebClient.DownloadData(String address) +29
ftp_connect.copyFile(String purl, String pusername, String ppassword, String pubordev) in d:\wwwdev\test\ftp\ftpconnect.aspx.cs:112
ftp_connect.copyFolder(String purl, String pusername, String ppassword, String pubordev) in d:\wwwdev\test\ftp\ftpconnect.aspx.cs:160
ftp_connect.Page_Load(Object sender, EventArgs e) in d:\wwwdev\test\ftp\ftpconnect.aspx.cs:93
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +50
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627
Presumably the file is there from a previous successful run?
The script might be using a version of the file saved when the Web request was still working.
Maybe the file is in user by some other client/user.
It turns out that I was calling a function which called the function I was trying to get to.
So, the solution I guess was to look at the stack. Should have done that first.