Weird System.AccessViolationException on accessing Type.FullName

Answered Weird System.AccessViolationException on accessing Type.FullName

  • Wednesday, September 12, 2012 10:12 AM
     
     

    Hello,

    on Win2008 R2 SP1 server, using a .NET 3.5 WinForms program, I intermittedly get weird AccessViolationExceptions in strange places, such as the following:

    System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
       at System.RuntimeType.RuntimeTypeCache..ctor(RuntimeType runtimeType)
       at System.RuntimeType.get_Cache()
       at System.RuntimeType.get_FullName()
       at Clx.Tools.TypeUtils.SearchType(String typename, Boolean doNotSearchSystemAssemblies)
       at Clx.EventoNG.Backend.Framework.CustomMetaModel.get_AttributedMetaTableType()
       at Clx.EventoNG.Backend.Framework.CustomMetaModel.GetTable(Type rowType)
       at System.Data.Linq.DataContext.GetTable[TEntity]()
       at Clx.EventoNG.Backend.Framework.DataServices.GetTable[TEntity]()
       at Clx.EventoNG.Backend.Framework.DataServices.GetByIdAsQueryable[TEntity](Object id)
       at Clx.EventoNG.Backend.Framework.DataServices.GetById[TEntity](Object id, Boolean throwIfNotFound)
       at Clx.EventoNG.Backend.Configuration.ConfigurationHelper.<get_BranchAsEnum>b__4()
       at Clx.Tools.Cache.Get[T](String key, Boolean cachingPerCulture, Func`1 constructObjectFunction)
       at Clx.EventoNG.Backend.Configuration.ConfigurationHelper.get_BranchAsEnum()
       at Clx.EventoNG.Backend.Configuration.ConfigurationHelper.<get_BranchAsString>b__2()
       at Clx.Tools.Cache.Get[T](String key, Boolean cachingPerCulture, Func`1 constructObjectFunction)
       at Clx.EventoNG.Backend.Configuration.ConfigurationHelper.get_BranchAsString()
       at Clx.EventoNG.Backend.Wcf.ServiceRunner.RunServices(Boolean waitForDebugFormClose, Boolean closeServicesOnExit, Nullable`1 function, String userId)
       at Clx.EventoNG.Backend.Wcf.ServiceRunner.RunServices(Boolean waitForDebugFormClose, Boolean closeServicesOnExit, Nullable`1 function, String userId)
       at Clx.EventoNG.Backend.Program.Main(String[] args)
    Stack Trace:
    Clx.Tools.Logging.LogAndGenerateException Line:0
    Clx.EventoNG.Backend.Program.Main Line:0

    It is really weird since Type.FullName does not normally throw any exceptions at all, let alone access violation excpetions. Does anyone have a clue what could be wrong here?

All Replies

  • Wednesday, September 12, 2012 10:24 AM
     
     
    You may have a race condition that the database you are using isn't locking an entry while it is being modified.  You may be trying to do a query as the data is being changed.  What type database are you using?  Is the database sharable?  If you are using Access or Excel as your database they don't work well in shared mode over a network.

    jdweng

  • Thursday, September 13, 2012 8:30 AM
    Moderator
     
     

    Hi Urs,

    Welcome to the MSDN Forum.

    Would you like to show us the related code?

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

  • Thursday, September 13, 2012 9:12 AM
     
      Has Code

    Hi Mike

    the code is as follows. Note that this code has been in production for years on various machines and never made any problems. So I don't think the problem is with the code itself, but somewhere in the OS.

    private static Dictionary<string, Type> _SearchType_Cache = new Dictionary<string, Type>(); /// <summary> /// searches for type 'typename' in all loaded assemblies. /// </summary> /// <param name="typename"></param> /// <returns></returns> public static Type SearchType(string typename, bool doNotSearchSystemAssemblies) { Type type; if (_SearchType_Cache.TryGetValue(typename, out type)) return type; foreach (Assembly assy in AppDomain.CurrentDomain.GetAssemblies()) { string name = assy.GetName().Name; if (doNotSearchSystemAssemblies) { if (name.StartsWith("System", StringComparison.OrdinalIgnoreCase) || name.StartsWith("Microsoft", StringComparison.OrdinalIgnoreCase) || name.StartsWith("mscorlib", StringComparison.OrdinalIgnoreCase)) continue; } if (name.Contains("VisualStudio")) continue; IEnumerable<Type> types; try { types = assy.GetTypes(); } catch (ReflectionTypeLoadException exception) {

    CRASH OCCURS HERE, ON GETTING Assembly.FullName
    throw new InvalidOperationException(("Cannot enumerate types in assembly '{0}'. Error: '{1}'. Loader Exceptions: " + exception.LoaderExceptions.Concat("\r\n")).FormatSecure(assy.FullName, exception.Message), exception); } foreach (Type t in types) { if (t.FullName.Equals(typename, StringComparison.OrdinalIgnoreCase) || t.Name.Equals(typename, StringComparison.OrdinalIgnoreCase)) { _SearchType_Cache[typename] = t; return t; } } } throw new TypeLoadException("didn't find type '{0}' in loaded assemblies.".FormatSecure(typename)); }



    Urs Meili


    • Edited by Urs.Meili Thursday, September 13, 2012 9:13 AM
    •  
  • Monday, September 17, 2012 2:58 AM
    Moderator
     
     

    Hi Meili,

    I haven't reproduce this scenario.

    Would you like to help to test the other version .net framework, such as 4.0 and the other computer?

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

  • Monday, September 17, 2012 6:26 AM
     
     Answered

    Hi Mike

    It seems that the problem is not with the application, but with the hardware. We moved the application to another Win2008 R2 host, and there it seems to work perfectly. Apparently the memory was corrupt, or there was another setup problem with the first host.

    So I think we can close this case.

    Thanks for your help

    Urs Meili


    Urs Meili

    • Marked As Answer by Urs.Meili Monday, September 17, 2012 6:26 AM
    •  
  • Monday, September 17, 2012 8:47 AM
    Moderator
     
     

    Hi Meili,

    Thank you for your update.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.