artem-zinnatullin / jet-image-loader

WP7+ fast and powerfull image loader with memory and storage caching for your projects!
Apache License 2.0
44 stars 14 forks source link

Resharper warning "Unable to determine application identity of the caller" in app.xaml. #16

Open ghost opened 10 years ago

ghost commented 10 years ago

Do you have this issue?

http://clip2net.com/clip/m0/1383941405-clip-5kb.png

Probably, we would need to have some kind of isostorage protection against designtime access.

artem-zinnatullin commented 10 years ago

mm, what did you mean with "some kind of isostorage protection agains designtime access"?

ghost commented 10 years ago

I googled some time ago about that "Unable to determine application identity of the caller", and it was said that it appears when designtime (particulary in convertors) tries to access to isoStorage.

it should be kinda

object Convert(blahblah)

{

 if (IsDesignTime)    

    return "designtime text";

IsoStorage.ReadFile("Whatewer.txt");       

}

PS: however, i'm still having that warning in some cases, when isostorage is not used - that's the second reason why i asked you :)

PPS: formatting is crapy here

ghost commented 10 years ago

Anyway, so do you also see that resharper warning in your case?

artem-zinnatullin commented 10 years ago

Yes, I see it too. I'll check it now

artem-zinnatullin commented 10 years ago

Can you check this solution, I don't have Resharper on home laptop

in BaseJetImageLoader.cs

public virtual object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
    if (System.ComponentModel.DesignerProperties.IsInDesignTool)
    {
        // hack to hide warning "Unable to determine application identity of the caller" in XAML editor
        // no sideeffects in runtime on WP
       return null;
    }

    // method body
}
ghost commented 10 years ago

Yep, that's protection i mentioned :) However, i see the same warning in some other lines - that's why i asked you if you are familiar with it,

Meanwhile, i'm solving another problem (maybe offtop a bit, but i dont want to spawn tons of threads).

Somehow, it works fine in test project, but in real project it crashes with exception "The type 'MyAppJetImageLoaderConverter' was not found." Re-checking everything again and again, cant see a cause of the problem.

If to make a dummy converter, which inherits IValueConverter, it works fine. But once i'm inheriting BaseJetImageLoaderConverter (which is also inherited from IValueConverter), it crashes. When i'll find the cause of problem, i'll add it to readme or to another file like FAQ/BestPractises.

artem-zinnatullin commented 10 years ago

Hmm, strange behavior. I am using JetImageLoader in two apps and never had that error.

May be this will help you? (the type or namespace name could not be found)[http://stackoverflow.com/questions/4764978/the-type-or-namespace-name-could-not-be-found]

In most of answers solution is to check .NET version of referenced projects and if they differs, you should set same versions for them.

ghost commented 10 years ago

Nope, wp versions doesnt have lots of .net versions. Only "target WP 7.1" or "target WP8".

Some freaking magic is going on... I rebuilded everything, also added *.pdb file.

Probably i should go to sleep :)

ghost commented 10 years ago

Ok, looking like i'm using different Bcl versions. However, i see no updates notifications.

Weird thing is that with autoinstall, i got version 1.0.19 (for wp7 version of your lib), but my project (which throws exceptions) is using 1.1.3.

Just great.

Reinstalling of Bcl and dependent packages hepled. Now i'm able to run JetCacher in my real app. Proceeding to testing leaks as mentioned before.

ghost commented 10 years ago

If to talk about subj (DesignerProperties.IsInDesignTool), it didnt help.

At first, i thought that Release build just "optimize" and throw away that condition. However, JustDecompile shows that it is still there. And yes, "Unable to determine application identity of the caller" warning is still there.

ghost commented 10 years ago

Holy crap.. it works on Lumia 920, but it fails on Lumia 800 (interlocked exception). Thats weird. ... And test project still works on 800.

artem-zinnatullin commented 10 years ago

That's sad :(

I think, without rewriting parts of code with async/await JetImageLoader would not work normally on wp7

ghost commented 10 years ago

Well, i dont think that all parts are needed to be replaced. That exception appears in LimitedStorageCache, during updating _currentCacheSizeInBytes.

For now, i'm re-checking assembly versions and stuff. It works in my sample project, but it crashes in my real project. Then, i assume, i can use locker instead of Interlocked. Afaik, they are a bit slower, but nothing is free (except BSD-licensed code). :)

ghost commented 10 years ago

Wtf.. i reinstalled all assemblies manually, now version are very same. However, it still crashes in my project, but works in sample one.

ghost commented 10 years ago

I found, why it didnt work in my real project: http://msdn.microsoft.com/en-us/library/windowsphone/develop/x629ff68%28v=vs.95%29.aspx

64-bit members of the Interlocked class are present but not supported.

I guess, i can just represent cache size in megabytes.

artem-zinnatullin commented 10 years ago

I'll check this when I'll be at home. At the moment I can suggest you to try different configurations of JetImageLoader, like NoCache, MemoryCache, StorageCache, you also can check UnlimitedStorageCache as implementation of storage cache

artem-zinnatullin commented 10 years ago

ok, i got it. I can change its type to int and it will contain currentCacheSizeIn kilobytes or megabytes or we can use lock for incrementing

ghost commented 10 years ago

Check push request - it is already there :)

On the other hand, i had about 20-30 images 15-20 Kb each. I dont think that they are taking more than int32 bytes, Well, anyway, now it works more or less fine (regarding Increment problem).

artem-zinnatullin commented 10 years ago

ConvertBytesToMegabytes from pull request works incorrectly, example:

long bytes = 123456;
int megaBytes = ConvertBytesToMegabytes(bytes); // == 0
artem-zinnatullin commented 10 years ago

I think I should use lock to synchronize that incrementings and do not break existing usages of JetImageLoader

ghost commented 10 years ago

Hmmm.. let me see..

ghost commented 10 years ago
    static void Main(string[] args)
    {
        Debug.WriteLine(ConvertBytesToMegabytes(1024));
        Debug.WriteLine(ConvertBytesToMegabytes(1024 * 1024 - 1));
        Debug.WriteLine(ConvertBytesToMegabytes(1024 * 1024));
        Debug.WriteLine(ConvertBytesToMegabytes(1024 * 1024 + 1));
        Debug.WriteLine(ConvertBytesToMegabytes(5654523));
        Debug.WriteLine(ConvertBytesToMegabytes(56545245354353));
    }

    static int ConvertBytesToMegabytes(long bytes)
    {
        return (int) bytes >> 20;
    }

This works. Simplicity rulezz :)

artem-zinnatullin commented 10 years ago

Can we go to the skype? (artem.zinnatullin)

I pushed fix with lock to the develop branch, can you can pull it and check how it works?

https://github.com/artem-zinnatullin/jet-image-loader/tree/develop

Nearga commented 10 years ago

Btw, subj is still there. :)

mhartvig commented 10 years ago

Did you find a solution for this issue? The one with

if (System.ComponentModel.DesignerProperties.IsInDesignTool)
{
        return null;
}

does not help