Getting error while opening form in visual studio 2005 - winforms

i am getting below excetion on opening a form on visual studio work bench
Its not always but sometime it opens without any problem
Does anyone has a solution for this?
The path is not of a legal form.
Hide
at System.IO.Path.NormalizePathFast(String path, Boolean fullCheck)
at System.IO.Path.NormalizePath(String path, Boolean fullCheck)
at System.IO.Path.GetFullPathInternal(String path)
at System.Reflection.AssemblyName.GetAssemblyName(String assemblyFile)
at Microsoft.VisualStudio.Design.VSTypeResolutionService.AddProjectDependencies(Project project)
at Microsoft.VisualStudio.Design.VSTypeResolutionService.AssemblyEntry.get_Assembly()
at Microsoft.VisualStudio.Design.VSTypeResolutionService.AssemblyEntry.Search(String fullName, String typeName, Boolean ignoreTypeCase, Assembly& assembly, String description)
at Microsoft.VisualStudio.Design.VSTypeResolutionService.SearchProjectEntries(AssemblyName assemblyName, String typeName, Boolean ignoreTypeCase, Assembly& assembly)
at Microsoft.VisualStudio.Design.VSTypeResolutionService.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase, ReferenceType refType)
at Microsoft.VisualStudio.Design.Serialization.CodeDom.AggregateTypeResolutionService.GetType(String name, Boolean throwOnError, Boolean ignoreCase)
at Microsoft.VisualStudio.Design.Serialization.CodeDom.AggregateTypeResolutionService.GetType(String name, Boolean throwOnError)
at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.GetType(ITypeResolutionService trs, String name, Dictionary`2 names)
at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.FillStatementTable(IDesignerSerializationManager manager, IDictionary table, Dictionary`2 names, CodeStatementCollection statements, String className)
at System.ComponentModel.Design.Serialization.TypeCodeDomSerializer.Deserialize(IDesignerSerializationManager manager, CodeTypeDeclaration declaration)
at System.ComponentModel.Design.Serialization.CodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager manager)
at Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager serializationManager)
at Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomDesignerLoader.DeferredLoadHandler.Microsoft.VisualStudio.TextManager.Interop.IVsTextBufferDataEvents.OnLoadCompleted(Int32 fReload)

From connect.microsoft.com:
This is a known issue and is a
regression from VS 2003. If this is
the known issue, this error happens
because a reference cannot be resolved
in your project. When the designer
loads, it attempts to locate and load
every assembly that is in your
reference list. In C#, you can expand
the reference list to see this. In VB,
you must click the "Show All Files"
button in the solution explorer window
to view the references collection. Try
to remove dead references, or remove
and re-add any custom references and
then reload the designer.
I would also clean your solution and rebuild (right click your solution in VS and select Clean, right click again and select Rebuild).

Install resharper. In VS right click on references and choose 'optimize references' , after clean+rebuild probably no problem exists!

Related

Why is this Entity Framework crash sometimes happening in my WPF app?

