Random invalid procedure call or argument in vbscript using a COM - c#

When I try to access my classic ASP application I get a random error of "Invalid Procedure Call or Argument". The line that causes this error calls a method from a C# component.
Here is the line that breaks in vbscript :
tmpArray2 = session.get(arrName) 'where arrName is a string
Also it cracks at this kind of line too :
if UBound(session.get("RTT_ID")) <> "-1" then
And here is the component code for the get method :
public object get(string key)
{
if (key == null || IsExpired)
{
return null;
}
if (!SessionData.ContainsKey(key))
{
var sessionData = GetDbSessionData(key);
var cachedValue = default(object);
if (sessionData == null || sessionData.Value == null || sessionData.ValueType == null)
{
LogManager.Instance.LogFormat(this, LogLevel.Warning, "Session data not found. SessionId: '{0}'; Key: '{1}'.", this.SessionInfo.Id, key);
cachedValue = null;
}
else
{
cachedValue = SessionDataSerializer.Instance.DeserializeSessionData(sessionData.Value, sessionData.ValueType);
}
var cachedSessionData = new CachedSessionData();
cachedSessionData.CachedValue = cachedValue;
cachedSessionData.DbEntity = sessionData;
SessionData.Add(key, cachedSessionData);
}
RefreshExpirationDate();
return SessionData[key].CachedValue;
}
Also, what I noticed and I do not know if it is relevant or not, this code cracks a lot on an environment that has 2 servers and makes a balancing between them when the first one is too busy. If I try it on a single server, I managed to broke it only once.
Any ideas?

Thank you for your answers. The problem was that because we wanted to increase our performance we had to serialize every object that was send to the component and deserialize it when we returned it to the vbscript. The issue was that we had one array that was containing other arrays and when we deserialize the array we could not return also the child arrays and that was causing the problem. We used for deserialization the MessageBox library.
Another thing to mention is that on our environment we had 2 servers and we are doing some balancing between them. When the application runs only on one server, the deserialization was ok and we had no problems, but when we switched to the other server we encountered this problem.
Maybe this answer will help others understand what could happen if you receive this type of error.

Related

How to resolve this error with Unity's AsyncGPUReadback?

I am trying to read back from the GPU a compute buffer inside of which there is an array of structs that I have defined and previously set.
var req = AsyncGPUReadback.Request(myBuffer);
if(req.hasError == false)
{
var readback = req.GetData<myStruct>();
print(readback);
}
When I put this in the code I get this error: InvalidOperationException: Cannot access the data as it is not available. The problem is that the data should be available because when I use the normal GetData method everything works just fine.
myBuffer.GetData(data);
Does anyone have an idea where I should be looking to get this error solved? Thanks!
------------------------Edit-------------------------------
I found a solution here https://github.com/keijiro/AsyncCaptureTest/blob/master/Assets/AsyncCapture.cs , but It's not very clear to me why it is working now and not before.
void Update()
{
AsyncGPUReadback.Request(myBuffer, OnCompleteReadBack);
}
void OnCompleteReadBack(AsyncGPUReadBackRequest request)
{
if(request.hasError == false)
{
var data = request.GetData<myStruct>();
}
}

How to check of object exists in Google Cloud Storage using C#?

Does anyone know how to check if an object exists inside a Google Cloud Storage bucket via C#?
To test for the existence of an object without generating an exception when it isn't found, use the ListObjects() method.
The documentation on the prefix argument is a little misleading.
Only objects with names that start with this string will be returned.
In fact, the full object name can be used and will result in positive matches.
using( var client = StorageClient.Create() )
{
var results = client.ListObjects( "bucketname", "test.jpg" );
var exists = results?.Count() > 0;
return exists;
}
I believe protecting results w/ the nullable test is unnecessary. Even when I get no results with this code results is still not null. That said, I feel safer with that added protection since we are explicitly trying to avoid a try/catch.
Obviously this code could be shortened, but I wanted to demonstrate each step of the process for clarity.
This code was tested in a .net6 Console App using Google.Cloud.Storage.V1 version 3.7.0.
You can use Google.Cloud.Storage.V1 library
using Google.Cloud.Storage.V1;
public class StorageClass
{
public bool IsObjectExist(string bucketName, string objectname)
{
var client = StorageClient.Create();
return client.GetObject(bucketName, objectname) != null ? true : false;
}
}

C# Hjson returns null after deserialization

