none
Unable to determine Identity of domain - System.IO.Packaging (XPS) RRS feed

  • Question

  • I have a C# class library which uses System.IO.Packaging (XPS). The problem is whenever I try to package a file bigger than 8MB (doesnt occur for files <8MB), I get the error "Unable to determine identity of domain" if I call the function from an MFC application. Calling the same function with a .NET application is succesful.

     

    I have read around it and I am convinced it has to do with IsolatedStorage Security/Permission. I tried creating some IsolatedStorage files/streams and the same situation. Work perfectly under C# and create exception when called from MFC.

     

    I want to know, how can I convince or trick IsolatedStorage Security that I am a good guy just trying to package a file larger than 8MB.

    Monday, February 11, 2008 1:08 PM

Answers

All replies

  • I'm not very sure about what exactly you mean by "called from MFC", could you please clarify?

    To troubleshoot this issue, we really need the source code and the detailed repro steps to reproduce the problem, so that we can investigate the issue in house. It is not necessary that you send out the complete source of your project. We just need a simplest sample to reproduce the problem. You can remove any confidential information or business logic from it.
    Monday, February 11, 2008 2:17 PM
  • Thanks for your response. I hearby send code to clarify the problem. The function below is defined in a .NET class library. Calling this function on a file (fileToAdd) of size less than 8MB does not give any problems from both the MFC and .NET apps. However, if I call this function from the MFC app and the file is bigger than 8MB then I get the exception "Unable to determine identity of domain". It doesn't occur for the .NET application. Similar problem in http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1757098&SiteID=1

     

     

    bool static AddToZip(string zipfilename, string fileToAdd)

    try

    {

    using (Package zip = System.IO.Packaging.Package.Open(zipFilename, FileMode.OpenOrCreate))

    {

    string destFilename = ".\\"Path.GetFileName(fileToAdd) ;

     

    Uri uri = PackUriHelper.CreatePartUri(new Uri(destFilename, UriKind.Relative));

    if (zip.PartExists(uri))

    {

    zip.DeletePart(uri);

    }

     

    PackagePart part = zip.CreatePart(uri, "", CompressionOption.Normal);

    using (FileStream fileStream = new FileStream(fileToAdd, FileMode.Open, FileAccess.Read))

    {

    using (Stream dest = part.GetStream())

    {

    CopyStream(fileStream, dest);

    }

    }

    }

    return true;

    }

    catch(Exception e)

    {

    System.Windows.Forms.MessageBox.Show(e.Message); //Says "Unable to determine identity of domain

    return false;

    }

     

     

    I understand it has something to do with IsolatedStorage. So I tried the following code in the same library. It returned the same error when called from the MFC app but worked perfectly when called from the .NET application.

     

    public static void Means()

    {

    System.Windows.Forms.MessageBox.Show("Testing means");

    IsolatedStorageFile isoFile = null; ;

    IsolatedStorageFileStream isoStream = null; ;

    try

    {

    isoFile = IsolatedStorageFile.GetUserStoreForDomain();

     

     

    // Open or create a writable file.

    isoStream = new IsolatedStorageFileStream("userName", FileMode.OpenOrCreate, FileAccess.Write, isoFile);

    }

    catch (Exception e)

    {

    System.Windows.Forms.MessageBox.Show(e.Message);

    }

    finally

    {

    if(isoStream != null) isoStream.Close();

    if(isoFile != null) isoFile.Close();

    }

    }

     

    Monday, February 11, 2008 2:32 PM
  • Hmm. Thanks to all who tried to help me on this. As I stated earlier, the problem comes with IsolatedStorage requesting Evidence that my MFC generated call did not have. So it found MFC guilty of trying to be malicious, ie, trying to get access to protected and secured places.

     

    Well, I tried every trick on the internet (hit google about 100 times) and a few of my own. Still no solution. So I have circumvented the problem by making sure System.IO.Packaging does not, over and under, any circumstance call IsolatedStorage. Since the problem only occurs after 8MB, I flush the outputstream to disk at 7.8MB (0.2MB Factor of Safety) so that there will be no need for IsolatedStorage.

     

    The problem is, is it going to be 8MB always on every machine???

     

    You can 8MB some of the machines all the time, you can 8MB all the machines some of the time, but you can't 8MB all the machines all the time.

     

    So can someone tell me how to get the 8MB figure programmatically. Is it related to the amount of memory on the Machine?

     

     

    Tuesday, February 12, 2008 5:18 PM
  • I'm still not sure about what exactly you mean by "called by MFC"?

    Could you show some code in the MFC application?
    Wednesday, February 13, 2008 8:14 AM
  • MFC application

    CNUtils::AddFileToZip(sPackageName,sFileToAdd);

     

    Mixed C++/Managed C++ library

     

    BOOL CNUtils::AddFileToZip(CString s1, CString s2)

    {

    WowPackage::AddFileToZip(gcnew String(s1), gcnew String(s2));

    }

     

     

     

    WowPackage defined in C# library is as defined in the code earlier.

     

     

     

     

     

     

     

    Wednesday, February 13, 2008 12:58 PM
  • Hi,
    Your workaround to make sure System.IO.Packaging does not call IsolatedStorage sounds better. Can u pls share with us how you  flush the outputstream to disk at 7.8MB. 

    I have pasted below my code for ur reference. It fails at the line
        
        
            
    doc.Load(mainPartxml.GetStream()); with exception Unable to determine Identity of domain

     foreach (PackageRelationship searchRelation in pack.GetRelationshipsByType(wordRelationshipType))
                    {
                        relationship = searchRelation;
                        break;
                    }

                    Uri partUri = PackUriHelper.ResolvePartUri(relationship.SourceUri, relationship.TargetUri);
                    PackagePart mainPartxml = pack.GetPart(partUri);

                    doc = new XmlDocument();
                    doc.Load(mainPartxml.GetStream());

    Am in real need of a solution to this. Any suggestions would be gr8ly appreciated.

    Thanks in Advance,
    Shabeer

    Friday, November 21, 2008 1:05 PM
  • I have the same problem when i use System.IO.Packaging to create a xlsx file.

    but  i had a little complex environment. i  had a win32 dll for getting data and  a  C# dll using System.IO.Packaging to create a excel file . C# dll register as COM for win32 dll's calling. 

    so , when i call the win32 dll with include its header file from a win32 exe , System.IO.Packaging will throw IsolatedStorageException while filesize is over 8MB. but  when i call the win32 dll with DllImport from a C# exe , excel file can be successful created.

     

     Can someone explain this problem?

    Thanks a lot!

     

    Friday, January 23, 2009 6:11 AM
  • I still can not solve this problem , could anyone help me ?!

    I have a test program for this problem, if anyone needs , i will send it to you.

     

    Thanks again!!!

    Wednesday, January 28, 2009 5:32 AM
  • i have solve this problem , i just set the C++ project with /CLR compile option.

    Friday, January 30, 2009 8:36 AM