I manage a publicly available WPF app which uses Entity Framework 6.1 (model-first ObjectContext) and a SQLite database.
The number one crash log (according to HockeyApp) for my app is the following (with pointers to my app's code marked ****):
System.InvalidOperationException: The property 'Id' is part of the object's key information and cannot be modified.
at System.Data.Entity.Core.Objects.EntityEntry.VerifyEntityValueIsEditable(StateManagerTypeMetadata typeMetadata, Int32 ordinal, String memberName)
at System.Data.Entity.Core.Objects.EntityEntry.GetAndValidateChangeMemberInfo(String entityMemberName, Object complexObject, String complexObjectMemberName, StateManagerTypeMetadata& typeMetadata, String& changingMemberName, Object& changingObject)
at System.Data.Entity.Core.Objects.EntityEntry.EntityMemberChanging(String entityMemberName, Object complexObject, String complexObjectMemberName)
at System.Data.Entity.Core.Objects.EntityEntry.EntityMemberChanging(String entityMemberName)
at System.Data.Entity.Core.Objects.ObjectStateEntry.System.Data.Entity.Core.Objects.DataClasses.IEntityChangeTracker.EntityMemberChanging(String entityMemberName)
at System.Data.Entity.Core.Objects.DataClasses.EntityObject.ReportPropertyChanging(String property)
****
at MyNamespace.MyApp.MyEntity.set_Id(Int64 value) in C:\MyPath\MyApp\EfGeneratedEntities.cs
****
at lambda_method(Closure , Object , Object )
at System.Data.Entity.Core.Objects.DelegateFactory.SetValue(EdmProperty property, Object target, Object value)
at System.Data.Entity.Core.Objects.StateManagerMemberMetadata.SetValue(Object userObject, Object value)
at System.Data.Entity.Core.Objects.Internal.LightweightEntityWrapper`1.SetCurrentValue(EntityEntry entry, StateManagerMemberMetadata member, Int32 ordinal, Object target, Object value)
at System.Data.Entity.Core.Objects.EntityEntry.SetCurrentEntityValue(StateManagerTypeMetadata metadata, Int32 ordinal, Object userObject, Object newValue)
at System.Data.Entity.Core.Objects.ObjectStateEntryDbUpdatableDataRecord.SetRecordValue(Int32 ordinal, Object value)
at System.Data.Entity.Core.Mapping.Update.Internal.PropagatorResult.SetServerGenValue(Object value)
at System.Data.Entity.Core.Mapping.Update.Internal.UpdateTranslator.BackPropagateServerGen(List`1 generatedValues)
at System.Data.Entity.Core.Mapping.Update.Internal.UpdateTranslator.Update()
at System.Data.Entity.Core.EntityClient.Internal.EntityAdapter.<Update>b__2(UpdateTranslator ut)
at System.Data.Entity.Core.EntityClient.Internal.EntityAdapter.Update[T](T noChangesResult, Func`2 updateFunction)
at System.Data.Entity.Core.EntityClient.Internal.EntityAdapter.Update()
at System.Data.Entity.Core.Objects.ObjectContext.<SaveChangesToStore>b__d()
at System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func`1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess)
at System.Data.Entity.Core.Objects.ObjectContext.SaveChangesToStore(SaveOptions options, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction)
at System.Data.Entity.Core.Objects.ObjectContext.<>c__DisplayClassb.<SaveChangesInternal>b__8()
at System.Data.Entity.Infrastructure.DefaultExecutionStrategy.Execute[TResult](Func`1 operation)
at System.Data.Entity.Core.Objects.ObjectContext.SaveChangesInternal(SaveOptions options, Boolean executeInExistingTransaction)
at System.Data.Entity.Core.Objects.ObjectContext.SaveChanges()
****
at MyNamespace.MyApp.MyContext.OnMyEvent() in C:\MyPath\MyApp\MyContext.cs
****
I have not been able to reproduce this crash, and so I have not been able to attempt to fix it. I would love to get it sorted.
I understand the crash message. But my app is not doing anything that should cause this. The MyEntity.Id property is an entity key (with StoreGeneratedPattern = Identity) and I never manually set the Id value. I never manually mark an entity as modified. My SQLite DB does not have any triggers or anything else that could mess with EF's interpretation of DB-generated identity values. I really can't see how this crash could happen, and I can't make it happen myself - inserts of new entities work just fine for me.
I of course don't expect anyone to read this post and come up with the solution, but I'm hoping somebody can lead me in the right direction.
What non-obvious reasons could cause this crash to happen?
I'm sure I'll be asked for source code, but there's really not much to it. In the culprit code I simply create a MyEntity object, set some property values, add it to context, and call SaveChanges(). That's it. As I said, it works just fine in my testing and for 99% of customer usage. But I get several crash reports like this every day and I'd love to put an end to them.
---- UPDATE ----
I think it's worth pointing out that the MyEntity.set_Id(Int64 value) in the stack trace is clearly part of Entity Framework's key/identity value retrieval (see lines around PropagatorResult.SetServerGenValue(Object value), etc.). This is not my code setting the Id, it's EF.
Looking the Entity Framework source code, this exception is thrown when trying to set an entity key value for an entity not in the Added state:
// Key fields are only editable if the entry is the `Added` state.
if (member.IsPartOfKey
&& State != EntityState.Added)
{
throw new InvalidOperationException(Strings.ObjectStateEntry_CannotModifyKeyProperty(memberName));
}
So could the issue be that MyEntity is somehow being put into an alternate state (e.g. Modified) before SaveChanges() (or during SaveChanges() but before identity value retrieval)?
How could that happen? As I mentioned, I am not manually setting the state anywhere.
Solved.
The MyNamespace.MyApp.MyContext.OnMyEvent() line at the bottom of my stack trace gets executed at a scheduled time.
It turns out that it would be possible for two or more executions to be scheduled at the same time. In some cases (even in my testing it was inconsistent and usually worked anyway), it would cause this crash, presumably because SQLite's EF generated ID retrieval could be tripped up when multiple DB inserts are done in near instantaneous proximity.
Anyway, the solution was to simply wrap the code in MyNamespace.MyApp.MyContext.OnMyEvent() in a lock { ... } statement to prevent concurrent execution.

Can't get Dynamic LINQ to work -Reflection error

Trying to produce my first sample with Dynamic LINQ and I just can't seem to get it to work. Here's what I've got. NBL It's a bit rugged because I've been culling it back trying to find the problem.
Dim blah = (New dcDataContext).Employees.Where("AccountGUID=#1", accountId)
The error I am getting is:
Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
[ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.]
System.Reflection.RuntimeModule.GetTypes(RuntimeModule module) +0
System.Reflection.RuntimeModule.GetTypes() +4
System.Reflection.Assembly.GetTypes() +70
System.Linq.Dynamic.DefaultDynamicLinqCustomTypeProvider.<FindTypesMarkedWithAttribute>b__0(Assembly x) +38
System.Linq.<SelectManyIterator>d__14`2.MoveNext() +234
System.Linq.WhereEnumerableIterator`1.MoveNext() +152
System.Collections.Generic.HashSet`1.UnionWith(IEnumerable`1 other) +82
System.Collections.Generic.HashSet`1..ctor(IEnumerable`1 collection, IEqualityComparer`1 comparer) +125
System.Collections.Generic.HashSet`1..ctor(IEnumerable`1 collection) +50
System.Linq.Dynamic.DefaultDynamicLinqCustomTypeProvider.GetCustomTypes() +81
System.Linq.Dynamic.ExpressionParser.CreateKeywords() +532
System.Linq.Dynamic.ExpressionParser..ctor(ParameterExpression[] parameters, String expression, Object[] values) +66
System.Linq.Dynamic.DynamicExpression.ParseLambda(ParameterExpression[] parameters, Type resultType, String expression, Object[] values) +72
System.Linq.Dynamic.DynamicExpression.ParseLambda(Type itType, Type resultType, String expression, Object[] values) +132
System.Linq.Dynamic.DynamicQueryable.Where(IQueryable source, String predicate, Object[] args) +252
System.Linq.Dynamic.DynamicQueryable.Where(IQueryable`1 source, String predicate, Object[] args) +51
TimeClock.Linq.Filters.Employees.QueryableExtensions.FromAccount(IQueryable`1 source, Guid accountId) in C:\Visual Studio Projects\mtc
tc
.login.Page_Load(Object sender, EventArgs e) in C:\Visual Studio Projects\mtc\tc\login.aspx.vb:13
System.Web.UI.Control.OnLoad(EventArgs e) +92
System.Web.UI.Control.LoadRecursive() +54
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +772
You should write it like this:
Dim blah = (New dcDataContext).Employees.Where("AccountGUID=#0", accountId)
refer:
This is completely weird but here's what I did (trying to fix something else) and now it works. I set full access permissions to 'Everyone' on the folder C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files

How do I fix DNN registration NullReferenceException on ProfilePropertyAccess.DisplayDataType?

On our production environment users are unable to register.
They receive: An error has occurred. Error: User Registration is currently unavailable.
The stacktrace is:
DotNetNuke.Services.Exceptions.ModuleLoadException: Object reference not set to an instance of an object. ---> System.NullReferenceException: Object reference not set to an instance of an object. at DotNetNuke.Entities.Users.ProfilePropertyAccess.DisplayDataType(ProfilePropertyDefinition definition) at DotNetNuke.Entities.Users.ProfilePropertyAccess.GetRichValue(ProfilePropertyDefinition prop, String strFormat, CultureInfo formatProvider) at DotNetNuke.Entities.Users.ProfilePropertyAccess.GetProperty(String strPropertyName, String strFormat, CultureInfo formatProvider, UserInfo AccessingUser, Scope currentScope, Boolean& PropertyNotFound) at DotNetNuke.Services.Tokens.BaseCustomTokenReplace.replacedTokenValue(String strObjectName, String strPropertyName, String strFormat) at DotNetNuke.Services.Tokens.BaseTokenReplace.ReplaceTokens(String strSourceText) at DotNetNuke.Services.Localization.Localization.GetSystemMessage(String strLanguage, PortalSettings objPortal, String MessageName, UserInfo objUser, String ResourceFile, ArrayList CustomArray, IDictionary CustomDictionary, String CustomCaption, Int32 AccessingUserID) at DotNetNuke.Services.Mail.Mail.SendMail(UserInfo user, MessageType msgType, PortalSettings settings) at DotNetNuke.Entities.Modules.UserModuleBase.CompleteUserCreation(UserCreateStatus createStatus, UserInfo newUser, Boolean notify, Boolean register) at DotNetNuke.Modules.Admin.Users.ManageUsers.UserCreateCompleted(Object sender, UserCreatedEventArgs e)
I suspect there is a profile property definition missing. I'm wondering how to fix this error?
It turns out my ProfilePropertyDefinition table DataType column values do not match EntryID values from the Lists table.
select * from profilePropertyDefinition
compared to
select * from Lists
where Listname = 'DataType'
order by EntryID
I figured this out by
Noticing users are actually added
Then I looked at a working dnn install's profile property page. Compared to the broken one.
The broken one was missing the data type field.

strange problem with reflection and static method

Visual Studio 2008 - framework 3.5 - Visual Basic
Hi!
I have a problem with a static method invoked by reflection.
On the loading of my win-wpf I create a copy of "A4Library.dll" with the name "_temp.dll", in the same directory of the original.
Then, on a button-click event, I invoke a static method on the _temp.dll in this way:
Dim AssemblyFileName As String = Directory.GetCurrentDirectory() & "\_temp.dll"
Dim oAssembly As Assembly = Assembly.LoadFrom(AssemblyFileName)
Dim TypeName As String = "MyLibrary.MyService"
Dim t As Type = oAssembly.GetType(TypeName)
Dim mi As MethodInfo = t.GetMethod("MyMethod", BindingFlags.Static AndAlso BindingFlags.Public)
Dim bResponse As Boolean = mi.Invoke(Nothing, New Object() {MyPar1, MyPar2})
But this works well only if I the .exe file is not in the same directory of the .dll files, otherwise I obtain this error (translated):
InnerException {"Cast impossible of [A]MyType on [B]MyType. The type A is originated from ... in the context 'Default' in the position 'F:\MyPath\A4Library.dll'. The type B is originated from ... in the context 'LoadFrom' in the position 'F:\MyPath_temp.dll'."}
It's strange: it seems to be a conflict with the same method in the original .dll, but I can't undertend why it looks at the original and not at the copy. If the .exe file relative to the principal assembly is placed in another directory, all runs well.
I neet to have the .exe in the same folder of the .dll, how can I solve the problem?
Thank you!
Pileggi
Why create a copy of assembly before executing static method? If creating a copy is needed, load that assembly in another AppDomain and execute the method in there.

Attempted to read or write protected memory. This is often an indication that other memory has been corrupted

I created a Winforms AutoComplete combobox control inheriting from ComboBox with the following method:
Protected Overrides Sub OnKeyPress(ByVal e As System.Windows.Forms.KeyPressEventArgs)
MyBase.OnKeyPress(e)
Dim text As String = Me.Text
If Char.IsLetter(e.KeyChar) Then
text = text + e.KeyChar
End If
If (text.Length = AutoCompleteSearchChars And Char.IsLetter(e.KeyChar)) Then
SetAutoCompleteMethod.Invoke(text)
Me.AutoCompleteSource = AutoCompleteSource.ListItems
Me.Text = text
Me.SelectionStart = text.Length
Me.SelectionLength = 0
If Me.Items.Count > 0 Then
Me.SelectedIndex = 0
End If
e.Handled = True
End If
End Sub
The "SetAutoCompleteMethod" is a delegate pointing to a method that populates the
combobox items based on using the current text in the combo box as the prefix for a
wildcard search. This provides similar functionality to the ajax autocomplete combobox.
This all works fine the first time it is called, but the second time it is called I get the "Attempted to read or write protected memory. This is often an indication that other memory has been corrupted" error. The error appears after all the code to update the combobox is completed. I get the following stack trace:
at
System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG&
msg) at
System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.
UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32
dwComponentID, Int32 reason, Int32
pvLoopData) at
System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32
reason, ApplicationContext context)
at
System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32
reason, ApplicationContext context)
at
System.Windows.Forms.Application.Run(ApplicationContext
context) at
Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
at
Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
at
Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[]
commandLine) at
ApplicationShell.My.MyApplication.Main(String[]
Args) in
17d14f5c-a337-4978-8281-53493378c1071.vb:line
81 at
System.AppDomain._nExecuteAssembly(Assembly
assembly, String[] args) at
System.AppDomain.ExecuteAssembly(String
assemblyFile, Evidence
assemblySecurity, String[] args) at
Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at
System.Threading.ThreadHelper.ThreadStart_Context(Object
state) at
System.Threading.ExecutionContext.Run(ExecutionContext
executionContext, ContextCallback
callback, Object state) at
System.Threading.ThreadHelper.ThreadStart()
Is Anyone able to point me in the right direction to solve this?
When I've gotten that error, it turned out to really be an issue with dereferencing a null pointer, but it made the method call anyway and didn't crash until it tried to access one of the member variables. I haven't really worked with VB since before the days of .Net, but your stack trace suggests it died in a native call somewhere. If that's the case, you might be running into the same issue in which case I'd recommend you double check those pointers, not just where it crashes, but a couple levels up too.
Adding an object to the items collection whose ToString() method returns nothing is an easy way to get this. There are probably other ways to reach the same behavior.
Proceed to diagnosis it as if it were a NullReferenceException.
See What's the strangest corner case you've seen in C# or .NET? for another case.

Resources