I have a hjson file like this that I want to deserialize and work with:
{
"TestConfig": {
"SecondConfig": {
"ConnectionString": "Integrated Security = true; Data Source = dataPseudo; Initial Catalog = catalogPseudo; Connect Timeout = 180",
"SpecificationPseudo": "pseudo",
"NumberOfHintsPseudo": 300
},
"ThirdConfig": "pseudo"
}... // more hjson coming here.
I load it with the HjsonValue.Load method like this:
private static Foo convertJson()
{
var loadedValue = HjsonValue.Load("hjsonFile.hjson").ToString();
return new JsonSerializer<Foo>().DeserializeFromString(loadedValue);
// another failed method: return JsonConvert.DeserializeObject<Foo>(loadedValue);
// A third failed method: return JsonConvert.DeserializeObject<Dictionary<string, Foo>>(loadedValue);
}
I think my problem is in the 2 c#-coded lines, but can't figure what. Am I deserializing wrong or what seems to be the problem? I suspect that it's because it is a nested json, but can't find a way to deserialize it. Trying to use dictionary as it is a answer in a other stack-question, but it didn't work for me.
Note: The first and second tried return method don't return any errors, but they just return a nullreferenceexception since "SecondConfig" and "ThirdConfig" both are null..
Update (with help from er-sho): removed the "root"-element from the hjson (TestConfig), which solved the problem.
Removing "TestConfig" from the hjson fixed it, since it's root and the class I am working with.

CRM Plugin Error The given key was not present in the dictionary

I developed a CRM plugin that gets triggered when creating a Case entity. The Case has a N:1 relationship with another custom entity. Short story, when a field "new_CaseAssign" from the custom entity is set to 1, then the plugin will generate a Task assigned to Case Owner.
However the problem is that the field "new_CaseAssign" is newly added so most of the custom entity records don't have this field set yet, which causes the plugins to error out with "The given key was not present in the dictionary". If the custom field has value, then it's no problem.
What would be the best way to handle this situation? I tried customEntity.Attributes.Contains("new_CaseAssign") like below codes but no success:
var new_CaseAssign = customEntity.Attributes["new_CaseAssign"];
if ((customEntity.Attributes.Contains("new_CaseAssign")) && (bool)new_CaseAssign)
{
activityEntity.Attributes.Add("ownerid", incident.Attributes["ownerid"]);
}
else
{ //something else
}
Any suggestions is appreciated. Thanks much.
The line:
var new_CaseAssign = customEntity.Attributes["new_CaseAssign"];
is probably causing the exception. You could rewrite the code as:
bool new_CaseAssign = false;
if (customEntity.Attributes.Contains("new_CaseAssign"))
new_CaseAssign = (bool) customEntity.Attributes["new_CaseAssign"];
if (new_CaseAssign) {
activityEntity.Attributes.Add("ownerid", incident.Attributes["ownerid"]);
}
else { //something else
}
So first check contains before trying to access the key.
Loathing's answer is partially correct, in fact you are accessing the attribute before the check if is present or not. Normally I also check if the attribute it's not null before the cast.
The second error is with the field name, you are using late bound style, this means you need to use the logical name instead of the schema name, so the field name is new_caseassign (all lower case) instead of new_CaseAssign.
if ((customEntity.Attributes.Contains("new_caseassign")) && customEntity.Attributes["new_caseassign"] != null)
{
if ((bool)customEntity.Attributes["new_caseassign"])
{
activityEntity.Attributes.Add("ownerid", incident.Attributes["ownerid"]);
}
}
else
{ //something else
}

Null pointer exception I'm having trouble resolving

On one of my ASP.NET MVC websites I occassionally get a NPE in production that I'm having trouble understanding root cause. I'm using ELMAH for tracing errors.
The full stacktrace is here (not much to it:
System.NullReferenceException: Object reference not set to an instance of an object.
at PG.Controllers.FooController.FooActionName(FooModel model) in
{REMOVED}\web\www\Controllers\FooController.cs:line 622
Here's line 622:
if(UserCanEditFoo(out result))
Here's the "UserCanEditFoo listing:
private bool UserCanEditFoo(out ActionResult result)
{
String email = User != null && User.Identity != null ? User.Identity.Name : String.Empty;
UserAccount user = String.IsNullOrEmpty(email) ? null : this.accountServices.GetUserAccount(email);
bool canEditFoo = false;
result = null;
// Don't know this user
if(user == null)
{
FormsAuthentication.SignOut();
Session.Abandon();
result = RedirectToAction(Routes.Actions.Index, Routes.Controllers.Home);
}
// Only admins and foo profile can edit foo
else if(user.Role != Types.UserRole.Admin && user.Role != Types.UserRole.Foo)
{
result = new HttpUnauthorizedResult("Oops! Only administrators and foo users can edit foo.");
}
else
{
result = null;
canEditFoo = true;
}
return canEditFoo;
}
I'm assuming the exception is actually raised in the "UserCanEditFoo" private method but I don't understand why the line number is not being reported as such. On the flipside, if the exception is truly being raised at line 622 I don't understand how that can be given it is a simple function call.
Any help will be much appreciated. Thanks in advance.
Assuming this.accountServices cannot be null, your code looks fine to me, so I would suggest that the exception is actually happening elsewhere (perhaps due to inlining).
Take a look at this question for details on displaying correct line numbers in Release mode.

Categories