While doing some load testing on our .Net Win32 application, I ran into some exception:
System.TypeInitializationException: The type initializer for 'MyClass' threw an exception. ---> System.InvalidOperationException: Custom counters file view is out of memory.
at System.Diagnostics.SharedPerformanceCounter.CalculateMemory(Int32 oldOffset, Int32 totalSize, Int32& alignmentAdjustment)
at System.Diagnostics.SharedPerformanceCounter.CreateInstance(CategoryEntry* categoryPointer, Int32 instanceNameHashCode, String instanceName, PerformanceCounterInstanceLifetime lifetime)
at System.Diagnostics.SharedPerformanceCounter.GetCounter(String counterName, String instanceName, Boolean enableReuse, PerformanceCounterInstanceLifetime lifetime)
at System.Diagnostics.SharedPerformanceCounter..ctor(String catName, String counterName, String instanceName, PerformanceCounterInstanceLifetime lifetime)
at System.Diagnostics.PerformanceCounter.InitializeImpl()
at System.Diagnostics.PerformanceCounter..ctor(String categoryName, String counterName, String instanceName, Boolean readOnly)
It happens when running this line:
new PerformanceCounter("CategoryName", "CounterName", "InstanceName", false);
I'm not very familiar with the performance counter, by seeing this message, I understand they are stored in some file, but is this the responsability of the developer to clear this file? If yes how? If no, what should I do?
I've 5 instance of this application running on the same machine.
Performance Counters Implement IDisposable, so you can use
Directly:
perfCounter.Close();
perfCounter.Dispose();
Indirectly:
using(PerformanceCounter perfCounter=new PerformanceCounter())
{
//Your Code.
}
to clear its resources.
Also you can allocate more memory to the performance counter using the registry. See this post in the documentation: https://msdn.microsoft.com/en-us/library/system.diagnostics.performancecounter(v=vs.110).aspx
Performance counter categories installed with the .NET Framework 2.0 use separate shared memory, with each performance counter category having its own memory. You can specify the size of separate shared memory by creating a DWORD named FileMappingSize in the registry key HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\\Performance. The FileMappingSize value is set to the shared memory size of the category. The default size is 131072 decimal. If the FileMappingSize value is not present, the fileMappingSize attribute value for the performanceCounters element specified in the Machine.config file is used, causing additional overhead for configuration file processing. You can realize a performance improvement for application startup by setting the file mapping size in the registry. For more information about the file mapping size, see Element.
Related
OS: Mac M1
Framework: .Net 6.0
IDE: Rider
NuGet packages:
Microsoft.ClearScript (v7.2.1)
Microsoft.ClearScript.V8 (v7.2.1)
My simple JavaScript REPL:
using Microsoft.ClearScript.V8;
using myConsole = System.Console;
var v8 = new V8ScriptEngine();
v8.AddHostType("myConsole", typeof(Console));
// JavaScript REPL
while (true)
{
myConsole.WriteLine("> ");
var expression = myConsole.ReadLine();
if(string.IsNullOrEmpty(expression)) continue;
if(expression.Equals("exit", StringComparison.InvariantCultureIgnoreCase)) Environment.Exit(0);
try
{
_ = v8.Evaluate(expression);
}
catch (Exception ex)
{
myConsole.WriteLine(ex.Message);
}
}
I can build it without any problems. But if I run my code I get the error. I see it can't find file ClearScriptV8.osx-arm64.dylib:
/Users/andrey/RiderProjects/ConsoleApp1/ConsoleApp1/bin/Debug/net6.0/ConsoleApp1
Unhandled exception. System.TypeLoadException: Cannot load ClearScript V8 library. Load failure information for ClearScriptV8.osx-arm64.dylib:
/Users/andrey/RiderProjects/ConsoleApp1/ConsoleApp1/bin/Debug/net6.0/runtimes/osx-arm64/native/ClearScriptV8.osx-arm64.dylib: Unable to load shared library '/Users/andrey/RiderProjects/ConsoleApp1/ConsoleApp1/bin/Debug/net6.0/runtimes/osx-arm64/native/ClearScriptV8.osx-arm64.dylib' or one of its dependencies. In order to help diagnose loading problems, consider setting the DYLD_PRINT_LIBRARIES environment variable: dlopen(/Users/andrey/RiderProjects/ConsoleApp1/ConsoleApp1/bin/Debug/net6.0/runtimes/osx-arm64/native/ClearScriptV8.osx-arm64.dylib, 0x0001): tried: '/Users/andrey/RiderProjects/ConsoleApp1/ConsoleApp1/bin/Debug/net6.0/runtimes/osx-arm64/native/ClearScriptV8.osx-arm64.dylib' (no such file), '/usr/local/lib/ClearScriptV8.osx-arm64.dylib' (no such file), '/usr/lib/ClearScriptV8.osx-arm64.dylib' (no such file)
/Users/andrey/RiderProjects/ConsoleApp1/ConsoleApp1/bin/Debug/net6.0/ClearScriptV8.osx-arm64.dylib: Unable to load shared library '/Users/andrey/RiderProjects/ConsoleApp1/ConsoleApp1/bin/Debug/net6.0/ClearScriptV8.osx-arm64.dylib' or one of its dependencies. In order to help diagnose loading problems, consider setting the DYLD_PRINT_LIBRARIES environment variable: dlopen(/Users/andrey/RiderProjects/ConsoleApp1/ConsoleApp1/bin/Debug/net6.0/ClearScriptV8.osx-arm64.dylib, 0x0001): tried: '/Users/andrey/RiderProjects/ConsoleApp1/ConsoleApp1/bin/Debug/net6.0/ClearScriptV8.osx-arm64.dylib' (no such file), '/usr/local/lib/ClearScriptV8.osx-arm64.dylib' (no such file), '/usr/lib/ClearScriptV8.osx-arm64.dylib' (no such file)
/System/ClearScriptV8.osx-arm64.dylib: Unable to load shared library '/System/ClearScriptV8.osx-arm64.dylib' or one of its dependencies. In order to help diagnose loading problems, consider setting the DYLD_PRINT_LIBRARIES environment variable: dlopen(/System/ClearScriptV8.osx-arm64.dylib, 0x0001): tried: '/System/ClearScriptV8.osx-arm64.dylib' (no such file), '/usr/local/lib/ClearScriptV8.osx-arm64.dylib' (no such file), '/usr/lib/ClearScriptV8.osx-arm64.dylib' (no such file)
at Microsoft.ClearScript.V8.V8Proxy.LoadNativeLibrary(String baseName, String platform, String architecture, String extension)
at Microsoft.ClearScript.V8.V8Proxy.LoadNativeAssembly()
at Microsoft.ClearScript.V8.V8Proxy.OnEntityHolderCreated()
at Microsoft.ClearScript.V8.SplitProxy.V8EntityHolder..ctor(String name, Func`1 acquireHandle)
at Microsoft.ClearScript.V8.SplitProxy.V8IsolateProxyImpl..ctor(String name, V8RuntimeConstraints constraints, V8RuntimeFlags flags, Int32 debugPort)
at Microsoft.ClearScript.V8.V8IsolateProxy.Create(String name, V8RuntimeConstraints constraints, V8RuntimeFlags flags, Int32 debugPort)
at Microsoft.ClearScript.V8.V8Runtime..ctor(String name, V8RuntimeConstraints constraints, V8RuntimeFlags flags, Int32 debugPort)
at Microsoft.ClearScript.V8.V8Runtime..ctor(String name, V8RuntimeConstraints constraints, V8RuntimeFlags flags)
at Microsoft.ClearScript.V8.V8Runtime..ctor(String name, V8RuntimeConstraints constraints)
at Microsoft.ClearScript.V8.V8ScriptEngine..ctor(V8Runtime runtime, String name, V8RuntimeConstraints constraints, V8ScriptEngineFlags flags, Int32 debugPort)
at Microsoft.ClearScript.V8.V8ScriptEngine..ctor(String name, V8RuntimeConstraints constraints, V8ScriptEngineFlags flags, Int32 debugPort)
at Microsoft.ClearScript.V8.V8ScriptEngine..ctor(String name, V8RuntimeConstraints constraints, V8ScriptEngineFlags flags)
at Microsoft.ClearScript.V8.V8ScriptEngine..ctor(String name, V8RuntimeConstraints constraints)
at Microsoft.ClearScript.V8.V8ScriptEngine..ctor()
at Program.<Main>$(String[] args) in /Users/andrey/RiderProjects/ConsoleApp1/ConsoleApp1/Program.cs:line 4
Process finished with exit code 134.
Is it possible to use ClearScript on Mac M1? If "yes" then how can I fix the problem?
The problem solved. A solution was provided in the following GitHub issue: here.
The solution is to use the Microsoft.ClearScript.osx-arm64 package.
I am using Memory Mapped Files to read data from binary file like below but getting error :
Error : Not Enough Storage Is Available To Process This Command.
public void Execute()
{
MemoryMappedFile dataMmf;
dataMmf = MemoryMappedFile.CreateFromFile(Path.Combine(folder, "Data.bin"));
dataStream = dataMmf.CreateViewStream();
BinaryReader reader = new BinaryReader(dataStream, Encoding.UTF8, true);
// Code .......
}
I am working with following application :
Mvc Application
Class Library(MyEngine.dll)
Mvc Application contains MyEngine.dll and i am calling Execute method from my mvc application.
Memory Mapped file requires 64 bit environment to run so i guess when i call Execute method from mvc app,Execute method runs inside web server.
But when i go to properties of my mvc app there i see : Prefer 32 bit option as unchecked and disable
Then why i am getting storage error.This storage error occurs when memory mapped file is run inside 32 bit environment.
MyEngine.dll also have this option as unchecked : Prefer 32 bit
Strange things is i dont get error in case of 100,000 records but when i read 12 millions records then i get error.
On Msdn there is nothing mention about limit that for 32 bit it will read up to this much data.
The way i resolved this error is like below :
But i am trying to understand that why it worked after setting above option only and what i have to do when i will publish this solution on server?
Is there any other way to solve this without setting above option?
Size of data.bin = 448 mb
Stack Trace :
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.MemoryMappedFiles.MemoryMappedView.CreateView(SafeMemoryMappedFileHandle memMappedFileHandle, MemoryMappedFileAccess access, Int64 offset, Int64 size)
at System.IO.MemoryMappedFiles.MemoryMappedFile.CreateViewStream(Int64 offset, Int64 size, MemoryMappedFileAccess access)
at System.IO.MemoryMappedFiles.MemoryMappedFile.CreateViewStream()
I get this exception when trying to perform an XSLT transformation with C#:
Exception: System.NotSupportedException: The given path's format is not supported.
at System.Security.Permissions.FileIOPermission.QuickDemand(FileIOPermissionAccess access, String fullPath, Boolean checkForDuplicates, Boolean needFullPath)
at System.Xml.XmlResolver.ResolveUri(Uri baseUri, String relativeUri)
at System.Xml.XmlUrlResolver.ResolveUri(Uri baseUri, String relativeUri)
at System.Xml.XmlTextReaderImpl..ctor(String url, XmlNameTable nt)
at System.Xml.XPath.XPathDocument..ctor(String uri, XmlSpace space)
at System.Xml.XPath.XPathDocument..ctor(String uri)
at ConsoleApplication8.Program.TransformXML(String sXmlPath, String sXslPath)
when i try to run this code
void test()
{
var myXslTrans = new XslCompiledTransform();
myXslTrans.Load(#"C:\Users\ahmed\Desktop\fewf\visio.xsl");
myXslTrans.Transform(#"C:\Users\ahmed\Desktop\fewf\page1.xml", #"C:\Users\ahmed\Desktop\fewf\page.html");
}
i try to use Path.Combine(); but give me the same case
How can i solve this ?
Unfortunately, it was not clear from your question that you are using Silverlight (or at least some platform that somehow triggers this method)). When I started searching for QuickDemand, it turned out that this is only called in SilverLight (or similar?) environments, so I am rewriting my answer with that in mind.
at System.Security.Permissions.FileIOPermission.QuickDemand
This error is caused by this block of code in the reference source. As can be seen there, if the path contains a colon above second position, it is considered invalid.
In your code above this isn't shown, but since this is the only place in the reference source where this specific error is thrown, I am going to assume that the real code you have (possibly any of the xsl:includes in the XSLT) is containing a colon at some position other than the second position.
Either way, if this doesn't help, go to the Exceptions screen and check the NotSupportedException and in the Debug window uncheck the "Just my code" and check the "Enable .NET framework source stepping". That way, you can break at the position where the error is thrown and use IntelliSense and the debug windows to find out the context (i.e. the actual path) that is causing this error.
Also, from my previous post, if this doesn't help:
Try your code with a minimal XSLT (this is vital!)
Once you have that running, add an xsl:include
Once you have that running, add a document (if you use that, in addition, enable it in the settings)
Once you have that running... well, you get the drift
In my .NET client application I use the default settings provider with Scope=User and Roaming=True. This works fine in most environments, no matter if client or Terminal Server, except for a customer with a Citrix Terminal Server farm. Whenever Properties. Settings.Default.Save() is called, the following exception is thrown:
System.UnauthorizedAccessException: Attempted to perform an unauthorized operation.
at System.Security.AccessControl.Win32.SetSecurityInfo(ResourceType type, String name, SafeHandle handle, SecurityInfos securityInformation, SecurityIdentifier owner, SecurityIdentifier group, GenericAcl sacl, GenericAcl dacl)
at System.Security.AccessControl.NativeObjectSecurity.Persist(String name, SafeHandle handle, AccessControlSections includeSections, Object exceptionContext)
at System.Security.AccessControl.NativeObjectSecurity.Persist(String name, AccessControlSections includeSections, Object exceptionContext)
at System.Security.AccessControl.FileSystemSecurity.Persist(String fullPath)
at System.Configuration.Internal.WriteFileContext.DuplicateTemplateAttributes (String source, String destination)
at System.Configuration.Internal.WriteFileContext.DuplicateFileAttributes(String source, String destination)
at System.Configuration.Internal.WriteFileContext.Complete(String filename, Boolean success)
at System.Configuration.Internal.InternalConfigHost.StaticWriteCompleted(String streamName, Boolean success, Object writeContext, Boolean assertPermissions)
at System.Configuration.Internal.DelegatingConfigHost.WriteCompleted(String streamName, Boolean success, Object writeContext, Boolean assertPermissions)
at System.Configuration.ClientSettingsStore.ClientSettingsConfigurationHost.WriteCompleted(String streamName, Boolean success, Object writeContext)
at System.Configuration.UpdateConfigHost.WriteCompleted(String streamName, Boolean success, Object writeContext)
at System.Configuration.MgmtConfigurationRecord.SaveAs(String filename, ConfigurationSaveMode saveMode, Boolean forceUpdateAll)
at System.Configuration.ClientSettingsStore.WriteSettings(String sectionName, Boolean isRoaming, IDictionary newSettings)
at System.Configuration.LocalFileSettingsProvider.SetPropertyValues(SettingsContext context, SettingsPropertyValueCollection values)
at System.Configuration.SettingsBase.SaveCore()
at System.Configuration.SettingsBase.Save()
The reason for this exception:
System.Configuration.Internal.WriteFileContext writes a new copy (...newcfg) of the user settings in the user's roaming profile. Then, DuplicateTemplateAttributes tries to modify the ACLs of this file and explicitly set the ownership to the current user.
In the case of this customer this fails because the roaming profile is stored on a file share and the users have only Read and Change permissions, but not Full Control. They probably have Full Control in NTFS (because by default you are "Owner" of all files you create, and as the owner, you can do anything with the file no matter if you have "Full Control" explicitly set), but it seems like its blocked on the SMB share level.
This behavior doesn't make any sense to me: Given that the LocalFileSystemProvider always uses a private profile folder of the current user (local or roaming), we can safely assume that the user is the owner anyway.
Since WriteFileContext catches the exception, deletes the temporary .newcfg file and then rethrows, there is no way to simply catch the exception in my code and rename the file or somehow grab its content since it is already deleted when the exception is thrown.
I couldn't find any simple way to work around this issue except for implementing my own settings provider. For this, it seems like I even would have to rebuild things like the serialization part since all the System.Configuration stuff used for this is internal. And of course I don't want to break the currently used settings, so it looks like a ridiculous amount of code just to rebuild everything as it is with just "one line commented out" (setting the owner of the file).
Any ideas what else I could try?
There is no way the customer changes anything in its file share permissions...
I have experienced a similar issue on Citrix - AppData is redirected to a "Change & Read" network share (not "Full Control" - it works on "Full Control"). On first run, our application will create the user.config on the first Save() call but throws UnauthorizedAccessException on any subsequent Save() calls.
The answer appears to be to delete the user.config file if it exists before calling Save().
We are currently testing this with our client - I will update my answer when I have concrete results.
Update: You need to "touch" each setting in Settings.Default before calling Save() as the temp file is actually merged with existing user.config. By calling the following method before calling Save(), the user.config is correctly recreated each time (no UnauthorizedAccessException thrown).
public static void ClearUserConfigFile()
{
//Touch each setting
foreach (SettingsProperty property in Settings.Default.Properties)
{
if (property.DefaultValue != Settings.Default[property.Name])
Settings.Default[property.Name] = Settings.Default[property.Name];
}
//Delete the user.config file
var config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoaming);
var userConfigPath = config.FilePath;
try
{
if (File.Exists(userConfigPath) == true)
File.Delete(userConfigPath);
}
catch (Exception ex)
{
_log.ErrorFormat("Exception thrown while deleting user.config : {0}", ex.ToString());
}
}
Mode : http://www.emacswiki.org/emacs/CSharpMode
log:
Loading /.emacs.d/contrib/dev/csharp-mode.el
Done loading /.emacs.d/contrib/dev/csharp-mode.el
File mode specification error: (void-function make-local-hook)
Loading vc-git...done
When done with a buffer, type C-x #
(No files need saving)
File mode specification error: (void-function make-local-hook)
When done with a buffer, type C-x #
Making completion list... [2 times]
goto-history-element: End of history; no default available [3 times]
or: Symbol's function definition is void: make-local-hook
mouse-minibuffer-check: Minibuffer window is not active
(No files need saving)
When done with a buffer, type C-x #
(No files need saving)
File mode specification error: (void-function make-local-hook)
When done with a buffer, type C-x #
Making completion list... [2 times]
or: Symbol's function definition is void: make-local-hook
Why that? And how can I fix it?
make-local-hook has been obsolete for years, and was removed entirely in Emacs 24.
You should try to locate an updated version of the library. According to the Wiki page you linked to, the latest version is here:
http://code.google.com/p/csharpmode/
Failing that, there's a pretty good chance that the code only includes those function calls to retain backwards-compatibility with Emacs 20, and that provided there is an appropriate call to add-hook present, all you would need to do is delete all instances of (make-local-hook HOOK) from the code.
Here's the relevant bits of its old docstring:
(make-local-hook HOOK)
This function is obsolete since 21.1;
not necessary any more.
Make the hook HOOK local to the current buffer.
The return value is HOOK.
You never need to call this function now that `add-hook' does it for you
if its LOCAL argument is non-nil.
See also C-hf add-hook RET